VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
DtUcString Class Reference

A unicode string. More...

+ Inheritance diagram for DtUcString:
+ Collaboration diagram for DtUcString:

Classes

struct  CodeUnitArray
 Internal structure used to store the code units. More...

Public Types

typedef unsigned short CodeUnit

Public Member Functions

 DtUcString ()
 CTOR creates an empty string.
 DtUcString (size_t len, DtUnicodeChar c=DtUnicodeChar('\0'))
 CTOR create a string of n length filled with the unicode character c.
 DtUcString (const DtUcString &str)
 Copy ctor copies the string, this function will NOT allocate memory for the string, and thus it is fast to pass by value, and create many identical copies of a string.
 ~DtUcString ()
 DTOR may NOT deallocate memory as this string may share data.
DtUcStringoperator= (const DtUcString &str)
 Assignment operator copies the string, this function will NOT allocate memory for the string, and thus it is fast to pass by value, and create many identical copies of a string.
template<typename QStringType , typename QCoreApp >
QStringType translate () const
 Utility function for translating a DtUcString variable initialized using the static DtUcString::tr function, and QLinguist.
void setFromWCharArray (const wchar_t utf16[], int len=-1)
 Set from an wchar string, the string MUST be zero terminated if the length is not passed, the encoding of wchar arrays are different on each platform.
void setFromUtf8 (const unsigned char *utf8, int len=-1)
 Set from an UTF-8 encoded string, the string MUST be zero terminated if the length is not passed.
void setFromUtf8 (const std::string &utf8)
void setFromLatin1 (const char *latin, int len=-1)
 Set from an UTF-8 encoded string, the string MUST be zero terminated if the length is not passed.
void setFromUtf16 (const unsigned short *utf16, int len=-1)
 Set from an UTF-16 encoded string, the string MUST be zero terminated if the length is not passed.
void setFromUtf32 (const unsigned int *utf32, int len=-1)
 Set from an UTF-32 encoded string, the string MUST be zero terminated if the length is not passed.
void setFromAscii (const std::string &ascii)
 Set from an ascii string, the string MUST be zero terminated if the length is not passed.
void setFromAscii (const char *ascii, int len=-1)
 Set from an ascii string, the string MUST be zero terminated if the length is not passed.
template<typename QStringType >
void setFromQString (QStringType qstr)
 Template function for setting from Qt 4 style string.
void toAscii (std::string &str) const
 Encode to an ascii string.
std::string toAscii () const
void toLatin1 (std::string &str) const
 Encode to an Latin-1 string.
std::string toLatin1 () const
void toUtf8 (std::string &str) const
 Encode to a UTF-8 string.
std::string toUtf8 () const
void toWideString (std::wstring &str) const
 Encode to a wstring.
std::wstring toWideString () const
template<typename QStringType >
QStringType toQString () const
 Template function for outputting a Qt 4 style string.
template<typename QStringType >
void toQString (QStringType &qstr) const
 Template function for initializing a Qt 4 style string.
DtUcStringoperator+= (const DtUcString &str)
 Append a string to the end.
DtUcStringoperator+= (const DtUnicodeChar &x)
 Append a character to the end.
DtUcString operator+ (const DtUcString &str) const
 Append two strings together.
bool operator== (const DtUcString &other) const
 Test if two strings are identical.
bool operator!= (const DtUcString &other) const
 Test if two strings are not identical.
bool operator< (const DtUcString &other) const
 Test if a string is less than another based on their first different character or the length.
size_t length () const
 Get the length in Code Units.
size_t sizeInBytes () const
 Get the size in 8bit bytes.
size_t calculateCodePoints () const
 Calculate the number of Code Points.
const CodeUnitcodeUnits () const
 Get an array of code units.
int indexOf (const DtUnicodeChar &x, size_t pos=0) const
 Search for a character starting a pos, returns index, or -1 if not found.
int indexOf (const DtUcString &x, size_t pos=0) const
 Search for a string starting a pos, returns index, or -1 if not found.
int lastIndexOf (const DtUnicodeChar &x, size_t pos=0) const
 Search for a character starting a pos, returns index, or -1 if not found.
int lastIndexOf (const DtUcString &x, size_t pos=0) const
 Search for a string starting a pos, returns index, or -1 if not found.
