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/serializer/generator.cxx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'xsde/cxx/serializer/generator.cxx') 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 " << 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 ().default_value ("utf8"); + spec.option ().default_value ("-sskel"); spec.option ().default_value ("_sskel"); spec.option ().default_value ("-simpl"); @@ -1193,6 +1202,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 @@ -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 () -- cgit v1.1