]> git.donarmstrong.com Git - flightcrew.git/blob - src/XercesExtensions/ToXercesStringConverter.cpp
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / XercesExtensions / ToXercesStringConverter.cpp
1 /************************************************************************
2 **
3 **  Copyright (C) 2010  Strahinja Markovic
4 **
5 **  This file is part of FlightCrew.
6 **
7 **  FlightCrew is free software: you can redistribute it and/or modify
8 **  it under the terms of the GNU Lesser General Public License as published
9 **  by the Free Software Foundation, either version 3 of the License, or
10 **  (at your option) any later version.
11 **
12 **  FlightCrew is distributed in the hope that it will be useful,
13 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 **  GNU Lesser General Public License for more details.
16 **
17 **  You should have received a copy of the GNU Lesser General Public License
18 **  along with FlightCrew.  If not, see <http://www.gnu.org/licenses/>.
19 **
20 *************************************************************************/
21
22 #include <xercesc/util/TransService.hpp>
23 #include "ToXercesStringConverter.h"
24
25 namespace XercesExt
26 {
27
28 ToXercesStringConverter::ToXercesStringConverter( const std::string &utf8_string )
29 {
30     if ( utf8_string.length() > 0 )
31     {
32         xc::TranscodeFromStr transcoder( 
33             (const XMLByte*) utf8_string.c_str(), utf8_string.length(), "UTF-8" );
34
35         m_XercesString = transcoder.adopt();
36     }
37
38     else
39     {
40         m_XercesString = NULL;
41     }
42 }
43
44
45 ToXercesStringConverter::ToXercesStringConverter( const char* const utf8_string )
46 {
47     if ( utf8_string )
48     {
49         size_t string_length = strlen( utf8_string );
50
51         if ( string_length > 0 )
52         {
53             xc::TranscodeFromStr transcoder( 
54                 (const XMLByte*) utf8_string, string_length, "UTF-8" );
55
56             m_XercesString = transcoder.adopt();
57         }
58
59         else
60         {
61             m_XercesString = NULL;
62         }
63     }
64
65     else
66     {
67         m_XercesString = NULL;
68     }
69 }
70
71
72 ToXercesStringConverter::~ToXercesStringConverter()
73 {
74     if ( m_XercesString )
75     
76         xc::XMLString::release( &m_XercesString );
77 }
78
79
80 const XMLCh* ToXercesStringConverter::XercesString() const
81 {
82     return m_XercesString;
83 }
84
85 } // namespace XercesExt
86