| 1 | // file : xsd/cxx/xml/string.hxx |
|---|
| 2 | // author : Boris Kolpackov <boris@codesynthesis.com> |
|---|
| 3 | // copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC |
|---|
| 4 | // license : GNU GPL v2 + exceptions; see accompanying LICENSE file |
|---|
| 5 | |
|---|
| 6 | #ifndef XSD_CXX_XML_STRING_HXX |
|---|
| 7 | #define XSD_CXX_XML_STRING_HXX |
|---|
| 8 | |
|---|
| 9 | #include <string> |
|---|
| 10 | |
|---|
| 11 | #include <xsd/cxx/auto-array.hxx> |
|---|
| 12 | #include <xercesc/util/XercesDefs.hpp> // XMLCh |
|---|
| 13 | |
|---|
| 14 | namespace xsd |
|---|
| 15 | { |
|---|
| 16 | namespace cxx |
|---|
| 17 | { |
|---|
| 18 | namespace xml |
|---|
| 19 | { |
|---|
| 20 | // |
|---|
| 21 | // |
|---|
| 22 | struct invalid_utf8_string {}; |
|---|
| 23 | struct invalid_utf16_string {}; |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | // Transcode a null-terminated string. |
|---|
| 27 | // |
|---|
| 28 | template <typename C> |
|---|
| 29 | std::basic_string<C> |
|---|
| 30 | transcode (const XMLCh* s); |
|---|
| 31 | |
|---|
| 32 | // Transcode a potentially non-null-terminated string. |
|---|
| 33 | // |
|---|
| 34 | template <typename C> |
|---|
| 35 | std::basic_string<C> |
|---|
| 36 | transcode (const XMLCh* s, std::size_t length); |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | // For VC7.1 wchar_t and XMLCh are the same type so we cannot |
|---|
| 40 | // overload the transcode name. You should not use these functions |
|---|
| 41 | // anyway and instead use the xml::string class below. |
|---|
| 42 | // |
|---|
| 43 | template <typename C> |
|---|
| 44 | XMLCh* |
|---|
| 45 | transcode_to_xmlch (const C*); |
|---|
| 46 | |
|---|
| 47 | template <typename C> |
|---|
| 48 | XMLCh* |
|---|
| 49 | transcode_to_xmlch (const std::basic_string<C>& s); |
|---|
| 50 | |
|---|
| 51 | // |
|---|
| 52 | // |
|---|
| 53 | class string |
|---|
| 54 | { |
|---|
| 55 | public : |
|---|
| 56 | template <typename C> |
|---|
| 57 | string (const std::basic_string<C>& s) |
|---|
| 58 | : s_ (transcode_to_xmlch<C> (s)) |
|---|
| 59 | { |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | template <typename C> |
|---|
| 63 | string (const C* s) |
|---|
| 64 | : s_ (transcode_to_xmlch<C> (s)) |
|---|
| 65 | { |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | const XMLCh* |
|---|
| 69 | c_str () const |
|---|
| 70 | { |
|---|
| 71 | return s_.get (); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | private: |
|---|
| 75 | string (const string&); |
|---|
| 76 | |
|---|
| 77 | string& |
|---|
| 78 | operator= (const string&); |
|---|
| 79 | |
|---|
| 80 | private: |
|---|
| 81 | auto_array<XMLCh> s_; |
|---|
| 82 | }; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | #endif // XSD_CXX_XML_STRING_HXX |
|---|
| 88 | |
|---|
| 89 | #include <xsd/cxx/xml/string.ixx> |
|---|
| 90 | #include <xsd/cxx/xml/string.txx> |
|---|