Arcane  v3.16.8.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
strfunc.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2// Tencent is pleased to support the open source community by making RapidJSON available.
3//
4// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
5//
6// Licensed under the MIT License (the "License"); you may not use this file except
7// in compliance with the License. You may obtain a copy of the License at
8//
9// http://opensource.org/licenses/MIT
10//
11// Unless required by applicable law or agreed to in writing, software distributed
12// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14// specific language governing permissions and limitations under the License.
15
16#ifndef RAPIDJSON_INTERNAL_STRFUNC_H_
17#define RAPIDJSON_INTERNAL_STRFUNC_H_
18
19#include "../stream.h"
20#include <cwchar>
21
23namespace internal {
24
26
31template <typename Ch>
32inline SizeType StrLen(const Ch* s) {
33 RAPIDJSON_ASSERT(s != 0);
34 const Ch* p = s;
35 while (*p) ++p;
36 return SizeType(p - s);
37}
38
39template <>
40inline SizeType StrLen(const char* s) {
41 return SizeType(std::strlen(s));
42}
43
44template <>
45inline SizeType StrLen(const wchar_t* s) {
46 return SizeType(std::wcslen(s));
47}
48
50
55template<typename Ch>
56inline int StrCmp(const Ch* s1, const Ch* s2) {
57 RAPIDJSON_ASSERT(s1 != 0);
58 RAPIDJSON_ASSERT(s2 != 0);
59 while(*s1 && (*s1 == *s2)) { s1++; s2++; }
60 return static_cast<unsigned>(*s1) < static_cast<unsigned>(*s2) ? -1 : static_cast<unsigned>(*s1) > static_cast<unsigned>(*s2);
61}
62
64template<typename Encoding>
65bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {
66 RAPIDJSON_ASSERT(s != 0);
67 RAPIDJSON_ASSERT(outCount != 0);
68 GenericStringStream<Encoding> is(s);
69 const typename Encoding::Ch* end = s + length;
70 SizeType count = 0;
71 while (is.src_ < end) {
72 unsigned codepoint;
73 if (!Encoding::Decode(is, &codepoint))
74 return false;
75 count++;
76 }
77 *outCount = count;
78 return true;
79}
80
81} // namespace internal
83
84#endif // RAPIDJSON_INTERNAL_STRFUNC_H_
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:438
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition rapidjson.h:122
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition rapidjson.h:125
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition rapidjson.h:416