| 48 | //! Returns number of code points in a encoded string. |
| 49 | template<typename Encoding> |
| 50 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { |
| 51 | RAPIDJSON_ASSERT(s != 0); |
| 52 | 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 | } // namespace internal |
| 67 | RAPIDJSON_NAMESPACE_END |