strfunc.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_
20 #define RAPIDJSON_INTERNAL_STRFUNC_H_
21 
22 #include <cwchar>
23 #include "../stream.h"
24 
26 namespace internal {
27 
29 
35 template <typename Ch>
36 inline SizeType StrLen(const Ch *s) {
37  RAPIDJSON_ASSERT(s != 0);
38  const Ch *p = s;
39  while (*p) ++p;
40  return SizeType(p - s);
41 }
42 
43 template <>
44 inline SizeType StrLen(const char *s) {
45  return SizeType(std::strlen(s));
46 }
47 
48 template <>
49 inline SizeType StrLen(const wchar_t *s) {
50  return SizeType(std::wcslen(s));
51 }
52 
54 template <typename Encoding>
55 bool CountStringCodePoint(const typename Encoding::Ch *s, SizeType length,
56  SizeType *outCount) {
57  RAPIDJSON_ASSERT(s != 0);
58  RAPIDJSON_ASSERT(outCount != 0);
60  const typename Encoding::Ch *end = s + length;
61  SizeType count = 0;
62  while (is.src_ < end) {
63  unsigned codepoint;
64  if (!Encoding::Decode(is, &codepoint)) return false;
65  count++;
66  }
67  *outCount = count;
68  return true;
69 }
70 
71 } // namespace internal
73 
74 #endif // RAPIDJSON_INTERNAL_STRFUNC_H_
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:411
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:433
Read-only string stream.
Definition: fwd.h:60
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
const Ch * src_
Current read position.
Definition: stream.h:180
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
bool CountStringCodePoint(const typename Encoding::Ch *s, SizeType length, SizeType *outCount)
Returns number of code points in a encoded string.
Definition: strfunc.h:55
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:36


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46