Converts String to a different encoding (UTF8, UTF16). More...
#include <StringConverter.h>
Public Types | |
enum | NullTermination { AddZeroTerminator , DoNotAddZeroTerminator } |
Specifies if to add a null terminator. More... | |
enum | Flags { Clear , DoNotClear } |
Clearing flags used when initializing destination buffer. More... | |
Public Member Functions | |
StringConverter (String &text, Flags flags=DoNotClear) | |
Create a StringBuilder that will push to given String. More... | |
StringConverter (Vector< char > &text, StringEncoding encoding) | |
Create a StringBuilder that will push to given Vector, with specific encoding. More... | |
bool | convertNullTerminateFastPath (StringView input, StringView &encodedText) |
Converts a given input StringView to null-terminated version. More... | |
bool | appendNullTerminated (StringView input, bool popExistingNullTerminator=true) |
Appends the given StringView and adds null-terminator. More... | |
Static Public Member Functions | |
static bool | convertEncodingToUTF8 (StringView text, Vector< char > &buffer, StringView *encodedText=nullptr, NullTermination nullTerminate=AddZeroTerminator) |
Converts text to (eventually null terminated) UTF8 encoding. More... | |
static bool | convertEncodingToUTF16 (StringView text, Vector< char > &buffer, StringView *encodedText=nullptr, NullTermination nullTerminate=AddZeroTerminator) |
Converts text to (eventually null terminated) UTF16 encoding. More... | |
static bool | convertEncodingTo (StringEncoding encoding, StringView text, Vector< char > &buffer, StringView *encodedText=nullptr, NullTermination nullTerminate=AddZeroTerminator) |
Converts text to (eventually null terminated) requested encoding. More... | |
Friends | |
struct | FileSystemIterator |
template<int N> | |
struct | SmallString |
struct | StringBuilder |
struct | FileDescriptor |
Converts String to a different encoding (UTF8, UTF16).
SC::StringConverter converts strings between different UTF encodings and can add null-terminator if requested. When the SC::StringView is already null-terminated, the class just forwards the original SC::StringView.
Example:
SC::StringConverter::StringConverter | ( | String & | text, |
Flags | flags = DoNotClear |
||
) |
Create a StringBuilder that will push to given String.
text | Destination buffer where code points will be pushed |
flags | Specifies if destination buffer must be emptied or not before pushing |
SC::StringConverter::StringConverter | ( | Vector< char > & | text, |
StringEncoding | encoding | ||
) |
Create a StringBuilder that will push to given Vector, with specific encoding.
text | Destination buffer where code points will be pushed |
encoding | The encoding to be used |
bool SC::StringConverter::appendNullTerminated | ( | StringView | input, |
bool | popExistingNullTerminator = true |
||
) |
Appends the given StringView and adds null-terminator.
If existing null-terminator was already last inserted code point, it will be removed before appending input.
input | The StringView to be appended |
popExistingNullTerminator | If true, removes existing null terminator before adding the new one |
true
if the StringView has been successfully appended
|
static |
Converts text to (eventually null terminated) requested encoding.
Uses the passed in buffer if necessary.
encoding | The requested destination encoding to convert to |
text | The StringView to be converted |
buffer | The destination buffer that will be eventually used |
encodedText | If specified, a StringView containing the encoded text will be returned |
nullTerminate | Specifies if the StringView will need to be null terminated or not |
true
if the conversion succeeds
|
static |
Converts text to (eventually null terminated) UTF16 encoding.
Uses the passed in buffer if necessary.
text | The StringView to be converted |
buffer | The destination buffer that will be eventually used |
encodedText | If specified, a StringView containing the encoded text will be returned |
nullTerminate | Specifies if the StringView will need to be null terminated or not |
true
if the conversion succeeds
|
static |
Converts text to (eventually null terminated) UTF8 encoding.
Uses the passed in buffer if necessary.
text | The StringView to be converted |
buffer | The destination buffer that will be eventually used |
encodedText | If specified, a StringView containing the encoded text will be returned |
nullTerminate | Specifies if the StringView will need to be null terminated or not |
true
if the conversion succeeds bool SC::StringConverter::convertNullTerminateFastPath | ( | StringView | input, |
StringView & | encodedText | ||
) |
Converts a given input StringView to null-terminated version.
Uses supplied buffer in constructor if an actual conversion is needed.
input | The StringView to be converted |
encodedText | The converted output StringView |
true
if the conversion succeeded