DtUcString subString (size_t pos=0, int len=-1) const
 Create a substring starting at position, for n characters.
void push_back (const DtUnicodeChar &x)
 Append a unicode character to the string.
void resize (int size)
 Resize a string to a new size, if the size < 0 the string will be empty.
virtual bool snipFront (const char ch, bool toLastCh=false)
 Truncates everything before or after the character, including the character, respectively.
virtual bool snipBack (const char ch, bool fromFirstCh=false)
 Truncates everything before or after the character, including the character, respectively.

Static Public Member Functions

static DtUcString fromWCharArray (const wchar_t utf16[], int len=-1)
 Set from a wchar_t array, compiler encoding specific, the string MUST be zero terminated if the length is not passed.
static DtUcString fromWideString (const std::wstring &str)
 Set from a std::wstring.
static DtUcString fromUtf8 (const unsigned char *utf8, int len=-1)
 Create a unicode string from an UTF-16 encoded string, the string MUST be zero terminated if the length is not passed.
static DtUcString fromUtf8 (const std::string &utf8)
static DtUcString fromUtf16 (const unsigned short *utf16, int len=-1)
 Create a unicode string from an UTF-16 encoded string, the string MUST be zero terminated if the length is not passed.
static DtUcString fromUtf32 (const unsigned int *utf32, int len=-1)
 Create a unicode string from an UTF-32 encoded string, the string MUST be zero terminated if the length is not passed.
static DtUcString fromAscii (const std::string &ascii)
 Create a unicode string from an ascii string, the string MUST be zero terminated if the length is not passed.
static DtUcString fromAscii (const char *ascii, int len=-1)
 Create a unicode string from an ascii string, the string MUST be zero terminated if the length is not passed.
static DtUcString tr (const char *ascii)
 Ascii translation function, used to be compatible with Qt's translation tools.
template<typename QStringType >
static DtUcString fromQString (QStringType qstr)
 Template function for setting from Qt 4 style string.

Protected Types

enum  Encoding { Ascii, Latin1, Utf8 }

Protected Member Functions

 DtUcString (const char *ascii, int len=-1, Encoding encoding=Ascii)
 DtUcString (const unsigned short *utf16, int len=-1)
 DtUcString (const unsigned int *utf32, int len=-1)
 DtUcString (const std::string &ascii)
 DtUcString (const DtUcString &a, const DtUcString &b)

Protected Attributes

CodeUnitArray myCodeUnits

Detailed Description

A unicode string.

DtUcString stores a UTF-16 encoded unicode string. Code Point, a Unicode character, UTF encodes a Code Point in 1 or 2 Code Units. Code Unit, a 16 bit word. Each character is 1 or 2 code units.

DtUcString uses copy on write, thus creating copies and passing by value is cheap, however special care must be taken when passing between threads. DtUcString reference counts are thread safe, however the content is not so thread synchronization is required when modifying strings.

Member Typedef Documentation

typedef unsigned short DtUcString::CodeUnit

Member Enumeration Documentation

enum DtUcString::Encoding
protected
Enumerator:
Ascii 
Latin1 
Utf8 

Constructor & Destructor Documentation

DtUcString::DtUcString ( )
inline

CTOR creates an empty string.

DtUcString::DtUcString ( size_t  len,
DtUnicodeChar  c = DtUnicodeChar('\0') 
)
inlineexplicit

CTOR create a string of n length filled with the unicode character c.

DtUcString::DtUcString ( const DtUcString str)
inline

Copy ctor copies the string, this function will NOT allocate memory for the string, and thus it is fast to pass by value, and create many identical copies of a string.

DtUcString::~DtUcString ( )
inline

DTOR may NOT deallocate memory as this string may share data.

DtUcString::DtUcString ( const char *  ascii,
int  len = -1,
Encoding  encoding = Ascii 
)
inlineexplicitprotected
DtUcString::DtUcString ( const unsigned short *  utf16,
int  len = -1 
)
inlineexplicitprotected
DtUcString::DtUcString ( const unsigned int *  utf32,
int  len = -1 
)
inlineexplicitprotected
DtUcString::DtUcString ( const std::string &  ascii)
inlineexplicitprotected
DtUcString::DtUcString ( const DtUcString a,
const DtUcString b 
)
inlineexplicitprotected

Member Function Documentation

size_t DtUcString::calculateCodePoints ( ) const
inline

Calculate the number of Code Points.

const CodeUnit* DtUcString::codeUnits ( ) const
inline

Get an array of code units.

Referenced by hash_value().

static DtUcString DtUcString::fromAscii ( const std::string &  ascii)
inlinestatic

Create a unicode string from an ascii string, the string MUST be zero terminated if the length is not passed.

static DtUcString DtUcString::fromAscii ( const char *  ascii,
int  len = -1 
)
inlinestatic

Create a unicode string from an ascii string, the string MUST be zero terminated if the length is not passed.

template<typename QStringType >
static DtUcString DtUcString::fromQString ( QStringType  qstr)
inlinestatic

Template function for setting from Qt 4 style string.

static DtUcString DtUcString::fromUtf16 ( const unsigned short *  utf16,
int  len = -1 
)
inlinestatic

Create a unicode string from an UTF-16 encoded string, the string MUST be zero terminated if the length is not passed.

static DtUcString DtUcString::fromUtf32 ( const unsigned int *  utf32,
int  len = -1 
)
inlinestatic

Create a unicode string from an UTF-32 encoded string, the string MUST be zero terminated if the length is not passed.

static DtUcString DtUcString::fromUtf8 ( const unsigned char *  utf8,
int  len = -1 
)
inlinestatic

Create a unicode string from an UTF-16 encoded string, the string MUST be zero terminated if the length is not passed.

static DtUcString DtUcString::fromUtf8 ( const std::string &  utf8)
inlinestatic
static DtUcString DtUcString::fromWCharArray ( const wchar_t  utf16[],
int  len = -1 
)
inlinestatic

Set from a wchar_t array, compiler encoding specific, the string MUST be zero terminated if the length is not passed.

static DtUcString DtUcString::fromWideString ( const std::wstring &  str)
inlinestatic

Set from a std::wstring.

int DtUcString::indexOf ( const DtUnicodeChar x,
size_t  pos = 0 
) const
inline

Search for a character starting a pos, returns index, or -1 if not found.

int DtUcString::indexOf ( const DtUcString x,
size_t  pos = 0 
) const
inline

Search for a string starting a pos, returns index, or -1 if not found.

int DtUcString::lastIndexOf ( const DtUnicodeChar x,
size_t  pos = 0 
) const
inline

Search for a character starting a pos, returns index, or -1 if not found.

int DtUcString::lastIndexOf ( const DtUcString x,
size_t  pos = 0 
) const
inline

Search for a string starting a pos, returns index, or -1 if not found.

size_t DtUcString::length ( ) const
inline

Get the length in Code Units.

This is NOT the length in bytes, or the number of code points.

Referenced by hash_value().

bool DtUcString::operator!= ( const DtUcString other) const
inline

Test if two strings are not identical.

DtUcString DtUcString::operator+ ( const DtUcString str) const
inline

Append two strings together.

DtUcString& DtUcString::operator+= ( const DtUcString str)
inline

Append a string to the end.

DtUcString& DtUcString::operator+= ( const DtUnicodeChar x)
inline

Append a character to the end.

bool DtUcString::operator< ( const DtUcString other) const
inline

Test if a string is less than another based on their first different character or the length.

Used for sorting strings.

DtUcString& DtUcString::operator= ( const DtUcString str)
inline

Assignment operator copies the string, this function will NOT allocate memory for the string, and thus it is fast to pass by value, and create many identical copies of a string.

Reimplemented in DtUcFilename.

bool DtUcString::operator== ( const DtUcString other) const
inline

Test if two strings are identical.

void DtUcString::push_back ( const DtUnicodeChar x)
inline

Append a unicode character to the string.

void DtUcString::resize ( int  size)
inline

Resize a string to a new size, if the size < 0 the string will be empty.

If size is greater than the current size, the string is extended to make it size characters long with the extra characters added to the end. The new characters are uninitialized. If size is less than the current size, characters are removed from the end. If the size is less than 0, the string will be resized to 0 without deallocating if possible.

void DtUcString::setFromAscii ( const std::string &  ascii)
inline

Set from an ascii string, the string MUST be zero terminated if the length is not passed.

void DtUcString::setFromAscii ( const char *  ascii,
int  len = -1 
)
inline

