Spinning Topp Logo BlackTopp Studios
inc
xmlstring.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 /*
41  *
42  * Software, Files, Libraries and all other items referenced in this clause refers only
43  * to the contents of this file and associated documentation.
44  *
45  * Pugixml parser - version 1.0
46  * --------------------------------------------------------
47  * Copyright © 2006-2012, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
48  * Report bugs and download new versions at http://pugixml.org/
49  *
50  * This library is distributed under the MIT License. See notice at the end
51  * of this file.
52  *
53  * This work is based on the pugxml parser, which is:
54  * Copyright © 2003, by Kristen Wegner (kristen@tima.net)
55  */
56 #ifndef _xmlutfconversion_h
57 #define _xmlutfconversion_h
58 
59 /// @file
60 /// @brief A few functions to help the XML system perform conversions between UTF8 and the native wide character UTF implementation.
61 
62 #include "datatypes.h"
63 
64 
65 
66 namespace Mezzanine
67 {
68  namespace XML
69  {
70  /// @brief Convert a c-style string of wchar_t to std::string containing UTF8.
71  /// @param str The wide string to convert
72  /// @return A std::basic_string<char, std::char_traits<char>, std::allocator<char> > containing the converted data
73  std::basic_string<char, std::char_traits<char>, std::allocator<char> > MEZZ_LIB AsUtf8(const wchar_t* str);
74 
75  /// @brief Convert a std::wstring to a UTF8 std::string
76  /// @param str The wide string to convert.
77  /// @return A std::basic_string<char, std::char_traits<char>, std::allocator<char> > containing the converted data
78  std::basic_string<char, std::char_traits<char>, std::allocator<char> > MEZZ_LIB AsUtf8(const std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >& str);
79 
80  /// @brief Convert a Convert a c-style string to std::wstring containing native encoding (Usually UCS2 on windows and UTF32 on Linux/Mac).
81  /// @param str The string to convert.
82  /// @return A std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > containing the converted data
83  std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > MEZZ_LIB AsWide(const char* str);
84 
85  /// @brief Convert a Convert a std::string to std::wstring containing native encoding (Usually UCS2 on windows and UTF32 on Linux/Mac).
86  /// @param str The string to convert.
87  /// @return A std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > containing the converted data
88  std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > MEZZ_LIB AsWide(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >& str);
89 
90  /// @brief Gets the first tag out of the Stream and returns it as a String
91  /// @param stream An std::ostream that contains atleast one xml tag
92  /// @return This gets one XML tag, its closing tage, and all subtags.
93  String MEZZ_LIB GetOneTag(std::istream& stream);
94 
95 
96  class Document;
97  /// @internal
98  /// @brief Perform a basic series of checks for extracting meaning from a single xml tag.
99  /// @param NameSpace Used when throwing exceptions, this is a string containing the namespace and colons of a class to be deserialized for example "Mezzanine::"
100  /// @param ClassName This will be used to identify the main xml element/tag you are attempting to deserialize. This will also be used in error messages.
101  /// @param OneTag One XML tag/elements worth of text to deserialize.
102  /// @return A pointer to XML::Document that you are now the owner of and must delete, that has the data parse and ready to access.
103  /// @throw This can throw a Mezzanine::exception in the event that the xml cannot be parsed.
104  Document* MEZZ_LIB PreParseClassFromSingleTag(const String& NameSpace, const String& ClassName, const String& OneTag);
105 
106  /// @internal
107  /// @brief Calls PreParseClassFromSingleTag passing a "" as the Namespace
108  /// @param ClassName This will be used to identify the main xml element/tag you are attempting to deserialize. This will also be used in error messages.
109  /// @param OneTag One XML tag/elements worth of text to deserialize.
110  /// @return A pointer to XML::Document that you are now the owner of and must delete, that has the data parse and ready to access.
111  /// @throw This can throw a Mezzanine::exception in the event that the xml cannot be parsed.
112  Document* MEZZ_LIB PreParseClassFromSingleTag(const String& ClassName, const String& OneTag);
113 
114  /// @brief Convert < > \& and " in text to \&lt;, \&gt;, \&amp; and \&quote so text can safely be stored in XML
115  /// @details Usually this is not required. Entering text into an XML::Attribute or and XML::Node will correctly escape it.
116  /// Use this when you will be creating raw xml want to safely escape these characters.
117  /// @param XMLText The Text to convert to xml safe text
118  /// @return a String containing the escaped version of XMLText
119  String MEZZ_LIB EscapeXML(const String& XMLText);
120  }
121 } // /namespace Mezzanine
122 
123 
124 
125 #endif // Include guard
126 
127 
128 /*
129  *
130  * Software, Files, Libraries and all other items referenced in this clause refers only
131  * to the contents of this file and associated documentation.
132  *
133  * Copyright © 2006-2012 Arseny Kapoulkine
134  *
135  * Permission is hereby granted, free of charge, to any person
136  * obtaining a copy of this software and associated documentation
137  * files (the "Software"), to deal in the Software without
138  * restriction, including without limitation the rights to use,
139  * copy, modify, merge, publish, distribute, sublicense, and/or sell
140  * copies of the Software, and to permit persons to whom the
141  * Software is furnished to do so, subject to the following
142  * conditions:
143  *
144  * The above copyright notice and this permission notice shall be
145  * included in all copies or substantial portions of the Software.
146  *
147  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
148  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
149  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
150  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
151  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
152  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
153  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
154  * OTHER DEALINGS IN THE SOFTWARE.
155  */
String GetOneTag(std::istream &stream)
Gets the first tag out of the Stream and returns it as a String.
Definition: xmlstring.cpp:72
Document * PreParseClassFromSingleTag(const String &NameSpace, const String &ClassName, const String &OneTag)
Perform a basic series of checks for extracting meaning from a single xml tag.
Definition: xmlstring.cpp:116
std::basic_string< wchar_t, std::char_traits< wchar_t >, std::allocator< wchar_t > > MEZZ_LIB AsWide(const char *str)
Convert a Convert a c-style string to std::wstring containing native encoding (Usually UCS2 on window...
All the definitions for datatypes as well as some basic conversion functions are defined here...
std::basic_string< char, std::char_traits< char >, std::allocator< char > > MEZZ_LIB AsUtf8(const wchar_t *str)
Convert a c-style string of wchar_t to std::string containing UTF8.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
String EscapeXML(const String &XMLText)
Convert < > & and " in text to <, >, & and "e so text can safely be stored in XML.
Definition: xmlstring.cpp:144
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159