aboutsummaryrefslogtreecommitdiff
path: root/xsde/cxx/serializer/generator.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-01-07 13:50:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-01-07 13:50:11 +0200
commit76d23e639004517db8f9469d64ac1789f8449365 (patch)
treedbafc8c4e31a97f74046c98af19d0fe76f360001 /xsde/cxx/serializer/generator.cxx
parentc30caae30bc64974eeaa1e81aa2abdc203f5120d (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/generator.cxx')
-rw-r--r--xsde/cxx/serializer/generator.cxx36
1 files changed, 36 insertions, 0 deletions
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 ()