Set from an ascii string, the string MUST be zero terminated if the length is not passed.

void DtUcString::setFromLatin1 ( const char *  latin,
int  len = -1 
)
inline

Set from an UTF-8 encoded string, the string MUST be zero terminated if the length is not passed.

template<typename QStringType >
void DtUcString::setFromQString ( QStringType  qstr)
inline

Template function for setting from Qt 4 style string.

void DtUcString::setFromUtf16 ( const unsigned short *  utf16,
int  len = -1 
)
inline

Set from an UTF-16 encoded string, the string MUST be zero terminated if the length is not passed.

void DtUcString::setFromUtf32 ( const unsigned int *  utf32,
int  len = -1 
)
inline

Set from an UTF-32 encoded string, the string MUST be zero terminated if the length is not passed.

void DtUcString::setFromUtf8 ( const unsigned char *  utf8,
int  len = -1 
)
inline

Set from an UTF-8 encoded string, the string MUST be zero terminated if the length is not passed.

void DtUcString::setFromUtf8 ( const std::string &  utf8)
inline
void DtUcString::setFromWCharArray ( const wchar_t  utf16[],
int  len = -1 
)
inline

Set from an wchar string, the string MUST be zero terminated if the length is not passed, the encoding of wchar arrays are different on each platform.

Do NOT assume a wchar string is UTF16 or UTF32.

size_t DtUcString::sizeInBytes ( ) const
inline

Get the size in 8bit bytes.

virtual bool DtUcString::snipBack ( const char  ch,
bool  fromFirstCh = false 
)
virtual

Truncates everything before or after the character, including the character, respectively.

Normally, snipFront stops at the first occurrence of "ch", and snipBack stops at the last occurrence of "ch". The second argument flags reverse this. Return value is true if "ch" was found in the string. Does not include the null terminator (only searches characters counted by size).

virtual bool DtUcString::snipFront ( const char  ch,
bool  toLastCh = false 
)
virtual

Truncates everything before or after the character, including the character, respectively.

Normally, snipFront stops at the first occurrence of "ch", and snipBack stops at the last occurrence of "ch". The second argument flags reverse this. Return value is true if "ch" was found in the string. Does not include the null terminator (only searches characters counted by size).

DtUcString DtUcString::subString ( size_t  pos = 0,
int  len = -1 
) const
inline

Create a substring starting at position, for n characters.

If len is -1. for the remaining characters. if pos is out of range then a null string is returned.

void DtUcString::toAscii ( std::string &  str) const
inline

Encode to an ascii string.

All non Ascii characters are skipped. Ascii is 0-127

std::string DtUcString::toAscii ( ) const
inline
void DtUcString::toLatin1 ( std::string &  str) const
inline

Encode to an Latin-1 string.

All non Latin-1 characters are skipped. Latin-1 is is 0-255

std::string DtUcString::toLatin1 ( ) const
inline
template<typename QStringType >
QStringType DtUcString::toQString ( ) const
inline

Template function for outputting a Qt 4 style string.

template<typename QStringType >
void DtUcString::toQString ( QStringType &  qstr) const
inline

Template function for initializing a Qt 4 style string.

void DtUcString::toUtf8 ( std::string &  str) const
inline

Encode to a UTF-8 string.

std::string DtUcString::toUtf8 ( ) const
inline
void DtUcString::toWideString ( std::wstring &  str) const
inline

Encode to a wstring.

std::wstring DtUcString::toWideString ( ) const
inline
static DtUcString DtUcString::tr ( const char *  ascii)
inlinestatic

Ascii translation function, used to be compatible with Qt's translation tools.

This will simply call fromAscii. The name 'tr' is used by Qt's translation tools when scanning source code for translatable strings. This function should only take string literals aka "characters" and should never take pointer variables.

template<typename QStringType , typename QCoreApp >
QStringType DtUcString::translate ( ) const

Utility function for translating a DtUcString variable initialized using the static DtUcString::tr function, and QLinguist.

Member Data Documentation

CodeUnitArray DtUcString::myCodeUnits
protected

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

Document ID: Generated on Mon Apr 8 04:49:21 EDT 2019 from SVN revision 197403
Copyright © 2005-2016 VT MÄK. All Rights Reserved (www.mak.com)