nlib
nn::nlib::unicode::ToUtf8Obj Class Referencefinal

Class to use to pass a UTF-8, UTF-16, or UTF-32 string as UTF-8. More...

#include "nn/nlib/unicode/Convert.h"

Public Member Functions

 ToUtf8Obj (const wchar_t *wstr) noexcept
 Converts a wide character string to a UTF-8 string. More...
 
 ToUtf8Obj (const nlib_utf16_t *utf16str) noexcept
 Converts a UTF-16 string to a UTF-8 string. More...
 
 ToUtf8Obj (const nlib_utf32_t *utf32str) noexcept
 Converts a UTF-32 string to a UTF-8 string. More...
 
 ToUtf8Obj (const nlib_utf8_t *str) noexcept
 Sets the UTF-8 string. More...
 
 operator const nlib_utf8_t * () noexcept
 Implicitly returns a C string.
 
const char * c_str () noexcept
 Explicitly returns a C string. More...
 
 operator bool () const
 Returns true if the object is enabled.
 

Detailed Description

Class to use to pass a UTF-8, UTF-16, or UTF-32 string as UTF-8.

Description
Because operator const nlib_utf8_t* is defined, you can pass to function arguments as a multibyte character string. If the conversion fails and the object is invalid, an empty string is passed instead of a null pointer. This class exists as a utility for running codes handling UTF-8 string literals in Visual Studio. The class is used by defining a macro as follows:
#ifdef _MSC_VER
#define X(str) L##str
#else
#define X(str)
#endif
......
UseTextAsUtf8(X("my utf8 text"));

Definition at line 25 of file Convert.h.

Constructor & Destructor Documentation

◆ ToUtf8Obj() [1/4]

nn::nlib::unicode::ToUtf8Obj::ToUtf8Obj ( const wchar_t *  wstr)
explicitnoexcept

Converts a wide character string to a UTF-8 string.

Parameters
[in]wstrWide character string to pass as a UTF-8 string.
Description
Stores the UTF-8 converted string internally in dynamically allocated memory. The object becomes invalid if the conversion fails.

◆ ToUtf8Obj() [2/4]

nn::nlib::unicode::ToUtf8Obj::ToUtf8Obj ( const nlib_utf16_t utf16str)
explicitnoexcept

Converts a UTF-16 string to a UTF-8 string.

Parameters
[in]utf16strUTF-16 string to pass as a UTF-8 string.

◆ ToUtf8Obj() [3/4]

nn::nlib::unicode::ToUtf8Obj::ToUtf8Obj ( const nlib_utf32_t utf32str)
explicitnoexcept

Converts a UTF-32 string to a UTF-8 string.

Parameters
[in]utf32strUTF-32 string to pass as a UTF-8 string.

◆ ToUtf8Obj() [4/4]

nn::nlib::unicode::ToUtf8Obj::ToUtf8Obj ( const nlib_utf8_t str)
inlineexplicitnoexcept

Sets the UTF-8 string.

Parameters
[in]strUTF-8 string.
Description
Stores the passed pointer in the object. Does not dynamically allocate memory or copy the string.

Definition at line 30 of file Convert.h.

Member Function Documentation

◆ c_str()

nn::nlib::unicode::ToUtf8Obj::c_str ( )
inlinenoexcept

Explicitly returns a C string.

Returns
C string converted to UTF-8.

Definition at line 37 of file Convert.h.


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