summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-09-11 13:30:49 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-09-11 13:30:49 +0000
commitcae6c066b736c1b582991e5496a54c9a85b5832d (patch)
treea47bad45a37b9cf820376fe6177b3043a0f68745
parentb67f104498393f60f701a6bef219d0f34ece6f51 (diff)
XPath: Minor lang() fix (use ASCII lowercase because language names are ASCII-only anyway)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@716 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r--src/pugixml.cpp9
-rw-r--r--tests/test_xpath_functions.cpp12
2 files changed, 13 insertions, 8 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index a8ed526..0e9b99c 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -21,7 +21,6 @@
#include <wchar.h>
#ifndef PUGIXML_NO_XPATH
-# include <ctype.h>
# include <math.h>
# include <float.h>
#endif
@@ -4903,6 +4902,12 @@ namespace
#endif
}
+ // Converts symbol to lower case, if it is an ASCII one
+ char_t tolower_ascii(char_t ch)
+ {
+ return static_cast<unsigned int>(ch - 'A') < 26 ? (ch | ' ') : ch;
+ }
+
xpath_string string_value(const xpath_node& na)
{
if (na.attribute())
@@ -7127,7 +7132,7 @@ namespace pugi
// strnicmp / strncasecmp is not portable
for (const char_t* lit = lang.c_str(); *lit; ++lit)
{
- if (tolower(*lit) != tolower(*value)) return false;
+ if (tolower_ascii(*lit) != tolower_ascii(*value)) return false;
++value;
}
diff --git a/tests/test_xpath_functions.cpp b/tests/test_xpath_functions.cpp
index 016c722..7245bee 100644
--- a/tests/test_xpath_functions.cpp
+++ b/tests/test_xpath_functions.cpp
@@ -216,7 +216,7 @@ TEST(xpath_boolean_false)
CHECK_XPATH_FAIL(STR("false(1)"));
}
-TEST_XML(xpath_boolean_lang, "<node xml:lang='en'><child xml:lang='ru-UK'><subchild/></child></node><foo><bar/></foo>")
+TEST_XML(xpath_boolean_lang, "<node xml:lang='en'><child xml:lang='zh-UK'><subchild/></child></node><foo><bar/></foo>")
{
xml_node c;
@@ -231,16 +231,16 @@ TEST_XML(xpath_boolean_lang, "<node xml:lang='en'><child xml:lang='ru-UK'><subch
// lang with 1 argument, same language/prefix
CHECK_XPATH_BOOLEAN(doc.child(STR("node")), STR("lang('en')"), true);
- CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")), STR("lang('ru-uk')"), true);
- CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")), STR("lang('ru')"), true);
- CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")).child(STR("subchild")), STR("lang('ru')"), true);
- CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")).child(STR("subchild")), STR("lang('RU')"), true);
+ CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")), STR("lang('zh-uk')"), true);
+ CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")), STR("lang('zh')"), true);
+ CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")).child(STR("subchild")), STR("lang('zh')"), true);
+ CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")).child(STR("subchild")), STR("lang('ZH')"), true);
// lang with 1 argument, different language/prefix
CHECK_XPATH_BOOLEAN(doc.child(STR("node")), STR("lang('')"), false);
CHECK_XPATH_BOOLEAN(doc.child(STR("node")), STR("lang('e')"), false);
CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")), STR("lang('en')"), false);
- CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")), STR("lang('ru-gb')"), false);
+ CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")), STR("lang('zh-gb')"), false);
CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")), STR("lang('r')"), false);
CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")).child(STR("subchild")), STR("lang('en')"), false);