C++ Library Extensions 2022.12.09
To help learn modern C++ programming
tpf::conversion Namespace Reference

String conversions are implemented. More...

Functions

void load_default_locale (bool ShowLocaleName=false)
 Load system default locale for string conversion. More...
 
std::string wstring_to_string (const std::wstring &wstr, unsigned int codepage=CP_UTF8)
 Converts from std::wstring to std::string with codepage. More...
 
std::wstring string_to_wstring (const std::string &str, unsigned int codepage=CP_UTF8)
 Converts std::string to std::wstring using codepage. More...
 
std::string utf16_to_utf8 (const std::wstring &utf16str)
 Converts UTF16 std::wstring to UTF8 std::string. More...
 
std::wstring utf8_to_utf16 (const std::string &utf8str)
 Converts UTF8 std::string to UTF16 std::wstring. More...
 
std::string utf16_to_utf8 (const wchar_t *utf16str)
 Converts UTF16 (const wchar_t*) to UTF8 (std::string) More...
 
std::wstring utf8_to_utf16 (const char *utf8str)
 Converts UTF8 string (const char*) to UTF16 (std::wstring) More...
 
char utf16_to_utf8 (const wchar_t utf16_char)
 Converts UTF16 wchar_t to UFT8 char. More...
 
wchar_t utf8_to_utf16 (const char utf8_char)
 Converts UTF8 char to UTF16 char. More...
 
std::wstring windows_codepage_to_utf16 (const std::string &codepage_string)
 Converts Windows codepage std::string to utf16 std::wstring. More...
 
std::string utf16_to_windows_codepage (const std::wstring &utf16_string)
 Converts UTF16 std::wstring to Windows codepage std::string. More...
 
std::wstring windows_codepage_to_utf16 (const char *codepage_string)
 Converts Windows codepage const char* to UTF16 std::wstring. More...
 
std::string utf16_to_windows_codepage (const wchar_t *utf16_string)
 Converts UTF16 const wchar_t* to Windows codepage std::string. More...
 
std::string windows_codepage_to_utf8 (const std::string &codepage_string)
 Converts Windows codepage std::string to UTF8 std::string. More...
 
std::string windows_codepage_to_utf8 (const char *codepage_string)
 Converts Windows codepage const char* to UTF8 std::string. More...
 
std::string utf8_to_windows_codepage (const std::string &utf8_string)
 Converts UTF8 std::string to Windows codepage string. More...
 
std::string utf8_to_windows_codepage (const char *utf8_string)
 Converts UTF8 const char* to Windows codepage std::string. More...
 
template<typename TargetCharType , typename SourceCharType >
decltype(auto) source_to_target (const std::basic_string< SourceCharType > &str)
 Converts from source to target. More...
 
std::string smart_encode (const char *arg)
 
std::string smart_encode (const wchar_t *arg)
 

Detailed Description

String conversions are implemented.

Function Documentation

◆ load_default_locale()

void tpf::conversion::load_default_locale ( bool  ShowLocaleName = false)
inline

Load system default locale for string conversion.

See also
002-conversion.cpp

Definition at line 59 of file tpf_conversion.hpp.

Here is the caller graph for this function:

◆ smart_encode() [1/2]

std::string tpf::conversion::smart_encode ( const char *  arg)
inline

Definition at line 444 of file tpf_conversion.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ smart_encode() [2/2]

std::string tpf::conversion::smart_encode ( const wchar_t *  arg)
inline

Definition at line 453 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ source_to_target()

template<typename TargetCharType , typename SourceCharType >
decltype(auto) tpf::conversion::source_to_target ( const std::basic_string< SourceCharType > &  str)

Converts from source to target.

Template Parameters
TargetCharType
SourceCharType
Parameters
str
Returns
decltype(auto)

Definition at line 428 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ string_to_wstring()

std::wstring tpf::conversion::string_to_wstring ( const std::string &  str,
unsigned int  codepage = CP_UTF8 
)
inline

Converts std::string to std::wstring using codepage.

If fails, returns empty string, std::wstring(L"")

Parameters
strfor string to convert
codepagefor Code Page (default CP_UTF8)
Returns
std::wstring for the converted UTF16 string
See also
002-conversion.cpp

Definition at line 146 of file tpf_conversion.hpp.

Here is the caller graph for this function:

◆ utf16_to_utf8() [1/3]

std::string tpf::conversion::utf16_to_utf8 ( const std::wstring &  utf16str)
inline

Converts UTF16 std::wstring to UTF8 std::string.

If fails, returns empty string, std::string("")

Parameters
utf16strfor UTF16 std::wstring to convert
Returns
std::string for the converted UTF8 string
See also
002-conversion.cpp

Definition at line 181 of file tpf_conversion.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16_to_utf8() [2/3]

std::string tpf::conversion::utf16_to_utf8 ( const wchar_t *  utf16str)
inline

Converts UTF16 (const wchar_t*) to UTF8 (std::string)

This function converts zero terminated UTF16 or const wchar_t* to UTF8 std::string. If conversion fails, returns empty string "".

Parameters
utf16strfor UTF16 string to convert to UTF8
Returns
std::string for UTF8 string, if fails returns empty string ""
See also
002-conversion.cpp

Definition at line 216 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ utf16_to_utf8() [3/3]

char tpf::conversion::utf16_to_utf8 ( const wchar_t  utf16_char)
inline

Converts UTF16 wchar_t to UFT8 char.

If fails, returns '\0'

