diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-01-07 13:50:11 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-01-07 13:50:11 +0200 |
commit | 76d23e639004517db8f9469d64ac1789f8449365 (patch) | |
tree | dbafc8c4e31a97f74046c98af19d0fe76f360001 /xsde/cxx/serializer | |
parent | c30caae30bc64974eeaa1e81aa2abdc203f5120d (diff) |
Add support for ISO-8859-1 as application encoding
New runtime configuration parameter, XSDE_ENCODING. New option,
--char-encoding. New test, tests/cxx/hybrid/iso8859-1.
Diffstat (limited to 'xsde/cxx/serializer')
-rw-r--r-- | xsde/cxx/serializer/cli.hxx | 2 | ||||
-rw-r--r-- | xsde/cxx/serializer/elements.cxx | 1 | ||||
-rw-r--r-- | xsde/cxx/serializer/generator.cxx | 36 | ||||
-rw-r--r-- | xsde/cxx/serializer/name-processor.cxx | 1 | ||||
-rw-r--r-- | xsde/cxx/serializer/validator.cxx | 10 |
5 files changed, 50 insertions, 0 deletions
diff --git a/xsde/cxx/serializer/cli.hxx b/xsde/cxx/serializer/cli.hxx index 41bdde2..d65ca1a 100644 --- a/xsde/cxx/serializer/cli.hxx +++ b/xsde/cxx/serializer/cli.hxx @@ -24,6 +24,7 @@ namespace CXX typedef Char const Key[]; extern Key type_map; + extern Key char_encoding; extern Key no_stl; extern Key no_iostream; extern Key no_exceptions; @@ -85,6 +86,7 @@ namespace CXX typedef Cult::CLI::Options< type_map, Cult::Containers::Vector<NarrowString>, + char_encoding, NarrowString, no_stl, Boolean, no_iostream, Boolean, no_exceptions, Boolean, diff --git a/xsde/cxx/serializer/elements.cxx b/xsde/cxx/serializer/elements.cxx index 495b867..f59a102 100644 --- a/xsde/cxx/serializer/elements.cxx +++ b/xsde/cxx/serializer/elements.cxx @@ -20,6 +20,7 @@ namespace CXX root, "s:name", "char", + ops.value<CLI::char_encoding> (), ops.value<CLI::include_with_brackets> (), ops.value<CLI::include_prefix> (), "", // export symbol diff --git a/xsde/cxx/serializer/generator.cxx b/xsde/cxx/serializer/generator.cxx index c15d603..cf6091d 100644 --- a/xsde/cxx/serializer/generator.cxx +++ b/xsde/cxx/serializer/generator.cxx @@ -111,6 +111,7 @@ namespace CXX namespace CLI { extern Key type_map = "type-map"; + extern Key char_encoding = "char-encoding"; extern Key no_stl = "no-stl"; extern Key no_iostream = "no-iostream"; extern Key no_exceptions = "no-exceptions"; @@ -185,6 +186,12 @@ namespace CXX << " order of appearance and the first match is used." << endl; + e << "--char-encoding <enc>" << endl + << " Specify the character encoding that is used in\n" + << " the text data being serialized. Valid values are\n" + << " 'utf8' (default) and 'iso8859-1'." + << endl; + e << "--no-stl" << endl << " Generate code that does not use STL." << endl; @@ -507,6 +514,8 @@ namespace CXX { CLI::OptionsSpec spec; + spec.option<CLI::char_encoding> ().default_value ("utf8"); + spec.option<CLI::skel_file_suffix> ().default_value ("-sskel"); spec.option<CLI::skel_type_suffix> ().default_value ("_sskel"); spec.option<CLI::impl_file_suffix> ().default_value ("-simpl"); @@ -1193,6 +1202,25 @@ namespace CXX hxx << "#include <xsde/cxx/config.hxx>" << endl << endl; + if (ops.value<CLI::char_encoding> () == "iso8859-1") + { + hxx << "#ifndef XSDE_ENCODING_ISO8859_1" << endl + << "#error the generated code uses the ISO-8859-1 encoding" << + "while the XSD/e runtime does not (reconfigure the runtime " << + "or change the --char-encoding value)" << endl + << "#endif" << endl + << endl; + } + else + { + hxx << "#ifndef XSDE_ENCODING_UTF8" << endl + << "#error the generated code uses the UTF-8 encoding" << + "while the XSD/e runtime does not (reconfigure the runtime " << + "or change the --char-encoding value)" << endl + << "#endif" << endl + << endl; + } + if (ops.value<CLI::no_stl> ()) { hxx << "#ifdef XSDE_STL" << endl @@ -1570,6 +1598,14 @@ namespace CXX return sloc; } + catch (UnrepresentableCharacter const& e) + { + wcerr << "error: character at position " << e.position () << " " + << "in string '" << e.string () << "' is unrepresentable in " + << "the target encoding" << endl; + + throw Failed (); + } catch (NoNamespaceMapping const& e) { wcerr << e.file () << ":" << e.line () << ":" << e.column () diff --git a/xsde/cxx/serializer/name-processor.cxx b/xsde/cxx/serializer/name-processor.cxx index e388169..ddc9c4e 100644 --- a/xsde/cxx/serializer/name-processor.cxx +++ b/xsde/cxx/serializer/name-processor.cxx @@ -34,6 +34,7 @@ namespace CXX root, "s:name", "char", + ops.value<CLI::char_encoding> (), ops.value<CLI::include_with_brackets> (), ops.value<CLI::include_prefix> (), "", // export symbol diff --git a/xsde/cxx/serializer/validator.cxx b/xsde/cxx/serializer/validator.cxx index 50948b9..c163459 100644 --- a/xsde/cxx/serializer/validator.cxx +++ b/xsde/cxx/serializer/validator.cxx @@ -410,6 +410,16 @@ namespace CXX // // + NarrowString enc (options.value<CLI::char_encoding> ()); + + if (enc != "utf8" && enc != "iso8859-1") + { + wcerr << "error: unknown encoding '" << enc.c_str () << "'" << endl; + return false; + } + + // + // { Boolean ref (options.value<CLI::root_element_first> ()); Boolean rel (options.value<CLI::root_element_last> ()); |