Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
Burger::String16 Class Reference

UTF 16 bit string class. More...

Public Member Functions

 String16 (void) noexcept
 Creates an empty string.
 
 String16 (const String16 &rInput)
 Initialize a Burger::String16 with a Burger::String16.
 
 String16 (const String16 &rInput, uintptr_t uStart, uintptr_t uEnd=UINTPTR_MAX)
 Initialize a Burger::String16 by using a subsection of a different Burger::String16.
 
 String16 (const char *pInput) noexcept
 Initialize with a UTF8 "C" string.
 
 String16 (const char *pInput, uintptr_t uPadding)
 Initialize with a UTF8 "C" string with padding.
 
 String16 (const uint16_t *pInput)
 Initialize with a UTF16 string.
 
 String16 (const uint32_t *pInput)
 
 ~String16 ()
 Release memory, if any.
 
 operator uint16_t * () noexcept
 Return the pointer to the string.
 
 operator const uint16_t * () const noexcept
 Return the const pointer to the string.
 
const uint16_tc_str () const noexcept
 Return the const pointer to the string.
 
uint16_tc_str () noexcept
 Return the pointer to the string.
 
const uint16_tdata (void) const noexcept
 
uint16_tdata (void) noexcept
 
 operator uint16_t () const noexcept
 Return the first character of the UTF16 "C" string.
 
uintptr_t length (void) const noexcept
 Return the length of the "C" string.
 
uint_t empty (void) const noexcept
 
uintptr_t GetLength (void) const noexcept
 Return the length of the UTF16 "C" string.
 
uint16_tGetPtr () noexcept
 Return the pointer to the string.
 
const uint16_tGetPtr () const noexcept
 Return the const pointer to the string.
 
eError Set (const char *pInput) noexcept
 Copy an 8 bit "C" string to a Burger::String16.
 
eError Set (const uint16_t *pInput) noexcept
 Copy a "C" string to a Burger::String.
 
eError SetBufferSize (uintptr_t uSize) noexcept
 Force a buffer size.
 
eError resize (uintptr_t uSize) noexcept
 
String16operator= (const String16 &rInput)
 Assign a Burger::String16.
 
String16operator= (const uint16_t *pInput)
 Assign a "C" string to a Burger::String16.
 
String16operator= (const char *pInput)
 Assign a "C" string to a Burger::String16.
 
String16operator= (char cInput)
 Assign a single character length string to this Burger::String.
 
String16 operator() (uintptr_t uStart, uintptr_t uEnd) const noexcept
 Create a new Burger::String16 from a substring.
 
uint16_toperator() (uintptr_t uInput) noexcept
 Return the reference to a location in the string.
 
uint16_t constoperator() (uintptr_t uInput) const noexcept
 Return the reference to a location in the string.
 
uint16_toperator[] (uintptr_t uInput) noexcept
 Return the reference to a location in the string.
 
uint16_t constoperator[] (uintptr_t uInput) const noexcept
 Return the reference to a location in the string.
 
uint_t operator! () const noexcept
 Return TRUE if the string is empty.
 
uint_t IsValid (void) const noexcept
 Return TRUE if the string has characters.
 
void clear (void) noexcept
 Clear out the data.
 

Static Public Attributes

static const uintptr_t BUFFERSIZE
 Ensures the structure is 128 bytes in size on all platforms.
 

Private Attributes

uint16_tm_pData
 Pointer to the string.
 
uintptr_t m_uLength
 Length of the string.
 
uint16_t m_Raw [BUFFERSIZE]
 Temp preallocated buffer for most strings Structure size is 128 bytes.
 

Detailed Description

UTF 16 bit string class.


This commonly used string class was designed for performance in mind. Each instance takes 128 bytes to contain data for the string and a pointer to allocated memory if the internal string buffer is too large. Since most strings rarely exceed 120 bytes in length, this class will be able to allocate and free strings with no calls to a memory manager. Only when the string exceeds the internal buffer will Burger::Alloc() and Burger::Free() be used.

Functions exist to convert UTF8 and UTF32 data into UTF16 format, which this string class uses internally for data storage.

See also
Burger::String

Constructor & Destructor Documentation

◆ String16() [1/7]

Burger::String16::String16 ( void )
inlinenoexcept

Creates an empty string.


◆ String16() [2/7]

Burger::String16::String16 ( const String16 & rInput)

Initialize a Burger::String16 with a Burger::String16.


Parameters
rInputReference to a Burger::String16

◆ String16() [3/7]

Burger::String16::String16 ( const String16 & rInput,
uintptr_t uStart,
uintptr_t uEnd = UINTPTR_MAX )

Initialize a Burger::String16 by using a subsection of a different Burger::String16.


Given a starting (inclusive) and ending (exclusive) offset, grab the sub string and use it to create a new Burger::String16

Note
If uEnd is less than or equal to uStart, the resulting string will be empty.
Parameters
rInputBurger::String16 to receive input from
uStartOffset to the first character to read from
uEndOffset beyond the last character to read from

