From 76d23e639004517db8f9469d64ac1789f8449365 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 7 Jan 2010 13:50:11 +0200 Subject: 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. --- xsde/cxx/hybrid/cli.hxx | 2 ++ xsde/cxx/hybrid/elements.cxx | 1 + xsde/cxx/hybrid/generator.cxx | 38 +++++++++++++++++++++++++++ xsde/cxx/hybrid/parser-name-processor.cxx | 1 + xsde/cxx/hybrid/serializer-name-processor.cxx | 1 + xsde/cxx/hybrid/tree-name-processor.cxx | 1 + xsde/cxx/hybrid/tree-type-map.cxx | 1 + xsde/cxx/hybrid/validator.cxx | 12 +++++++++ 8 files changed, 57 insertions(+) (limited to 'xsde/cxx/hybrid') diff --git a/xsde/cxx/hybrid/cli.hxx b/xsde/cxx/hybrid/cli.hxx index ff89942..3834767 100644 --- a/xsde/cxx/hybrid/cli.hxx +++ b/xsde/cxx/hybrid/cli.hxx @@ -23,6 +23,7 @@ namespace CXX typedef Char const Key[]; + extern Key char_encoding; extern Key no_stl; extern Key no_iostream; extern Key no_exceptions; @@ -112,6 +113,7 @@ namespace CXX extern Key proprietary_license; typedef Cult::CLI::Options< + char_encoding, NarrowString, no_stl, Boolean, no_iostream, Boolean, no_exceptions, Boolean, diff --git a/xsde/cxx/hybrid/elements.cxx b/xsde/cxx/hybrid/elements.cxx index e08cf8b..27e983a 100644 --- a/xsde/cxx/hybrid/elements.cxx +++ b/xsde/cxx/hybrid/elements.cxx @@ -20,6 +20,7 @@ namespace CXX root, "name", "char", + ops.value (), ops.value (), ops.value (), "", // export symbol diff --git a/xsde/cxx/hybrid/generator.cxx b/xsde/cxx/hybrid/generator.cxx index 311d5d7..14cba6a 100644 --- a/xsde/cxx/hybrid/generator.cxx +++ b/xsde/cxx/hybrid/generator.cxx @@ -111,6 +111,7 @@ namespace CXX { namespace CLI { + extern Key char_encoding = "char-encoding"; extern Key no_stl = "no-stl"; extern Key no_iostream = "no-iostream"; extern Key no_exceptions = "no-exceptions"; @@ -207,6 +208,12 @@ namespace CXX std::wostream& e (wcerr); ::CLI::Indent::Clip< ::CLI::OptionsUsage, WideChar> clip (e); + e << "--char-encoding " << endl + << " Specify the character encoding that should be\n" + << " used in the object model. Valid values are 'utf8'\n" + << " (default) and 'iso8859-1'." + << endl; + e << "--no-stl" << endl << " Generate code that does not use STL." << endl; @@ -704,6 +711,8 @@ namespace CXX { CLI::OptionsSpec spec; + spec.option ().default_value ("utf8"); + spec.option ().default_value ("-pskel"); spec.option ().default_value ("-sskel"); spec.option ().default_value ("_pskel"); @@ -814,6 +823,7 @@ namespace CXX Evptr r (new P::Options); + r->value () = h.value (); r->value () = h.value (); r->value () = h.value (); r->value () = h.value (); @@ -895,6 +905,7 @@ namespace CXX Evptr r (new S::Options); + r->value () = h.value (); r->value () = h.value (); r->value () = h.value (); r->value () = h.value (); @@ -1527,6 +1538,25 @@ namespace CXX hxx << "#include " << endl << endl; + if (ops.value () == "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 ()) { hxx << "#ifdef XSDE_STL" << endl @@ -2613,6 +2643,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/hybrid/parser-name-processor.cxx b/xsde/cxx/hybrid/parser-name-processor.cxx index a8d3639..afb0df4 100644 --- a/xsde/cxx/hybrid/parser-name-processor.cxx +++ b/xsde/cxx/hybrid/parser-name-processor.cxx @@ -36,6 +36,7 @@ namespace CXX root, "name", "char", + ops.value (), ops.value (), ops.value (), "", // export symbol diff --git a/xsde/cxx/hybrid/serializer-name-processor.cxx b/xsde/cxx/hybrid/serializer-name-processor.cxx index 34f205a..5da88b9 100644 --- a/xsde/cxx/hybrid/serializer-name-processor.cxx +++ b/xsde/cxx/hybrid/serializer-name-processor.cxx @@ -35,6 +35,7 @@ namespace CXX root, "name", "char", + ops.value (), ops.value (), ops.value (), "", // export symbol diff --git a/xsde/cxx/hybrid/tree-name-processor.cxx b/xsde/cxx/hybrid/tree-name-processor.cxx index 2ee30ef..b2a2c69 100644 --- a/xsde/cxx/hybrid/tree-name-processor.cxx +++ b/xsde/cxx/hybrid/tree-name-processor.cxx @@ -38,6 +38,7 @@ namespace CXX root, "name", "char", + ops.value (), ops.value (), ops.value (), "", // export symbol diff --git a/xsde/cxx/hybrid/tree-type-map.cxx b/xsde/cxx/hybrid/tree-type-map.cxx index 5f1c36b..1b22ff9 100644 --- a/xsde/cxx/hybrid/tree-type-map.cxx +++ b/xsde/cxx/hybrid/tree-type-map.cxx @@ -27,6 +27,7 @@ namespace CXX root, "name", "char", + ops.value (), ops.value (), ops.value (), "", // export symbol diff --git a/xsde/cxx/hybrid/validator.cxx b/xsde/cxx/hybrid/validator.cxx index f95bd96..716f072 100644 --- a/xsde/cxx/hybrid/validator.cxx +++ b/xsde/cxx/hybrid/validator.cxx @@ -489,6 +489,18 @@ namespace CXX Boolean valid (true); ValidationContext ctx (root, options, disabled_warnings, valid); + // + // + NarrowString enc (options.value ()); + + if (enc != "utf8" && enc != "iso8859-1") + { + wcerr << "error: unknown encoding '" << enc.c_str () << "'" << endl; + return false; + } + + // + // Boolean par (options.value ()); Boolean ser (options.value ()); Boolean agg (options.value ()); -- cgit v1.1