| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#ifndef CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ |
| 16 |
#define CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ |
| 17 |
|
| 18 |
#include "../stream.h" |
| 19 |
#include <cwchar> |
| 20 |
|
| 21 |
CEREAL_RAPIDJSON_NAMESPACE_BEGIN |
| 22 |
namespace internal { |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
template <typename Ch> |
| 31 |
inline SizeType StrLen(const Ch* s) { |
| 32 |
CEREAL_RAPIDJSON_ASSERT(s != 0); |
| 33 |
const Ch* p = s; |
| 34 |
while (*p) ++p; |
| 35 |
return SizeType(p - s); |
| 36 |
} |
| 37 |
|
| 38 |
template <> |
| 39 |
inline SizeType StrLen(const char* s) { |
| 40 |
return SizeType(std::strlen(s)); |
| 41 |
} |
| 42 |
|
| 43 |
template <> |
| 44 |
inline SizeType StrLen(const wchar_t* s) { |
| 45 |
return SizeType(std::wcslen(s)); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
template<typename Encoding> |
| 50 |
bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { |
| 51 |
CEREAL_RAPIDJSON_ASSERT(s != 0); |
| 52 |
CEREAL_RAPIDJSON_ASSERT(outCount != 0); |
| 53 |
GenericStringStream<Encoding> is(s); |
| 54 |
const typename Encoding::Ch* end = s + length; |
| 55 |
SizeType count = 0; |
| 56 |
while (is.src_ < end) { |
| 57 |
unsigned codepoint; |
| 58 |
if (!Encoding::Decode(is, &codepoint)) |
| 59 |
return false; |
| 60 |
count++; |
| 61 |
} |
| 62 |
*outCount = count; |
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
CEREAL_RAPIDJSON_NAMESPACE_END |
| 68 |
|
| 69 |
#endif |