Parameters
utf16_charfor UTF16 wchar_t to convert
Returns
char for the converted UTF8 char
See also
002-conversion.cpp

Definition at line 259 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ utf16_to_windows_codepage() [1/2]

std::string tpf::conversion::utf16_to_windows_codepage ( const std::wstring &  utf16_string)
inline

Converts UTF16 std::wstring to Windows codepage std::string.

If fails, returns empty string, std::string("")

Parameters
utf16_stringfor UTF16 std::wstring to convert
Returns
std::string for the converted Windows codepage string
See also
002-conversion.cpp

Definition at line 309 of file tpf_conversion.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16_to_windows_codepage() [2/2]

std::string tpf::conversion::utf16_to_windows_codepage ( const wchar_t *  utf16_string)
inline

Converts UTF16 const wchar_t* to Windows codepage std::string.

If fails, returns empty string, std::string("")

Parameters
utf16_stringfor UTF16 const wchar_t* to convert
Returns
std::string for the converted Windows codepage string
See also
002-conversion.cpp

Definition at line 340 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ utf8_to_utf16() [1/3]

std::wstring tpf::conversion::utf8_to_utf16 ( const char *  utf8str)
inline

Converts UTF8 string (const char*) to UTF16 (std::wstring)

If fails, returns empty string or L"".

Parameters
utf8strfor UTF8 (const char*) to convert
Returns
std::wstring for the converted UTF16 (std::wstring)
See also
002-conversion.cpp

Definition at line 237 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ utf8_to_utf16() [2/3]

wchar_t tpf::conversion::utf8_to_utf16 ( const char  utf8_char)
inline

Converts UTF8 char to UTF16 char.

If fails, returns L'\0'

Parameters
utf8_charfor UTF8 char to convert
Returns
wchar_t for the converted UTF16 character
See also
002-conversion.cpp

Definition at line 276 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ utf8_to_utf16() [3/3]

std::wstring tpf::conversion::utf8_to_utf16 ( const std::string &  utf8str)
inline

Converts UTF8 std::string to UTF16 std::wstring.

If fails, returns empty string, std::wstring(L"")

Parameters
utf8strfor UTF8 std::string to convert
Returns
std::wstring for the converted UTF16 string
See also
002-conversion.cpp

Definition at line 197 of file tpf_conversion.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf8_to_windows_codepage() [1/2]

std::string tpf::conversion::utf8_to_windows_codepage ( const char *  utf8_string)
inline

Converts UTF8 const char* to Windows codepage std::string.

If fails, returns empty string, std::string("")

Parameters
utf8_stringfor UTF8 const char* to convert
Returns
std::string for the converted Windows codepage string
See also
002-conversion.cpp

Definition at line 410 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ utf8_to_windows_codepage() [2/2]

std::string tpf::conversion::utf8_to_windows_codepage ( const std::string &  utf8_string)
inline

Converts UTF8 std::string to Windows codepage string.

If fails, returns empty string, std::string("")

Parameters
utf8_stringfor UTF8 std::string to convert
Returns
std::string for the converted Windows codepage string
See also
002-conversion.cpp

Definition at line 393 of file tpf_conversion.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ windows_codepage_to_utf16() [1/2]

std::wstring tpf::conversion::windows_codepage_to_utf16 ( const char *  codepage_string)
inline

Converts Windows codepage const char* to UTF16 std::wstring.

If fails, returns empty string, std::wstring(L"")

Parameters
codepage_stringfor Windows codepage const char* to convert
Returns
std::wstring for the converted UTF16 string
See also
002-conversion.cpp

Definition at line 323 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ windows_codepage_to_utf16() [2/2]

std::wstring tpf::conversion::windows_codepage_to_utf16 ( const std::string &  codepage_string)
inline

Converts Windows codepage std::string to utf16 std::wstring.

If fails, returns empty string, std::wstring(L"")

Parameters
codepage_stringfor Windows codepage std::string to convert
Returns
std::wstring for the converted UTF16 std::wstring
See also
002-conversion.cpp

Definition at line 295 of file tpf_conversion.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ windows_codepage_to_utf8() [1/2]

std::string tpf::conversion::windows_codepage_to_utf8 ( const char *  codepage_string)
inline

Converts Windows codepage const char* to UTF8 std::string.

If fails, return empty string, std::string("")

Parameters
codepage_stringfor Windows codepage const char* to convert
Returns
std::string for the converted UTF8 string
See also
002-conversion.cpp

Definition at line 375 of file tpf_conversion.hpp.

Here is the call graph for this function:

◆ windows_codepage_to_utf8() [2/2]

std::string tpf::conversion::windows_codepage_to_utf8 ( const std::string &  codepage_string)
inline

Converts Windows codepage std::string to UTF8 std::string.

If fails, returns empty string, std::string("")

Parameters
codepage_stringfor Windows codepage std::string to convert
Returns
std::string for the converted UTF8 string
See also
002-conversion.cpp

Definition at line 358 of file tpf_conversion.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wstring_to_string()

std::string tpf::conversion::wstring_to_string ( const std::wstring &  wstr,
unsigned int  codepage = CP_UTF8 
)
inline

Converts from std::wstring to std::string with codepage.

If fails, returns empty string, std::string("")

Parameters
wstrfor std::wstring to convert
codepagefor Code Page, default = CP_UTF8
Returns
std::string for the converted string
See also
002-conversion.cpp

Definition at line 100 of file tpf_conversion.hpp.

Here is the caller graph for this function: