From 389d1c2893754193da41256a82f6c3c4c9a03097 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine@gmail.com" Date: Fri, 7 Dec 2012 08:11:23 +0000 Subject: Only include wchar.h in PUGIXML_WCHAR_MODE; use a custom implementation of wcslen in case there is no wide character support. git-svn-id: http://pugixml.googlecode.com/svn/trunk@942 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index edc03d6..c1720f1 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -20,7 +20,10 @@ #include #include #include -#include + +#ifdef PUGIXML_WCHAR_MODE +# include +#endif #ifndef PUGIXML_NO_XPATH # include @@ -195,7 +198,21 @@ PUGI__NS_BEGIN return lhs[count] == 0; } - + + // Get length of wide string, even if CRT lacks wide character support + PUGI__FN size_t strlength_wide(const wchar_t* s) + { + assert(s); + + #ifdef PUGIXML_WCHAR_MODE + return wcslen(s); + #else + const wchar_t* end = s; + while (*end) end++; + return static_cast(end - s); + #endif + } + #ifdef PUGIXML_WCHAR_MODE // Convert string to wide string, assuming all symbols are ASCII PUGI__FN void widen_ascii(wchar_t* dest, const char* source) @@ -3610,7 +3627,7 @@ PUGI__NS_BEGIN assert(str); // first pass: get length in utf8 characters - size_t length = wcslen(str); + size_t length = strlength_wide(str); size_t size = as_utf8_begin(str, length); // allocate resulting string @@ -5394,7 +5411,7 @@ namespace pugi { assert(str); - return impl::as_utf8_impl(str, wcslen(str)); + return impl::as_utf8_impl(str, impl::strlength_wide(str)); } PUGI__FN std::string PUGIXML_FUNCTION as_utf8(const std::basic_string& str) -- cgit v1.2.3