VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
G::Convert Class Reference

A static class which provides string encoding conversion functions. More...

#include <gconvert.h>

Classes

struct  ThrowOnError
 Holds context information which convert() adds to the exception when it fails. More...
 
struct  utf8
 A string wrapper that indicates UTF-8 encoding. More...
 

Public Types

typedef std::basic_string< TCHAR > tstring
 

Public Member Functions

 G_EXCEPTION_CLASS (Error,"string conversion error")
 

Static Public Member Functions

static void convert (utf8 &utf_out, const std::string &in_)
 Converts between string types/encodings: ansi to utf8. More...
 
static void convert (utf8 &utf_out, const utf8 &in_)
 Converts between string types/encodings: utf8 to utf8. More...
 
static void convert (utf8 &utf_out, const std::wstring &in_)
 Converts between string types/encodings: utf16 to utf8. More...
 
static void convert (std::string &ansi_out, const std::string &in_)
 Converts between string types/encodings: ansi to ansi. More...
 
static void convert (std::string &ansi_out, const utf8 &in_, const ThrowOnError &)
 Converts between string types/encodings: utf8 to ansi. More...
 
static void convert (std::string &ansi_out, const std::wstring &in_, const ThrowOnError &)
 Converts between string types/encodings: utf16 to ansi. More...
 
static void convert (std::wstring &wide_out, const std::string &ansi_in)
 Converts between string types/encodings: ansi to utf16. More...
 
static void convert (std::wstring &wide_out, const utf8 &utf_in)
 Converts between string types/encodings: utf8 to utf16. More...
 
static void convert (std::wstring &wide_out, const std::wstring &wide_in)
 Converts between string types/encodings: utf8 to utf16. More...
 
static void convert (std::string &ansi_out, const std::string &in_, const ThrowOnError &)
 An overload for TCHAR shenanigans on windows. More...
 

Detailed Description

A static class which provides string encoding conversion functions.

Supported encodings are "ANSI" (CP-1252/ISO-8859-1) char, UTF-16 wchar, and UTF-8 multi-byte char. Conversions that can fail take a ThrowOnError parameter which is used to add context information to the G::Convert::Error exception that is thrown.

Eg:

std::string to_utf8( const std::wstring & wide_input )
{
G::Convert::utf8 utf8_result ;
G::Convert::convert( utf8_result , wide_input ) ;
return utf8_result.s ;
}
std::string to_ansi( const std::wstring & wide_input )
{
std::string ansi_result ;
G::Convert::convert( ansi_result , wide_input , G::Convert::ThrowOnError("to_ansi") ) ;
return ansi_result ;
}

Definition at line 57 of file gconvert.h.

Member Function Documentation

void G::Convert::convert ( utf8 utf_out,
const std::string &  in_ 
)
static

Converts between string types/encodings: ansi to utf8.

Definition at line 44 of file gconvert.cpp.

void G::Convert::convert ( utf8 utf_out,
const utf8 in_ 
)
static

Converts between string types/encodings: utf8 to utf8.

Definition at line 24 of file gconvert.cpp.

void G::Convert::convert ( utf8 utf_out,
const std::wstring &  in_ 
)
static

Converts between string types/encodings: utf16 to utf8.

Definition at line 49 of file gconvert.cpp.

void G::Convert::convert ( std::string &  ansi_out,
const std::string &  in_ 
)
static

Converts between string types/encodings: ansi to ansi.

Definition at line 29 of file gconvert.cpp.

void G::Convert::convert ( std::string &  ansi_out,
const utf8 in_,
const ThrowOnError e 
)
static

Converts between string types/encodings: utf8 to ansi.

Definition at line 54 of file gconvert.cpp.

void G::Convert::convert ( std::string &  ansi_out,
const std::wstring &  in_,
const ThrowOnError e 
)
static

Converts between string types/encodings: utf16 to ansi.

Definition at line 59 of file gconvert.cpp.

void G::Convert::convert ( std::wstring &  wide_out,
const std::string &  ansi_in 
)
static

Converts between string types/encodings: ansi to utf16.

Definition at line 64 of file gconvert.cpp.

void G::Convert::convert ( std::wstring &  wide_out,
const utf8 utf_in 
)
static

Converts between string types/encodings: utf8 to utf16.

Definition at line 69 of file gconvert.cpp.

void G::Convert::convert ( std::wstring &  wide_out,
const std::wstring &  wide_in 
)
static

Converts between string types/encodings: utf8 to utf16.

Definition at line 39 of file gconvert.cpp.

void G::Convert::convert ( std::string &  ansi_out,
const std::string &  in_,
const ThrowOnError  
)
static

An overload for TCHAR shenanigans on windows.

Converts between string types/encodings: ansi to ansi.

Definition at line 34 of file gconvert.cpp.


The documentation for this class was generated from the following files: