aboutsummaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/xml/char-lcp.txx
blob: 982b24fef598f39854b4ecaf4aff13c29cb6fbfd (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
72
73
74
// file      : xsd/cxx/xml/char-lcp.txx
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#include <cstring> // std::memcpy

#include <xercesc/util/XMLString.hpp>

#include <xsd/cxx/config.hxx> // XSD_CXX11

#ifdef XSD_CXX11
#  include <memory> // std::unique_ptr
#else
#  include <xsd/cxx/auto-array.hxx>
#endif

#include <xsd/cxx/xml/std-memory-manager.hxx>

namespace xsd
{
  namespace cxx
  {
    namespace xml
    {
      template <typename C>
      std::basic_string<C> char_lcp_transcoder<C>::
      to (const XMLCh* s)
      {
        std_memory_manager mm;
#ifdef XSD_CXX11
        std::unique_ptr<C[], std_memory_manager&> r (
#else
        auto_array<C, std_memory_manager> r (
#endif
          xercesc::XMLString::transcode (s, &mm), mm);
        return std::basic_string<C> (r.get ());
      }

      template <typename C>
      std::basic_string<C> char_lcp_transcoder<C>::
      to (const XMLCh* s, std::size_t len)
      {
#ifdef XSD_CXX11
        std::unique_ptr<XMLCh[]> tmp (
#else
        auto_array<XMLCh> tmp (
#endif
          new XMLCh[len + 1]);
        std::memcpy (tmp.get (), s, len * sizeof (XMLCh));
        tmp[len] = XMLCh (0);

        std_memory_manager mm;
#ifdef XSD_CXX11
        std::unique_ptr<C[], std_memory_manager&> r (
#else
        auto_array<C, std_memory_manager> r (
#endif
          xercesc::XMLString::transcode (tmp.get (), &mm), mm);

        tmp.reset ();

        return std::basic_string<C> (r.get ());
      }

      template <typename C>
      XMLCh* char_lcp_transcoder<C>::
      from (const C* s)
      {
        std_memory_manager mm;
        return xercesc::XMLString::transcode (s, &mm);
      }
    }
  }
}