Arcane  v3.14.10.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. All rights reserved.
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
50template<typename Encoding>
51bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {
52 RAPIDJSON_ASSERT(s != 0);
53 RAPIDJSON_ASSERT(outCount != 0);
55 const typename Encoding::Ch* end = s + length;
56 SizeType count = 0;
57 while (is.src_ < end) {
58 unsigned codepoint;
59 if (!Encoding::Decode(is, &codepoint))
60 return false;
61 count++;
62 }
63 *outCount = count;
64 return true;
65}
66
67} // namespace internal
69
70#endif // RAPIDJSON_INTERNAL_STRFUNC_H_
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:407
#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:385
Read-only string stream.
Definition stream.h:155