◆ String16() [4/7]

Burger::String16::String16 ( const char * pInput)
noexcept

Initialize with a UTF8 "C" string.


Initialize the Burger::String16 with a copy of the passed string. The original string can be discarded after the call returns.

Note
This function will perform a conversion from UTF8 to UTF16
Parameters
pInputPointer to a valid UTF8 "C" string or NULL to create an empty string

◆ String16() [5/7]

Burger::String16::String16 ( const char * pInput,
uintptr_t uPadding )

Initialize with a UTF8 "C" string with padding.


Initialize the Burger::String16 with a copy of the passed string. The original string can be discarded after the call returns. Allocate a buffer that can hold the initialization string + the uPadding number of bytes so the programmer can manually append data to the end of the string with Burger::StringCopy() or equivalent

Parameters
pInputPointer to a valid UTF8 "C" string or NULL to create an empty string
uPaddingNumber of bytes to extend the string buffer. The extra bytes are NOT initialized

◆ String16() [6/7]

Burger::String16::String16 ( const uint16_t * pInput)

Initialize with a UTF16 string.


Copy the UTF16 encoded input string and initialize this class with it. The input string can be discarded after this call.

Parameters
pInputA pointer to a valid UTF16 "C" string

◆ String16() [7/7]

Burger::String16::String16 ( const uint32_t * pInput)

◆ ~String16()

Burger::String16::~String16 ( )
inline

Release memory, if any.


Releases any allocated memory for the string. Under most cases, this performs no operation.

Member Function Documentation

◆ c_str() [1/2]

Burger::String16::c_str ( ) const
inlinenoexcept

Return the const pointer to the string.


Helper to access the const pointer to the UTF16 string

Returns
Pointer to the const UTF16 "C" string.

◆ c_str() [2/2]

Burger::String16::c_str ( )
inlinenoexcept

Return the pointer to the string.


Helper to access the pointer to the UTF16 string

Returns
Pointer to the UTF16 "C" string.

◆ clear()

void Burger::String16::clear ( void )
noexcept

Clear out the data.


Set the string to an empty string

◆ data() [1/2]

const uint16_t * Burger::String16::data ( void ) const
inlinenoexcept

◆ data() [2/2]

uint16_t * Burger::String16::data ( void )
inlinenoexcept

◆ empty()

uint_t Burger::String16::empty ( void ) const
inlinenoexcept

◆ GetLength()

Burger::String16::GetLength ( void ) const
inlinenoexcept

Return the length of the UTF16 "C" string.


Returns
The length in shorts of the UTF16 "C" string

◆ GetPtr() [1/2]

Burger::String16::GetPtr ( ) const
inlinenoexcept

Return the const pointer to the string.


Helper to access the const pointer to the UTF16 string

Returns
Pointer to the const UTF16 "C" string.

◆ GetPtr() [2/2]

Burger::String16::GetPtr ( )
inlinenoexcept

Return the pointer to the string.


Helper to access the pointer to the UTF16 string

Returns
Pointer to the UTF16 "C" string.

◆ IsValid()

Burger::String16::IsValid ( void ) const
inlinenoexcept

Return TRUE if the string has characters.


Returns
FALSE on an empty string, TRUE if there are characters in the string

◆ length()

Burger::String16::length ( void ) const
inlinenoexcept

Return the length of the "C" string.


Returns
The length in shorts of the UTF16 "C" string

◆ operator const uint16_t *()

Burger::String16::operator const uint16_t * ( ) const
inlinenoexcept

Return the const pointer to the string.


Helper to access the const pointer to the UTF16 string

Returns
Pointer to the const UTF16 "C" string.

◆ operator uint16_t()

Burger::String16::operator uint16_t ( ) const
inlinenoexcept

Return the first character of the UTF16 "C" string.


Helper to access the first character of the UTF16 "C" string. It can be zero.

Returns
The first character of the UTF16 "C" string

◆ operator uint16_t *()

Burger::String16::operator uint16_t * ( )
inlinenoexcept

Return the pointer to the string.


Helper to access the pointer to the UTF16 string

Returns
Pointer to the UTF16 "C" string.

◆ operator!()

Burger::String16::operator! ( ) const
inlinenoexcept

Return TRUE if the string is empty.


Returns
TRUE on an empty string, FALSE if there are characters in the string

◆ operator()() [1/3]

Burger::String16::operator() ( uintptr_t uInput) const
inlinenoexcept

Return the reference to a location in the string.


Given an offset into the string, return the reference to the character. If the offset exceeds the length of the string, it will be clamped to the terminating zero.

Parameters
uInputOffset to the starting character of the new string
Returns
A constant reference to the character in the string.
See also
Burger::String16::operator [] (uintptr_t) const

◆ operator()() [2/3]

Burger::String16::operator() ( uintptr_t uInput)
inlinenoexcept

Return the reference to a location in the string.


Given an offset into the string, return the reference to the character. If the offset exceeds the length of the string, it will be clamped to the terminating zero.

