strfunc.h (rapidjson-1.0.2) | : | strfunc.h (rapidjson-1.1.0) | ||
---|---|---|---|---|
skipping to change at line 18 | skipping to change at line 18 | |||
// http://opensource.org/licenses/MIT | // http://opensource.org/licenses/MIT | |||
// | // | |||
// Unless required by applicable law or agreed to in writing, software distribut ed | // Unless required by applicable law or agreed to in writing, software distribut ed | |||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the | // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |||
// specific language governing permissions and limitations under the License. | // specific language governing permissions and limitations under the License. | |||
#ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ | |||
#define RAPIDJSON_INTERNAL_STRFUNC_H_ | #define RAPIDJSON_INTERNAL_STRFUNC_H_ | |||
#include "../rapidjson.h" | #include "../stream.h" | |||
RAPIDJSON_NAMESPACE_BEGIN | RAPIDJSON_NAMESPACE_BEGIN | |||
namespace internal { | namespace internal { | |||
//! Custom strlen() which works on different character types. | //! Custom strlen() which works on different character types. | |||
/*! \tparam Ch Character type (e.g. char, wchar_t, short) | /*! \tparam Ch Character type (e.g. char, wchar_t, short) | |||
\param s Null-terminated input string. | \param s Null-terminated input string. | |||
\return Number of characters in the string. | \return Number of characters in the string. | |||
\note This has the same semantics as strlen(), the return value is not numbe r of Unicode codepoints. | \note This has the same semantics as strlen(), the return value is not numbe r of Unicode codepoints. | |||
*/ | */ | |||
template <typename Ch> | template <typename Ch> | |||
inline SizeType StrLen(const Ch* s) { | inline SizeType StrLen(const Ch* s) { | |||
const Ch* p = s; | const Ch* p = s; | |||
while (*p) ++p; | while (*p) ++p; | |||
return SizeType(p - s); | return SizeType(p - s); | |||
} | } | |||
//! Returns number of code points in a encoded string. | ||||
template<typename Encoding> | ||||
bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeT | ||||
ype* outCount) { | ||||
GenericStringStream<Encoding> is(s); | ||||
const typename Encoding::Ch* end = s + length; | ||||
SizeType count = 0; | ||||
while (is.src_ < end) { | ||||
unsigned codepoint; | ||||
if (!Encoding::Decode(is, &codepoint)) | ||||
return false; | ||||
count++; | ||||
} | ||||
*outCount = count; | ||||
return true; | ||||
} | ||||
} // namespace internal | } // namespace internal | |||
RAPIDJSON_NAMESPACE_END | RAPIDJSON_NAMESPACE_END | |||
#endif // RAPIDJSON_INTERNAL_STRFUNC_H_ | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 18 lines changed or added |