Goby v2
xerces_strings.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 // this xml code based largely on work in C++ Cookbook by D. Ryan Stephens, Christopher Diggins, Jonathan Turkanis, and Jeff Cogswell. Copyright 2006 O'Reilly Media, INc., 0-596-00761-2.
24 
25 // these functions define an easy way to convert from and to the XercesString
26 // unicode format to the native (ASCII in our case) string format.
27 
28 #ifndef XERCES_STRINGS20091211H
29 #define XERCES_STRINGS20091211H
30 
31 #include <string>
32 
33 #include <boost/scoped_ptr.hpp>
34 #include <xercesc/util/XMLString.hpp>
35 
36 // typedef std::basic_string<XMLCh> XercesString;
37 
38 /* // Converts from a narrow-character string to a wide-character string. */
39 inline const XMLCh* fromNative(const char* str) { return xercesc::XMLString::transcode(str); }
40 
41 /* // Converts from a narrow-character string to a wide-charactr string. */
42 /* inline XercesString fromNative(const std::string& str) */
43 /* { */
44 /* return fromNative(str.c_str()); */
45 /* } */
46 
47 // Converts from a wide-character string to a narrow-character string.
48 inline std::string toNative(const XMLCh* str)
49 {
50  boost::scoped_ptr<char> ptr(xercesc::XMLString::transcode(str));
51  return std::string(ptr.get());
52 }
53 
54 /* // Converts from a wide-character string to a narrow-character string. */
55 /* inline std::string toNative(const XercesString& str) */
56 /* { */
57 /* return toNative(str.c_str()); */
58 /* } */
59 
60 #endif // #ifndef XERCES_STRINGS_HPP_INCLUDED