summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-12-07 08:11:23 +0000
committerarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-12-07 08:11:23 +0000
commit389d1c2893754193da41256a82f6c3c4c9a03097 (patch)
treeafa1f7768ccf045407584064aba1ca32e2822b03
parent30549910db4e65328a5ea671b57b4fc20a98551f (diff)
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
-rw-r--r--src/pugixml.cpp25
1 files changed, 21 insertions, 4 deletions
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 <stdio.h>
#include <string.h>
#include <assert.h>
-#include <wchar.h>
+
+#ifdef PUGIXML_WCHAR_MODE
+# include <wchar.h>
+#endif
#ifndef PUGIXML_NO_XPATH
# include <math.h>
@@ -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<size_t>(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<wchar_t>& str)