File indexing completed on 2025-12-16 10:28:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_
0016 #define RAPIDJSON_INTERNAL_STRFUNC_H_
0017
0018 #include "../stream.h"
0019 #include <cwchar>
0020
0021 RAPIDJSON_NAMESPACE_BEGIN
0022 namespace internal {
0023
0024
0025
0026
0027
0028
0029
0030 template <typename Ch>
0031 inline SizeType StrLen(const Ch* s) {
0032 RAPIDJSON_ASSERT(s != 0);
0033 const Ch* p = s;
0034 while (*p) ++p;
0035 return SizeType(p - s);
0036 }
0037
0038 template <>
0039 inline SizeType StrLen(const char* s) {
0040 return SizeType(std::strlen(s));
0041 }
0042
0043 template <>
0044 inline SizeType StrLen(const wchar_t* s) {
0045 return SizeType(std::wcslen(s));
0046 }
0047
0048
0049
0050
0051
0052
0053
0054 template<typename Ch>
0055 inline int StrCmp(const Ch* s1, const Ch* s2) {
0056 RAPIDJSON_ASSERT(s1 != 0);
0057 RAPIDJSON_ASSERT(s2 != 0);
0058 while(*s1 && (*s1 == *s2)) { s1++; s2++; }
0059 return static_cast<unsigned>(*s1) < static_cast<unsigned>(*s2) ? -1 : static_cast<unsigned>(*s1) > static_cast<unsigned>(*s2);
0060 }
0061
0062
0063 template<typename Encoding>
0064 bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {
0065 RAPIDJSON_ASSERT(s != 0);
0066 RAPIDJSON_ASSERT(outCount != 0);
0067 GenericStringStream<Encoding> is(s);
0068 const typename Encoding::Ch* end = s + length;
0069 SizeType count = 0;
0070 while (is.src_ < end) {
0071 unsigned codepoint;
0072 if (!Encoding::Decode(is, &codepoint))
0073 return false;
0074 count++;
0075 }
0076 *outCount = count;
0077 return true;
0078 }
0079
0080 }
0081 RAPIDJSON_NAMESPACE_END
0082
0083 #endif