aboutsummaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/xml/char-iso8859-1.hxx
blob: 800f5021ef4803184341160c561ca9f4fcaef032 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// file      : xsd/cxx/xml/char-iso8859-1.hxx
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef XSD_CXX_XML_TRANSCODER
#define XSD_CXX_XML_TRANSCODER
#define XSD_CXX_XML_TRANSCODER_CHAR_ISO8859_1

#include <string>
#include <cstddef> // std::size_t

#include <xercesc/util/XercesDefs.hpp> // XMLCh

#include <xsd/cxx/xml/exceptions.hxx>  // invalid_utf16_string

namespace xsd
{
  namespace cxx
  {
    namespace xml
    {
      struct iso8859_1_unrepresentable {};

      // UTF-16 to/from ISO-8859-1 transcoder.
      //
      template <typename C>
      struct char_iso8859_1_transcoder
      {
        static std::basic_string<C>
        to (const XMLCh* s, std::size_t length);

        static XMLCh*
        from (const C* s, std::size_t length);

        // Get/set a replacement for unrepresentable characters. If set to
        // 0 (the default value), throw iso8859_1_unrepresentable instead.
        //
        static C
        unrep_char ()
        {
          return unrep_char_;
        }

        static void
        unrep_char (C c)
        {
          unrep_char_ = c;
        }

      private:
        static C unrep_char_;
      };

      typedef char_iso8859_1_transcoder<char> char_transcoder;
    }
  }
}

#include <xsd/cxx/xml/char-iso8859-1.txx>

#else
#  ifndef XSD_CXX_XML_TRANSCODER_CHAR_ISO8859_1
     //
     // If you get this error, it usually means that either you compiled
     // your schemas with different --char-encoding values or you included
     // some of the libxsd headers (e.g., xsd/cxx/xml/string.hxx) directly
     // without first including the correct xsd/cxx/xml/char-*.hxx header.
     //
#    error conflicting character encoding detected
#  endif
#endif // XSD_CXX_XML_TRANSCODER