0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-28 23:03:00 +08:00

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
This commit is contained in:
arseny.kapoulkine 2010-09-11 13:30:49 +00:00
parent b67f104498
commit cae6c066b7
2 changed files with 13 additions and 8 deletions

View File

@ -21,7 +21,6 @@
#include <wchar.h> #include <wchar.h>
#ifndef PUGIXML_NO_XPATH #ifndef PUGIXML_NO_XPATH
# include <ctype.h>
# include <math.h> # include <math.h>
# include <float.h> # include <float.h>
#endif #endif
@ -4903,6 +4902,12 @@ namespace
#endif #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) xpath_string string_value(const xpath_node& na)
{ {
if (na.attribute()) if (na.attribute())
@ -7127,7 +7132,7 @@ namespace pugi
// strnicmp / strncasecmp is not portable // strnicmp / strncasecmp is not portable
for (const char_t* lit = lang.c_str(); *lit; ++lit) 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; ++value;
} }

View File

@ -216,7 +216,7 @@ TEST(xpath_boolean_false)
CHECK_XPATH_FAIL(STR("false(1)")); 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; 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 // 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")), 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('zh-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")), STR("lang('zh')"), 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('zh')"), 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('ZH')"), true);
// lang with 1 argument, different language/prefix // 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('')"), false);
CHECK_XPATH_BOOLEAN(doc.child(STR("node")), STR("lang('e')"), 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('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")), STR("lang('r')"), false);
CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")).child(STR("subchild")), STR("lang('en')"), false); CHECK_XPATH_BOOLEAN(doc.child(STR("node")).child(STR("child")).child(STR("subchild")), STR("lang('en')"), false);