Specialize StrLen for char/wchar_t

Compilers generally provide a much smarter strlen than ours.
This commit is contained in:
StilesCrisis 2017-02-28 01:11:30 -08:00
parent f349456bc5
commit 6e2e5c7dbe

View File

@ -16,6 +16,7 @@
#define RAPIDJSON_INTERNAL_STRFUNC_H_ #define RAPIDJSON_INTERNAL_STRFUNC_H_
#include "../stream.h" #include "../stream.h"
#include <cwchar>
RAPIDJSON_NAMESPACE_BEGIN RAPIDJSON_NAMESPACE_BEGIN
namespace internal { namespace internal {
@ -34,6 +35,16 @@ inline SizeType StrLen(const Ch* s) {
return SizeType(p - s); return SizeType(p - s);
} }
template <>
inline SizeType StrLen(const char* s) {
return SizeType(std::strlen(s));
}
template <>
inline SizeType StrLen(const wchar_t* s) {
return SizeType(std::wcslen(s));
}
//! Returns number of code points in a encoded string. //! Returns number of code points in a encoded string.
template<typename Encoding> template<typename Encoding>
bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {