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/cxx/iso8859-1.ixx | |
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/cxx/iso8859-1.ixx')
-rw-r--r-- | libxsde/xsde/cxx/iso8859-1.ixx | 128 |
1 files changed, 128 insertions, 0 deletions
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; + } + } +} |