Parameters
uInputOffset to the starting character of the new string
Returns
A reference to the character in the string.
See also
Burger::String16::operator [] (uintptr_t)

◆ operator()() [3/3]

Burger::String16::operator() ( uintptr_t uStart,
uintptr_t uEnd ) const
inlinenoexcept

Create a new Burger::String16 from a substring.


Given the start and end offsets of a string, create a new string with those offsets and return the resulting string

Parameters
uStartOffset to the starting character of the new string
uEndOffset to the character AFTER the last character of the new string
Returns
A class instance of Burger::String16 containing the new string.
See also
Burger::String16::String16(const Burger::String16 &,uintptr_t,uintptr_t)

◆ operator=() [1/4]

Burger::String16 & Burger::String16::operator= ( char cInput)

Assign a single character length string to this Burger::String.


If the input is zero, the string is empty.

Note
Since the default encoding is UFT8, input that's greater than 127 will yield a possibly invalid string due to UTF8 decoding.
Parameters
cInputSingle low ASCII character to create a string.
Returns
A reference to the this pointer

◆ operator=() [2/4]

Burger::String16 & Burger::String16::operator= ( const char * pInput)

Assign a "C" string to a Burger::String16.


Copy the contents of a UTF8 "C" string into this Burger::String16

Parameters
pInputPointer to a UTF8 "C" string. NULL generates an empty string.
Returns
A reference to the this pointer

◆ operator=() [3/4]

Burger::String16 & Burger::String16::operator= ( const String16 & rInput)

Assign a Burger::String16.


Copy the contents of a Burger::String16 into this Burger::String16

Parameters
rInputReference to a Burger::String16 to copy from
Returns
A reference to the this pointer

◆ operator=() [4/4]

Burger::String16 & Burger::String16::operator= ( const uint16_t * pInput)

Assign a "C" string to a Burger::String16.


Copy the contents of a UTF8 "C" string into this Burger::String16

Parameters
pInputPointer to a UTF8 "C" string. NULL generates an empty string.
Returns
A reference to the this pointer

◆ operator[]() [1/2]

Burger::String16::operator[] ( uintptr_t uInput) const
inlinenoexcept

Return the reference to a location in the string.


Given an offset into the string, return the reference to the character. If the offset exceeds the length of the string, it will be clamped to the terminating zero.

Parameters
uInputOffset to the starting character of the new string
Returns
A constant reference to the character in the string.
See also
Burger::String16::operator () (uintptr_t) const

◆ operator[]() [2/2]

Burger::String16::operator[] ( uintptr_t uInput)
inlinenoexcept

Return the reference to a location in the string.


Given an offset into the string, return the reference to the character. If the offset exceeds the length of the string, it will be clamped to the terminating zero.

Parameters
uInputOffset to the starting character of the new string
Returns
A reference to the character in the string.
See also
Burger::String16::operator () (uintptr_t)

◆ resize()

eError Burger::String16::resize ( uintptr_t uSize)
inlinenoexcept

◆ Set() [1/2]

Burger::eError BURGER_API Burger::String16::Set ( const char * pInput)
noexcept

Copy an 8 bit "C" string to a Burger::String16.


Parameters
pInputPointer to a UTF16 "C" string. NULL generates an empty string.
Returns
Zero if no error, non zero if memory allocation failed

◆ Set() [2/2]

Burger::eError BURGER_API Burger::String16::Set ( const uint16_t * pInput)
noexcept

Copy a "C" string to a Burger::String.


Note
This function allows using the tail end of the current string as input
Parameters
pInputPointer to a UTF8 "C" string. NULL generates an empty string.
Returns
Zero if no error, non zero if memory allocation failed

◆ SetBufferSize()

Burger::eError BURGER_API Burger::String16::SetBufferSize ( uintptr_t uSize)
noexcept

Force a buffer size.


Set the buffer to a specific size while retaining the existing string. If the preexisting string is too long for the new buffer, it will be truncated. The buffer size will be padded to reserve two bytes for the terminating zero.

Note
If a buffer of 100 characters is requested, 202 bytes will be allocated to hold a string up to 100 characters in length with the 101st short being the terminating zero. The output of Burger::StringLength(const uint16_t *) is acceptable as input for a new string.
Parameters
uSizeNumber of characters to set the buffer to

Member Data Documentation

◆ BUFFERSIZE

const uintptr_t Burger::String16::BUFFERSIZE
static
Initial value:
= static_cast<uintptr_t>(
(128 - (sizeof(uint16_t*) + sizeof(uintptr_t))) / sizeof(uint16_t))

Ensures the structure is 128 bytes in size on all platforms.

◆ m_pData

uint16_t* Burger::String16::m_pData
private

Pointer to the string.

◆ m_Raw

uint16_t Burger::String16::m_Raw[BUFFERSIZE]
private

Temp preallocated buffer for most strings Structure size is 128 bytes.

◆ m_uLength

uintptr_t Burger::String16::m_uLength
private

Length of the string.