aboutsummaryrefslogtreecommitdiff
path: root/xsd/cxx/elements.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-10-11 14:45:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-10-11 14:45:21 +0200
commit48778e6ccb9dfac96f939584c336a1e8ca7a36ad (patch)
tree68825277d80883e6568ef7ec30bc63af722068e9 /xsd/cxx/elements.cxx
parent0e70bc69e1a686933a69ba6a60c1ea48f50b327c (diff)
Use a set instead of pre-sorted array for keywords
The pre-sorted array approach depends on the character encoding.
Diffstat (limited to 'xsd/cxx/elements.cxx')
-rw-r--r--xsd/cxx/elements.cxx175
1 files changed, 89 insertions, 86 deletions
diff --git a/xsd/cxx/elements.cxx b/xsd/cxx/elements.cxx
index 2bd29bb..3cd5e9e 100644
--- a/xsd/cxx/elements.cxx
+++ b/xsd/cxx/elements.cxx
@@ -10,7 +10,6 @@
#include <cctype> // std::toupper
#include <sstream>
#include <iostream>
-#include <algorithm>
using std::wcerr;
using std::endl;
@@ -25,6 +24,87 @@ namespace CXX
return std::toupper (c);
}
+ namespace
+ {
+ WideChar const* keywords[] = {
+ L"NULL",
+ L"and",
+ L"asm",
+ L"auto",
+ L"bitand",
+ L"bitor",
+ L"bool",
+ L"break",
+ L"case",
+ L"catch",
+ L"char",
+ L"class",
+ L"compl",
+ L"const",
+ L"const_cast",
+ L"continue",
+ L"default",
+ L"delete",
+ L"do",
+ L"double",
+ L"dynamic_cast",
+ L"else",
+ L"end_eq",
+ L"enum",
+ L"explicit",
+ L"export",
+ L"extern",
+ L"false",
+ L"float",
+ L"for",
+ L"friend",
+ L"goto",
+ L"if",
+ L"inline",
+ L"int",
+ L"long",
+ L"mutable",
+ L"namespace",
+ L"new",
+ L"not",
+ L"not_eq",
+ L"operator",
+ L"or",
+ L"or_eq",
+ L"private",
+ L"protected",
+ L"public",
+ L"register",
+ L"reinterpret_cast",
+ L"return",
+ L"short",
+ L"signed",
+ L"sizeof",
+ L"static",
+ L"static_cast",
+ L"struct",
+ L"switch",
+ L"template",
+ L"this",
+ L"throw",
+ L"true",
+ L"try",
+ L"typedef",
+ L"typeid",
+ L"typename",
+ L"union",
+ L"unsigned",
+ L"using",
+ L"virtual",
+ L"void",
+ L"volatile",
+ L"wchar_t",
+ L"while",
+ L"xor",
+ L"xor_eq"
+ };
+ }
+
// Context
//
@@ -68,7 +148,8 @@ namespace CXX
nsm_mapping (nsm_mapping_),
include_mapping (include_mapping_),
trace_include_regex (trace_include_regex_),
- reserved_name_map (reserved_name_map_)
+ reserved_name_map (reserved_name_map_),
+ keyword_set (keyword_set_)
{
// Resolve and cache XML Schema namespace.
//
@@ -167,6 +248,11 @@ namespace CXX
else
reserved_name_map_[String (s, 0, pos)] = String (s, pos + 1);
}
+
+ // Populate the keyword set.
+ //
+ for (Size i (0); i < sizeof (keywords) / sizeof (char*); ++i)
+ keyword_set_.insert (keywords[i]);
}
String Context::
@@ -415,87 +501,6 @@ namespace CXX
return *b;
}
- namespace
- {
- WideChar const* keywords[] = {
- L"NULL",
- L"and",
- L"asm",
- L"auto",
- L"bitand",
- L"bitor",
- L"bool",
- L"break",
- L"case",
- L"catch",
- L"char",
- L"class",
- L"compl",
- L"const",
- L"const_cast",
- L"continue",
- L"default",
- L"delete",
- L"do",
- L"double",
- L"dynamic_cast",
- L"else",
- L"end_eq",
- L"enum",
- L"explicit",
- L"export",
- L"extern",
- L"false",
- L"float",
- L"for",
- L"friend",
- L"goto",
- L"if",
- L"inline",
- L"int",
- L"long",
- L"mutable",
- L"namespace",
- L"new",
- L"not",
- L"not_eq",
- L"operator",
- L"or",
- L"or_eq",
- L"private",
- L"protected",
- L"public",
- L"register",
- L"reinterpret_cast",
- L"return",
- L"short",
- L"signed",
- L"sizeof",
- L"static",
- L"static_cast",
- L"struct",
- L"switch",
- L"template",
- L"this",
- L"throw",
- L"true",
- L"try",
- L"typedef",
- L"typeid",
- L"typename",
- L"union",
- L"unsigned",
- L"using",
- L"virtual",
- L"void",
- L"volatile",
- L"wchar_t",
- L"while",
- L"xor",
- L"xor_eq"
- };
- }
-
String Context::
escape (String const& name)
{
@@ -546,9 +551,7 @@ namespace CXX
// Keywords
//
- Size const size (sizeof (keywords) / sizeof (WideChar*));
-
- if (std::binary_search (keywords, keywords + size, r))
+ if (keyword_set.find (r) != keyword_set.end ())
{
r += L'_';