E-MailRelay

Classes | Public Types | Static Public Member Functions | List of all members
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
using | tstring = std::basic_string< TCHAR >

## 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: utf16 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 ISO-8859-15 eight-bit char, UTF-16 wchar, and UTF-8 multi-byte char.

On Windows the eight-bit char encoding uses the 'active code page', typically CP-1252, rather than ISO-8859-15. Note that the active code page is also used by the Win32 API "A()" functions when they have to convert from 'ansi' to UTF-16 (UCS-2) wide characters (see GetACP()).

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 ;
}
G::Convert::convert
static void convert(utf8 &utf_out, const std::string &in_)
Converts between string types/encodings: ansi to utf8.
Definition: gconvert.cpp:44
G::Convert::ThrowOnError
Holds context information which convert() adds to the exception when it fails.
Definition: gconvert.h:75
G::Convert::utf8
A string wrapper that indicates UTF-8 encoding.
Definition: gconvert.h:68

Definition at line 61 of file gconvert.h.

## Member Typedef Documentation

## ◆ tstring

using G::Convert::tstring = std::basic_string<TCHAR>

Definition at line 65 of file gconvert.h.

## Member Function Documentation

## ◆ convert() [1/10]

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.

## ◆ convert() [2/10]

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

An overload for TCHAR shenanigans on windows.

Note that a TCHAR can sometimes be a char, depending on the build options, so this three-parameter overload allows for the input to be a basic_string<TCHAR>, whatever the build.

Converts between string types/encodings: ansi to ansi.

Definition at line 34 of file gconvert.cpp.

## ◆ convert() [3/10]

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.

## ◆ convert() [4/10]

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.

## ◆ convert() [5/10]

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.

## ◆ convert() [6/10]

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

Converts between string types/encodings: utf16 to utf16.

Definition at line 39 of file gconvert.cpp.

## ◆ convert() [7/10]

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.

## ◆ convert() [8/10]

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.

## ◆ convert() [9/10]

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.

## ◆ convert() [10/10]

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.

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

- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/glib/gconvert.h
- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/glib/gconvert.cpp