- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gconvert.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program 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 // This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20
21 #ifndef G_CONVERT_H
22 #define G_CONVERT_H
23
24 #include "gdef.h"
25 #include "gexception.h"
26 #include <string>
27
29 namespace G
30 {
31 class Convert ;
32 }
33
37 class G::Convert
38 {
39 public:
40 G_EXCEPTION_CLASS( Error , "string conversion error" ) ;
41 typedef std::basic_string<TCHAR> tstring ;
42
44 struct utf8
45 {
46 utf8() {}
47 explicit utf8( const std::string & s_ ) : s(s_) {}
48 std::string s ;
49 } ;
50
52 struct ThrowOnError
53 {
54 ThrowOnError() {}
55 explicit ThrowOnError( const std::string & context_ ) : context(context_) {}
56 std::string context ;
57 } ;
58
59 static void convert( utf8 & utf_out , const std::string & in_ ) ;
61
62 static void convert( utf8 & utf_out , const utf8 & in_ ) ;
64
65 static void convert( utf8 & utf_out , const std::wstring & in_ ) ;
67
68 static void convert( std::string & ansi_out , const std::string & in_ ) ;
70
71 static void convert( std::string & ansi_out , const std::string & in_ ,
72 const ThrowOnError & just_for_tchar_overloading ) ;
74
75 static void convert( std::string & ansi_out , const utf8 & in_ , const ThrowOnError & ) ;
77
78 static void convert( std::string & ansi_out , const std::wstring & in_ , const ThrowOnError & ) ;
80
81 static void convert( std::wstring & out_ , const std::string & in_ ) ;
83
84 static void convert( std::wstring & out_ , const utf8 & in_ ) ;
86
87 static void convert( std::wstring & out_ , const std::wstring & in_ ) ;
89
90 private:
91 static std::string narrow( const std::wstring & s , bool is_utf8 , const std::string & = std::string() ) ;
92 static std::wstring widen( const std::string & s , bool is_utf8 , const std::string & = std::string() ) ;
93 Convert() ; // not implemented
94 } ;
95
96 #endif
G::Convert::convert
static void convert(utf8 &utf_out, const std::string &in_)
Converts between string types/encodings.
Definition: gconvert.cpp:44
G::Convert
A static class which provides string encoding conversion functions.
Definition: gconvert.h:37
G::Convert::utf8::utf8
utf8(const std::string &s_)
Definition: gconvert.h:47
G::Convert::tstring
std::basic_string< TCHAR > tstring
Definition: gconvert.h:40
G::Convert::ThrowOnError
Holds error context information for when convert() may fail.
Definition: gconvert.h:52
G::Convert::ThrowOnError::ThrowOnError
ThrowOnError()
Definition: gconvert.h:54
G::Convert::ThrowOnError::context
std::string context
Definition: gconvert.h:56
G
Low-level classes.
G::Convert::utf8
A string wrapper that indicates UTF-8 encoding.
Definition: gconvert.h:44
gexception.h
G::Convert::utf8::s
std::string s
Definition: gconvert.h:48
G::Convert::ThrowOnError::ThrowOnError
ThrowOnError(const std::string &context_)
Definition: gconvert.h:55
G::Convert::utf8::utf8
utf8()
Definition: gconvert.h:46
G_EXCEPTION_CLASS
#define G_EXCEPTION_CLASS(class_name, description)
Definition: gexception.h:87