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 /libxsde/xsde | |
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 'libxsde/xsde')
-rw-r--r-- | libxsde/xsde/cxx/iso8859-1.cxx | 170 | ||||
-rw-r--r-- | libxsde/xsde/cxx/iso8859-1.hxx | 85 | ||||
-rw-r--r-- | libxsde/xsde/cxx/iso8859-1.ixx | 128 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/expat/document.cxx | 375 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/expat/document.hxx | 21 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/expat/document.ixx | 1 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/expat/xml-error.cxx | 10 | ||||
-rw-r--r-- | libxsde/xsde/cxx/parser/expat/xml-error.hxx | 10 | ||||
-rw-r--r-- | libxsde/xsde/cxx/serializer/context.cxx | 702 | ||||
-rw-r--r-- | libxsde/xsde/cxx/serializer/context.hxx | 18 | ||||
-rw-r--r-- | libxsde/xsde/cxx/serializer/context.ixx | 274 | ||||
-rw-r--r-- | libxsde/xsde/makefile | 14 |
12 files changed, 1511 insertions, 297 deletions
diff --git a/libxsde/xsde/cxx/iso8859-1.cxx b/libxsde/xsde/cxx/iso8859-1.cxx new file mode 100644 index 0000000..b52a284 --- /dev/null +++ b/libxsde/xsde/cxx/iso8859-1.cxx @@ -0,0 +1,170 @@ +// file : xsde/cxx/iso8859-1.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/iso8859-1.hxx> + +namespace xsde +{ + namespace cxx + { + char iso8859_1::unrep_char_ = '\0'; + + bool iso8859_1:: + to (const char* s, char* r) + { + for (; *s != 0; ++s) + { + unsigned char c (*s); + + if (c < 0x80) + { + // Fast path. + // + *r++ = c; + continue; + } + else if ((c >> 5) == 0x06) + { + // UTF-8: 110yyyyy 10zzzzzz + // Unicode: 00000yyy yyzzzzzz + // + unsigned int u = (c & 0x1F) << 6; + c = *++s; + u |= c & 0x3F; + + if (u < 0x100) + { + *r++ = static_cast<char> (u); + continue; + } + } + else if ((c >> 4) == 0x0E) + { + // UTF-8: 1110xxxx 10yyyyyy 10zzzzzz + // Unicode: xxxxyyyy yyzzzzzz + // + s += 2; + } + else if ((c >> 3) == 0x1E) + { + // UTF-8: 000wwwxx xxxxyyyy yyzzzzzz + // Unicode: 11110www 10xxxxxx 10yyyyyy 10zzzzzz + // + s += 3; + } + + if (unrep_char_ != '\0') + *r++ = unrep_char_; + else + return false; + } + + *r = '\0'; + + return true; + } + + bool iso8859_1:: + to (const char* s, size_t n, char* r) + { + const char* end = s + n; + + for (; s != end; ++s) + { + unsigned char c (*s); + + if (c < 0x80) + { + // Fast path. + // + *r++ = c; + continue; + } + else if ((c >> 5) == 0x06) + { + // UTF-8: 110yyyyy 10zzzzzz + // Unicode: 00000yyy yyzzzzzz + // + unsigned int u = (c & 0x1F) << 6; + c = *++s; + u |= c & 0x3F; + + if (u < 0x100) + { + *r++ = static_cast<char> (u); + continue; + } + } + else if ((c >> 4) == 0x0E) + { + // UTF-8: 1110xxxx 10yyyyyy 10zzzzzz + // Unicode: xxxxyyyy yyzzzzzz + // + s += 2; + } + else if ((c >> 3) == 0x1E) + { + // UTF-8: 000wwwxx xxxxyyyy yyzzzzzz + // Unicode: 11110www 10xxxxxx 10yyyyyy 10zzzzzz + // + s += 3; + } + + if (unrep_char_ != '\0') + *r++ = unrep_char_; + else + return false; + } + + *r = '\0'; + + return true; + } + + void iso8859_1:: + from (const char* s, char* r) + { + for (; *s != 0; ++s) + { + unsigned char c (*s); + + if (c < 0x80) + *r++ = c; + else + { + // 2-byte sequence. + // + *r++ = (c >> 6) | 0xC0; + *r++ = (c | 0x80) & 0xBF; + } + } + + *r = '\0'; + } + + void iso8859_1:: + from (const char* s, size_t n, char* r) + { + const char* end = s + n; + + for (; s != end; ++s) + { + unsigned char c (*s); + + if (c < 0x80) + *r++ = c; + else + { + // 2-byte sequence. + // + *r++ = (c >> 6) | 0xC0; + *r++ = (c | 0x80) & 0xBF; + } + } + + *r = '\0'; + } + } +} diff --git a/libxsde/xsde/cxx/iso8859-1.hxx b/libxsde/xsde/cxx/iso8859-1.hxx new file mode 100644 index 0000000..5809886 --- /dev/null +++ b/libxsde/xsde/cxx/iso8859-1.hxx @@ -0,0 +1,85 @@ +// file : xsde/cxx/iso8859-1.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_ISO8859_1_HXX +#define XSDE_CXX_ISO8859_1_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + class iso8859_1 + { + public: + // Get/set a replacement for unrepresentable characters. If set to + // 0 (the default value), the conversion fails if such a character + // is encountered. + // + static char + unrep_char () + { + return unrep_char_; + } + + static void + unrep_char (char c) + { + unrep_char_ = c; + } + + public: + // Test whether a UTF-8 string is an ASCII string. If these + // functions return false, the iso_size argument contains + // the size of the buffer needed to convert this string to + // ISO-8859-1. + // + static bool + ascii_utf (const char* utf_str, size_t& iso_size); + + static bool + ascii_utf (const char* utf_str, size_t utf_size, size_t& iso_size); + + // Test whether an ISO-8859-1 string is an ASCII string. If + // these functions return false, the utf_size argument contains + // the size of the buffer needed to convert this string to UTF-8. + // + static bool + ascii_iso (const char* iso_str, size_t& utf_size); + + static bool + ascii_iso (const char* iso_str, size_t iso_size, size_t& utf_size); + + // Convert from UTF-8 to ISO-8859-1. Return false if an + // unrepresentable character was encountered and no replacement + // was specified. + // + // + static bool + to (const char* utf_str, char* iso_str); + + static bool + to (const char* utf_str, size_t utf_size, char* iso_str); + + // Convert from ISO-8859-1 to UTF-8. + // + static void + from (const char* iso_str, char* utf_str); + + static void + from (const char* iso_str, size_t iso_size, char* utf_str); + + private: + static char unrep_char_; + }; + } +} + +#include <xsde/cxx/iso8859-1.ixx> + +#endif // XSDE_CXX_ISO8859_1_HXX diff --git a/libxsde/xsde/cxx/iso8859-1.ixx b/libxsde/xsde/cxx/iso8859-1.ixx new file mode 100644 index 0000000..716be53 --- /dev/null +++ b/libxsde/xsde/cxx/iso8859-1.ixx @@ -0,0 +1,128 @@ +// file : xsde/cxx/iso8859-1.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + inline bool iso8859_1:: + ascii_utf (const char* s, size_t& rn) + { + // NULL string is an ASCII string. + // + if (s == 0) + return true; + + bool r = true; + size_t l = 0; + + for (; *s != 0; ++s, ++l) + { + unsigned char c (*s); + + if (c > 0x7F) + { + if ((c >> 5) == 0x06) + ++s; + else if ((c >> 4) == 0x0E) + s += 2; + else if ((c >> 3) == 0x1E) + s += 3; + + r = false; + } + } + + rn = l + 1; + return r; + } + + inline bool iso8859_1:: + ascii_utf (const char* s, size_t n, size_t& rn) + { + // NULL string is an ASCII string. + // + if (s == 0) + return true; + + bool r = true; + size_t l = 0; + const char* end = s + n; + + for (; s != end; ++s, ++l) + { + unsigned char c (*s); + + if (c > 0x7F) + { + if ((c >> 5) == 0x06) + ++s; + else if ((c >> 4) == 0x0E) + s += 2; + else if ((c >> 3) == 0x1E) + s += 3; + + r = false; + } + } + + rn = l + 1; + return r; + } + + inline bool iso8859_1:: + ascii_iso (const char* s, size_t& rn) + { + // NULL string is an ASCII string. + // + if (s == 0) + return true; + + bool r = true; + size_t l = 0; + + for (; *s != 0; ++s, ++l) + { + unsigned char c (*s); + + if (c > 0x7F) + { + ++l; // 2-byte surrogate. + r = false; + } + } + + rn = l + 1; + return r; + } + + inline bool iso8859_1:: + ascii_iso (const char* s, size_t n, size_t& rn) + { + // NULL string is an ASCII string. + // + if (s == 0) + return true; + + bool r = true; + size_t l = 0; + const char* end = s + n; + + for (; s != end; ++s, ++l) + { + unsigned char c (*s); + + if (c > 0x7F) + { + ++l; // 2-byte surrogate. + r = false; + } + } + + rn = l + 1; + return r; + } + } +} diff --git a/libxsde/xsde/cxx/parser/expat/document.cxx b/libxsde/xsde/cxx/parser/expat/document.cxx index 4bb3ec0..61cc1d0 100644 --- a/libxsde/xsde/cxx/parser/expat/document.cxx +++ b/libxsde/xsde/cxx/parser/expat/document.cxx @@ -17,6 +17,10 @@ # include <fstream> #endif +#ifdef XSDE_ENCODING_ISO8859_1 +# include <xsde/cxx/iso8859-1.hxx> +#endif + #ifdef XSDE_EXCEPTIONS # include <xsde/cxx/parser/exceptions.hxx> #endif @@ -58,6 +62,9 @@ namespace xsde #endif : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) { +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif #ifdef XSDE_POLYMORPHIC polymorphic_ = poly; #endif @@ -77,6 +84,9 @@ namespace xsde #endif : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) { +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif #ifdef XSDE_POLYMORPHIC polymorphic_ = poly; #endif @@ -93,6 +103,9 @@ namespace xsde #endif : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) { +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif #ifdef XSDE_POLYMORPHIC polymorphic_ = poly; #endif @@ -110,6 +123,9 @@ namespace xsde #endif : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) { +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif #ifdef XSDE_POLYMORPHIC polymorphic_ = poly; #endif @@ -120,6 +136,9 @@ namespace xsde document_pimpl () : first_ (true), xml_parser_ (0), context_ (0), parser_ (0) { +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif #ifdef XSDE_POLYMORPHIC polymorphic_ = false; #endif @@ -131,6 +150,9 @@ namespace xsde : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), polymorphic_ (true) { +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif init_root_name (0, n); } @@ -139,6 +161,9 @@ namespace xsde : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), polymorphic_ (true) { +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif init_root_name (ns, n); } @@ -148,6 +173,9 @@ namespace xsde : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), polymorphic_ (true) { +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif init_root_name (0, n.c_str ()); } @@ -156,6 +184,9 @@ namespace xsde : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), polymorphic_ (true) { +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif init_root_name (ns.c_str (), n.c_str ()); } #endif // XSDE_STL @@ -208,6 +239,10 @@ namespace xsde #ifndef XSDE_EXCEPTIONS error_ = error (); #endif + +#ifdef XSDE_ENCODING_ISO8859_1 + xml_error_ = 0; +#endif first_ = true; if (parser_) @@ -405,6 +440,18 @@ namespace xsde // if (e == XML_ERROR_ABORTED) { +#ifdef XSDE_ENCODING_ISO8859_1 + if (xml_error_ != 0) + { +#ifdef XSDE_EXCEPTIONS + throw xml (xml_error_, l, c); +#else + error_ = error (xml_error_, l, c); + return; +#endif + } +#endif + // Got to be either a system, schema, or application // level error. // @@ -584,11 +631,35 @@ namespace xsde return; } + // Convert to application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* ans_name = ns_name; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* ans_name; + size_t an; + string buf; + + if (iso8859_1::ascii_utf (ns_name, an)) + ans_name = ns_name; + else + { + ans_name = conv_name (ns_name, an, buf); + + if (ans_name == 0) + { + XML_StopParser (xml_parser_, false); + return; + } + } + +#endif // XSDE_ENCODING_* + const char* ns_p; const char* name_p; size_t ns_s, name_s; - bits::split_name (ns_name, ns_p, ns_s, name_p, name_s); + bits::split_name (ans_name, ns_p, ns_s, name_p, name_s); parser_state& cur = context_.current_; @@ -602,7 +673,10 @@ namespace xsde if (polymorphic_) { - // Search for the xsi:type attribute. + // Search for the xsi:type attribute. The name and + // namespace of the attribute that we are looking for + // are ASCII strings so we don't need to convert it to + // the application encoding. // const XML_Char** p = atts; // VC8 can't handle p (atts) for (; *p != 0; p += 2) @@ -622,9 +696,34 @@ namespace xsde // @@ Need proper QName validation. // + + // Convert the type name to the application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* av = *(p + 1); +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* av; + size_t an; + string buf; + + if (iso8859_1::ascii_utf (*(p + 1), an)) + av = *(p + 1); + else + { + av = conv_data (*(p + 1), an, buf); + + if (av == 0) + { + XML_StopParser (xml_parser_, false); + return; + } + } + +#endif // XSDE_ENCODING_* + // Get the qualified type name and try to resolve it. // - ro_string qn (*(p + 1)); + ro_string qn (av); ro_string tp, tn; size_t pos = qn.find (':'); @@ -834,10 +933,53 @@ namespace xsde { for (; *atts != 0; atts += 2) { - bits::split_name (*atts, ns_p, ns_s, name_p, name_s); + // Convert the type name to the application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* aname = *atts; + const char* avalue = *(atts + 1); +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* aname; + const char* avalue; + size_t an; + string nbuf, vbuf; + + // Name. + // + if (iso8859_1::ascii_utf (*atts, an)) + aname = *atts; + else + { + aname = conv_name (*atts, an, nbuf); + + if (aname == 0) + { + XML_StopParser (xml_parser_, false); + return; + } + } + + // Value. + // + if (iso8859_1::ascii_utf (*(atts + 1), an)) + avalue = *(atts + 1); + else + { + avalue = conv_data (*(atts + 1), an, vbuf); + + if (avalue == 0) + { + XML_StopParser (xml_parser_, false); + return; + } + } + +#endif // XSDE_ENCODING_* + + bits::split_name (aname, ns_p, ns_s, name_p, name_s); const ro_string ns (ns_p, ns_s), name (name_p, name_s); - const ro_string value (*(atts + 1)); + const ro_string value (avalue); if (!cur.any_) cur.parser_->_attribute (ns, name, value); @@ -867,19 +1009,41 @@ namespace xsde return; } + // Convert to application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* ans_name = ns_name; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* ans_name; + size_t an; + string buf; + + if (iso8859_1::ascii_utf (ns_name, an)) + ans_name = ns_name; + else + { + ans_name = conv_name (ns_name, an, buf); + + if (ans_name == 0) + { + XML_StopParser (xml_parser_, false); + return; + } + } + +#endif // XSDE_ENCODING_* + const char* ns_p; const char* name_p; size_t ns_s, name_s; - bits::split_name (ns_name, ns_p, ns_s, name_p, name_s); + bits::split_name (ans_name, ns_p, ns_s, name_p, name_s); const ro_string ns (ns_p, ns_s); const ro_string name (name_p, name_s); parser_state& cur = context_.current_; - // @@ Error propagation. - // if (cur.depth_ == 0) { // The "normal" case: call _post to pop the parser and then @@ -980,7 +1144,37 @@ namespace xsde if (n != 0 && (cur.depth_ == 0 || cur.any_)) { - const ro_string str (s, n); + // Convert to application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* as = s; + size_t an = n; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* as; + size_t an; + string buf; + + if (iso8859_1::ascii_utf (s, n, an)) + { + as = s; + an = n; + } + else + { + as = conv_data (s, n, an, buf); + + if (as == 0) + { + XML_StopParser (xml_parser_, false); + return; + } + + --an; // Discount trailing zero. + } + +#endif // XSDE_ENCODING_* + + const ro_string str (as, an); if (!cur.any_) cur.parser_->_characters (str); @@ -1003,22 +1197,66 @@ namespace xsde // if (polymorphic_) { -#if defined (XSDE_STL) - prefixes_.push_back (p ? p : ""); - prefix_namespaces_.push_back (ns ? ns : ""); -#else -#if defined (XSDE_EXCEPTIONS) - prefixes_.push_back_copy (p ? p : ""); - prefix_namespaces_.push_back_copy (ns ? ns : ""); + // Convert the type name to the application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* ap = p; + const char* ans = ns; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* ap; + const char* ans; + size_t an; + string pbuf, nsbuf; + + // Prefix. + // + if (p == 0) + ap = 0; + else if (iso8859_1::ascii_utf (p, an)) + ap = p; + else + { + ap = conv_name (p, an, pbuf); + + if (ap == 0) + { + XML_StopParser (xml_parser_, false); + return; + } + } + + // Namespace. + // + if (ns == 0) + ans = 0; + else if (iso8859_1::ascii_utf (ns, an)) + ans = ns; + else + { + ans = conv_data (ns, an, nsbuf); + + if (ans == 0) + { + XML_StopParser (xml_parser_, false); + return; + } + } +#endif // XSDE_ENCODING_* + +#ifdef XSDE_STL + prefixes_.push_back (ap ? ap : ""); + prefix_namespaces_.push_back (ans ? ans : ""); +#elif defined (XSDE_EXCEPTIONS) + prefixes_.push_back_copy (ap ? ap : ""); + prefix_namespaces_.push_back_copy (ans ? ans : ""); #else - if (prefixes_.push_back_copy (p ? p : "" ) || - prefix_namespaces_.push_back_copy (ns ? ns : "")) + if (prefixes_.push_back_copy (ap ? ap : "" ) || + prefix_namespaces_.push_back_copy (ans ? ans : "")) { context_.sys_error (sys_error::no_memory); XML_StopParser (xml_parser_, false); } #endif -#endif } } @@ -1038,6 +1276,105 @@ namespace xsde } } #endif // XSDE_POLYMORPHIC + + // + // Support for ISO-8859-1 conversion. + // + +#ifdef XSDE_ENCODING_ISO8859_1 + const char* document_pimpl:: + conv_data (const XML_Char* utf_s, size_t iso_n, string& var) + { + char* buf; + + if (iso_n <= sizeof (data_buf_)) + buf = data_buf_; + else + { + buf = new char[iso_n]; + +#ifndef XSDE_EXCEPTIONS + if (buf == 0) + { + context_.sys_error (sys_error::no_memory); + return 0; + } +#endif + var.attach (buf, iso_n - 1); + } + + if (!iso8859_1::to (utf_s, buf)) + { + xml_error_ = XML_ERROR_UNREPRESENTABLE; + return 0; + } + + return buf; + } + + const char* document_pimpl:: + conv_data (const XML_Char* utf_s, + size_t utf_n, + size_t iso_n, + string& var) + { + char* buf; + + if (iso_n <= sizeof (data_buf_)) + buf = data_buf_; + else + { + buf = new char[iso_n]; + +#ifndef XSDE_EXCEPTIONS + if (buf == 0) + { + context_.sys_error (sys_error::no_memory); + return 0; + } +#endif + var.attach (buf, iso_n - 1); + } + + if (!iso8859_1::to (utf_s, utf_n, buf)) + { + xml_error_ = XML_ERROR_UNREPRESENTABLE; + return 0; + } + + return buf; + } + + const char* document_pimpl:: + conv_name (const XML_Char* utf_s, size_t iso_n, string& var) + { + char* buf; + + if (iso_n <= sizeof (name_buf_)) + buf = name_buf_; + else + { + buf = new char[iso_n]; + +#ifndef XSDE_EXCEPTIONS + if (buf == 0) + { + context_.sys_error (sys_error::no_memory); + return 0; + } +#endif + var.attach (buf, iso_n - 1); + } + + if (!iso8859_1::to (utf_s, buf)) + { + xml_error_ = XML_ERROR_UNREPRESENTABLE; + return 0; + } + + return buf; + } +#endif // XSDE_ENCODING_ISO8859_1 } } } diff --git a/libxsde/xsde/cxx/parser/expat/document.hxx b/libxsde/xsde/cxx/parser/expat/document.hxx index afa7625..df3bf21 100644 --- a/libxsde/xsde/cxx/parser/expat/document.hxx +++ b/libxsde/xsde/cxx/parser/expat/document.hxx @@ -323,6 +323,27 @@ namespace xsde error error_; #endif + // Support for ISO-8859-1 conversion. + // +#ifdef XSDE_ENCODING_ISO8859_1 + protected: + const char* + conv_data (const XML_Char* utf_s, size_t iso_n, string& var); + + const char* + conv_data (const XML_Char* utf_s, + size_t utf_n, + size_t iso_n, + string& var); + + const char* + conv_name (const XML_Char* utf_s, size_t iso_n, string& var); + + xml_error xml_error_; + + char data_buf_[256]; + char name_buf_[128]; +#endif private: void init_root_name (const char* ns, const char* name); diff --git a/libxsde/xsde/cxx/parser/expat/document.ixx b/libxsde/xsde/cxx/parser/expat/document.ixx index 72451ee..16d6ef7 100644 --- a/libxsde/xsde/cxx/parser/expat/document.ixx +++ b/libxsde/xsde/cxx/parser/expat/document.ixx @@ -50,4 +50,3 @@ namespace xsde } } } - diff --git a/libxsde/xsde/cxx/parser/expat/xml-error.cxx b/libxsde/xsde/cxx/parser/expat/xml-error.cxx index cb7b904..b5f15a4 100644 --- a/libxsde/xsde/cxx/parser/expat/xml-error.cxx +++ b/libxsde/xsde/cxx/parser/expat/xml-error.cxx @@ -13,13 +13,19 @@ namespace xsde { namespace expat { + static const char* const text_[] = + { + "character unrepresentable in application encoding" + }; + const char* xml_error_text (xml_error e) { - return XML_ErrorString (e); + return e < 0x10000 + ? XML_ErrorString (static_cast<XML_Error> (e)) + : text_[e & 0xFFFF]; } } } } } - diff --git a/libxsde/xsde/cxx/parser/expat/xml-error.hxx b/libxsde/xsde/cxx/parser/expat/xml-error.hxx index 6e28687..5871b48 100644 --- a/libxsde/xsde/cxx/parser/expat/xml-error.hxx +++ b/libxsde/xsde/cxx/parser/expat/xml-error.hxx @@ -8,6 +8,11 @@ #include <xsde/c/expat/expat.h> +enum XML_Error_Ex +{ + XML_ERROR_UNREPRESENTABLE = 0x10000 +}; + namespace xsde { namespace cxx @@ -16,7 +21,10 @@ namespace xsde { namespace expat { - typedef XML_Error xml_error; + // The xml_error type can hold values from XML_Error and + // XML_Error_Ex enums. + // + typedef unsigned int xml_error; const char* xml_error_text (xml_error); diff --git a/libxsde/xsde/cxx/serializer/context.cxx b/libxsde/xsde/cxx/serializer/context.cxx index 650bed2..faa1ed4 100644 --- a/libxsde/xsde/cxx/serializer/context.cxx +++ b/libxsde/xsde/cxx/serializer/context.cxx @@ -3,6 +3,8 @@ // copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include <assert.h> + #include <xsde/cxx/config.hxx> #include <xsde/cxx/ro-string.hxx> @@ -11,6 +13,10 @@ # include <xsde/cxx/serializer/exceptions.hxx> #endif +#ifdef XSDE_ENCODING_ISO8859_1 +# include <xsde/cxx/iso8859-1.hxx> +#endif + #include <xsde/cxx/serializer/context.hxx> namespace xsde @@ -19,6 +25,625 @@ namespace xsde { namespace serializer { + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + start_element (const char* name) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* uname = name; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* uname; + size_t un; + string buf; + + if (iso8859_1::ascii_iso (name, un)) + uname = name; + else + { + uname = conv_name (name, un, name_buf1_, buf); + +#ifndef XSDE_EXCEPTIONS + if (uname == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxStartElementLiteral ( + xml_serializer_, + 0, + reinterpret_cast<constUtf8> (uname)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + start_element (const char* ns, const char* name) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* uns = ns; + const char* uname = name; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* uns; + const char* uname; + size_t un; + string buf1, buf2; + + if (iso8859_1::ascii_iso (ns, un)) + uns = ns; + else + { + uns = conv_name (ns, un, name_buf1_, buf1); + +#ifndef XSDE_EXCEPTIONS + if (uns == 0) + return false; +#endif + } + + if (iso8859_1::ascii_iso (name, un)) + uname = name; + else + { + uname = conv_name (name, un, name_buf2_, buf2); + +#ifndef XSDE_EXCEPTIONS + if (uname == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxStartElementLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (uns), + reinterpret_cast<constUtf8> (uname)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + start_attribute (const char* name) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* uname = name; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* uname; + size_t un; + string buf; + + if (iso8859_1::ascii_iso (name, un)) + uname = name; + else + { + uname = conv_name (name, un, name_buf1_, buf); + +#ifndef XSDE_EXCEPTIONS + if (uname == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxStartAttributeLiteral ( + xml_serializer_, + 0, + reinterpret_cast<constUtf8> (uname)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + start_attribute (const char* ns, const char* name) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* uns = ns; + const char* uname = name; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* uns; + const char* uname; + size_t un; + string buf1, buf2; + + if (iso8859_1::ascii_iso (ns, un)) + uns = ns; + else + { + uns = conv_name (ns, un, name_buf1_, buf1); + +#ifndef XSDE_EXCEPTIONS + if (uns == 0) + return false; +#endif + } + + if (iso8859_1::ascii_iso (name, un)) + uname = name; + else + { + uname = conv_name (name, un, name_buf2_, buf2); + +#ifndef XSDE_EXCEPTIONS + if (uname == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxStartAttributeLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (uns), + reinterpret_cast<constUtf8> (uname)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + attribute (const char* name, const char* value) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* uname = name; + const char* uvalue = value; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* uname; + const char* uvalue; + size_t un; + string buf1, buf2; + + if (iso8859_1::ascii_iso (name, un)) + uname = name; + else + { + uname = conv_name (name, un, name_buf1_, buf1); + +#ifndef XSDE_EXCEPTIONS + if (uname == 0) + return false; +#endif + } + + if (iso8859_1::ascii_iso (value, un)) + uvalue = value; + else + { + uvalue = conv_data (value, un, buf2); + +#ifndef XSDE_EXCEPTIONS + if (uvalue == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxAddAttributeLiteral ( + xml_serializer_, + 0, + reinterpret_cast<constUtf8> (uname), + reinterpret_cast<constUtf8> (uvalue)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + attribute (const char* ns, const char* name, const char* value) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* uns = ns; + const char* uname = name; + const char* uvalue = value; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* uns; + const char* uname; + const char* uvalue; + size_t un; + string buf1, buf2, buf3; + + if (iso8859_1::ascii_iso (ns, un)) + uns = ns; + else + { + uns = conv_name (ns, un, name_buf1_, buf1); + +#ifndef XSDE_EXCEPTIONS + if (uns == 0) + return false; +#endif + } + + if (iso8859_1::ascii_iso (name, un)) + uname = name; + else + { + uname = conv_name (name, un, name_buf2_, buf2); + +#ifndef XSDE_EXCEPTIONS + if (uname == 0) + return false; +#endif + } + + if (iso8859_1::ascii_iso (value, un)) + uvalue = value; + else + { + uvalue = conv_data (value, un, buf3); + +#ifndef XSDE_EXCEPTIONS + if (uvalue == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxAddAttributeLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (uns), + reinterpret_cast<constUtf8> (uname), + reinterpret_cast<constUtf8> (uvalue)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + characters (const char* s) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* us = s; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* us; + size_t un; + string buf; + + if (iso8859_1::ascii_iso (s, un)) + us = s; + else + { + us = conv_data (s, un, buf); + +#ifndef XSDE_EXCEPTIONS + if (us == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxAddText ( + xml_serializer_, + reinterpret_cast<constUtf8> (us)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + characters (const char* s, size_t n) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* us = s; + size_t un = n; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* us; + size_t un; + string buf; + + if (iso8859_1::ascii_iso (s, n, un)) + { + us = s; + un = n; + } + else + { + us = conv_data (s, n, un, buf); + +#ifndef XSDE_EXCEPTIONS + if (us == 0) + return false; +#endif + --un; // Discount trailing zero. + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxAddCountedText ( + xml_serializer_, + reinterpret_cast<constUtf8> (us), + static_cast<int> (un)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + declare_namespace (const char* ns, const char* prefix) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* uns = ns; + const char* uprefix = prefix; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* uns; + const char* uprefix; + size_t un; + string buf1, buf2; + + if (iso8859_1::ascii_iso (ns, un)) + uns = ns; + else + { + uns = conv_name (ns, un, name_buf1_, buf1); + +#ifndef XSDE_EXCEPTIONS + if (uns == 0) + return false; +#endif + } + + if (iso8859_1::ascii_iso (prefix, un)) + uprefix = prefix; + else + { + uprefix = conv_name (prefix, un, name_buf2_, buf2); + +#ifndef XSDE_EXCEPTIONS + if (uprefix == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxAddNamespaceLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (uns), + reinterpret_cast<constUtf8> (uprefix)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + declare_default_namespace (const char* ns) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* uns = ns; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* uns; + size_t un; + string buf; + + if (iso8859_1::ascii_iso (ns, un)) + uns = ns; + else + { + uns = conv_name (ns, un, name_buf1_, buf); + +#ifndef XSDE_EXCEPTIONS + if (uns == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e = genxAddNamespaceLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (uns), + reinterpret_cast<constUtf8> ("")); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // + const char* context:: + lookup_namespace_prefix (const char* ns) + { + // Convert from application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + const char* uns = ns; +#elif defined(XSDE_ENCODING_ISO8859_1) + const char* uns; + size_t un; + string buf; + + if (iso8859_1::ascii_iso (ns, un)) + uns = ns; + else + { + uns = conv_name (ns, un, name_buf1_, buf); + +#ifndef XSDE_EXCEPTIONS + if (uns == 0) + return false; +#endif + } +#endif // XSDE_ENCODING_* + + genxStatus e; + genxNamespace gns = genxDeclareNamespace ( + xml_serializer_, reinterpret_cast<constUtf8> (uns), 0, &e); + + if (e != GENX_SUCCESS) + { +#ifdef XSDE_EXCEPTIONS + throw_xml_error (e); +#else + xml_error (e); +#endif + return 0; + } + + const char* p = reinterpret_cast<const char*> ( + genxGetNamespacePrefix (gns)); + + // Convert to application encoding. + // +#ifdef XSDE_ENCODING_UTF8 + return p; +#elif defined(XSDE_ENCODING_ISO8859_1) + // At the moment we can only support ASCII prefixes since there is + // no good way to store the converted string. + // + assert (iso8859_1::ascii_utf (p, un)); + return p; +#endif // XSDE_ENCODING_* + } + + // + // #ifdef XSDE_POLYMORPHIC #ifdef XSDE_EXCEPTIONS void context:: @@ -102,6 +727,83 @@ namespace xsde } } #endif + +#ifdef XSDE_ENCODING_ISO8859_1 + const char* context:: + conv_data (const char* iso_s, size_t utf_n, string& var) + { + char* buf; + + if (utf_n <= sizeof (data_buf_)) + buf = data_buf_; + else + { + buf = new char[utf_n]; + +#ifndef XSDE_EXCEPTIONS + if (buf == 0) + { + sys_error (sys_error::no_memory); + return 0; + } +#endif + var.attach (buf, utf_n - 1); + } + + iso8859_1::from (iso_s, buf); + return buf; + } + + const char* context:: + conv_data (const char* iso_s, size_t iso_n, size_t utf_n, string& var) + { + char* buf; + + if (utf_n <= sizeof (data_buf_)) + buf = data_buf_; + else + { + buf = new char[utf_n]; + +#ifndef XSDE_EXCEPTIONS + if (buf == 0) + { + sys_error (sys_error::no_memory); + return 0; + } +#endif + var.attach (buf, utf_n - 1); + } + + iso8859_1::from (iso_s, iso_n, buf); + return buf; + } + + const char* context:: + conv_name (const char* iso_s, size_t utf_n, char* fix, string& var) + { + char* buf; + + if (utf_n <= sizeof (name_buf1_)) + buf = fix; + else + { + buf = new char[utf_n]; + +#ifndef XSDE_EXCEPTIONS + if (buf == 0) + { + sys_error (sys_error::no_memory); + return 0; + } +#endif + var.attach (buf, utf_n - 1); + } + + iso8859_1::from (iso_s, buf); + return buf; + } +#endif // XSDE_ENCODING_ISO8859_1 } } } diff --git a/libxsde/xsde/cxx/serializer/context.hxx b/libxsde/xsde/cxx/serializer/context.hxx index d09bb4d..d2cec00 100644 --- a/libxsde/xsde/cxx/serializer/context.hxx +++ b/libxsde/xsde/cxx/serializer/context.hxx @@ -11,6 +11,7 @@ #include <stddef.h> // size_t #include <xsde/c/genx/genx.h> +#include <xsde/cxx/string.hxx> #ifndef XSDE_EXCEPTIONS # include <xsde/cxx/sys-error.hxx> @@ -251,6 +252,23 @@ namespace xsde const void* type_id_; #endif + // Support for ISO-8859-1 conversion. + // +#ifdef XSDE_ENCODING_ISO8859_1 + protected: + const char* + conv_data (const char* iso_s, size_t utf_n, string& var); + + const char* + conv_data (const char* iso_s, size_t iso_n, size_t utf_n, string& var); + + const char* + conv_name (const char* iso_s, size_t utf_n, char* fix, string& var); + + char data_buf_[256]; + char name_buf1_[128]; + char name_buf2_[128]; // Keep buf1 and buf2 sizes the same. +#endif }; } } diff --git a/libxsde/xsde/cxx/serializer/context.ixx b/libxsde/xsde/cxx/serializer/context.ixx index 04cfe87..3612f0a 100644 --- a/libxsde/xsde/cxx/serializer/context.ixx +++ b/libxsde/xsde/cxx/serializer/context.ixx @@ -45,56 +45,6 @@ namespace xsde #else inline bool context:: #endif - start_element (const char* name) - { - genxStatus e = genxStartElementLiteral ( - xml_serializer_, - 0, - reinterpret_cast<constUtf8> (name)); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif - start_element (const char* ns, const char* name) - { - genxStatus e = genxStartElementLiteral ( - xml_serializer_, - reinterpret_cast<constUtf8> (ns), - reinterpret_cast<constUtf8> (name)); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif end_element () { genxStatus e = genxEndElement (xml_serializer_); @@ -117,56 +67,6 @@ namespace xsde #else inline bool context:: #endif - start_attribute (const char* name) - { - genxStatus e = genxStartAttributeLiteral ( - xml_serializer_, - 0, - reinterpret_cast<constUtf8> (name)); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif - start_attribute (const char* ns, const char* name) - { - genxStatus e = genxStartAttributeLiteral ( - xml_serializer_, - reinterpret_cast<constUtf8> (ns), - reinterpret_cast<constUtf8> (name)); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif end_attribute () { genxStatus e = genxEndAttribute (xml_serializer_); @@ -189,157 +89,6 @@ namespace xsde #else inline bool context:: #endif - attribute (const char* name, const char* value) - { - genxStatus e = genxAddAttributeLiteral ( - xml_serializer_, - 0, - reinterpret_cast<constUtf8> (name), - reinterpret_cast<constUtf8> (value)); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif - attribute (const char* ns, const char* name, const char* value) - { - genxStatus e = genxAddAttributeLiteral ( - xml_serializer_, - reinterpret_cast<constUtf8> (ns), - reinterpret_cast<constUtf8> (name), - reinterpret_cast<constUtf8> (value)); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif - characters (const char* s) - { - genxStatus e = genxAddText ( - xml_serializer_, - reinterpret_cast<constUtf8> (s)); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif - characters (const char* s, size_t n) - { - genxStatus e = genxAddCountedText ( - xml_serializer_, - reinterpret_cast<constUtf8> (s), - static_cast<int> (n)); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif - declare_namespace (const char* ns, const char* prefix) - { - genxStatus e = genxAddNamespaceLiteral ( - xml_serializer_, - reinterpret_cast<constUtf8> (ns), - reinterpret_cast<constUtf8> (prefix)); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif - declare_default_namespace (const char* ns) - { - genxStatus e = genxAddNamespaceLiteral ( - xml_serializer_, - reinterpret_cast<constUtf8> (ns), - reinterpret_cast<constUtf8> ("")); - -#ifdef XSDE_EXCEPTIONS - if (e != GENX_SUCCESS) - throw_xml_error (e); -#else - if (e != GENX_SUCCESS) - xml_error (e); - - return e == GENX_SUCCESS; -#endif - } - - // - // -#ifdef XSDE_EXCEPTIONS - inline void context:: -#else - inline bool context:: -#endif clear_default_namespace () { genxStatus e = genxUnsetDefaultNamespace (xml_serializer_); @@ -357,29 +106,6 @@ namespace xsde // // - inline const char* context:: - lookup_namespace_prefix (const char* ns) - { - genxStatus e; - genxNamespace gns = genxDeclareNamespace ( - xml_serializer_, reinterpret_cast<constUtf8> (ns), 0, &e); - - if (e != GENX_SUCCESS) - { -#ifdef XSDE_EXCEPTIONS - throw_xml_error (e); -#else - xml_error (e); -#endif - return 0; - } - - return reinterpret_cast<const char*> ( - genxGetNamespacePrefix (gns)); - } - - // - // #ifndef XSDE_EXCEPTIONS inline int context:: app_error () const diff --git a/libxsde/xsde/makefile b/libxsde/xsde/makefile index 468d19e..3a0465c 100644 --- a/libxsde/xsde/makefile +++ b/libxsde/xsde/makefile @@ -10,6 +10,10 @@ c_tun += c/genx/genx.c c/genx/char-props.c cxx_tun := cxx/string.cxx cxx/ro-string.cxx cxx/stack.cxx +ifeq ($(xsde_encoding),iso8859-1) +cxx_tun += cxx/iso8859-1.cxx +endif + ifeq ($(xsde_stl),n) cxx_tun += cxx/strdupx.cxx endif @@ -517,6 +521,16 @@ ifeq ($(xsde_byteorder),l) else @echo '#define XSDE_BYTEORDER 4321' >>$@ endif +ifeq ($(xsde_encoding),utf8) + @echo '#define XSDE_ENCODING_UTF8' >>$@ +else + @echo '#undef XSDE_ENCODING_UTF8' >>$@ +endif +ifeq ($(xsde_encoding),iso8859-1) + @echo '#define XSDE_ENCODING_ISO8859_1' >>$@ +else + @echo '#undef XSDE_ENCODING_ISO8859_1' >>$@ +endif ifeq ($(xsde_stl),y) @echo '#define XSDE_STL' >>$@ else |