VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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
makVrv::DtUnicode Class Reference

A unicode string. More...

Inheritance diagram for makVrv::DtUnicode:
Inheritance graph
[legend]

Classes

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

Public Types

typedef unsigned short CodeUnit

Public Member Functions

 DtUnicode ()
 CTOR creates an empty string.
virtual ~DtUnicode ()
 DTOR may NOT deallocate memory as this string may share data.
 DtUnicode (size_t len, DtUnicodeChar c=DtUnicodeChar('\0'))
 CTOR create a string of n length filled with the unicode character c.
 DtUnicode (const DtUnicode &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.
DtUnicodeoperator= (const DtUnicode &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 DtUnicode variable initialized using the static DtUnicode::tr function, and QLinguist.
void setFromWCharArray (const wchar_t utf16[], int len=-1)
 Initialize via specifying encoding.
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
 Decode via specifying encoding.
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
std::string toUtf8 () const
void toWideString (std::wstring &str) const
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.
DtUnicodeoperator+= (const DtUnicode &str)
 Append a string to the end.
DtUnicodeoperator+= (const DtUnicodeChar &x)
 Append a character to the end.
DtUnicode operator+ (const DtUnicode &str) const
 Append two strings together.
bool operator== (const DtUnicode &other) const
 Test if two strings are identical.
bool operator!= (const DtUnicode &other) const
 Test if two strings are not identical.
bool operator< (const DtUnicode &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 DtUnicode &x, size_t pos=0) const
 Search for a string starting a pos, returns index, or -1 if not found.
DtUnicode 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 containsRightToLeft () const
 Returns true if this text contains any right to left characters.

Static Public Member Functions

static DtUnicode fromWCharArray (const wchar_t utf16[], int len=-1)
 Static create via specifying encoding.
static DtUnicode fromWideString (const std::wstring &str)
 Set from a std::wstring.
static DtUnicode 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 DtUnicode fromUtf8 (const std::string &utf8)
static DtUnicode 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 DtUnicode 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 DtUnicode 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 DtUnicode 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 DtUnicode tr (const char *ascii)
 Ascii translation function, used to be compatible with Qt's translation tools.
template<typename QStringType >
static DtUnicode fromQString (QStringType qstr)
 Template function for setting from Qt 4 style string.

Protected Types

enum  Encoding { Ascii, Latin1, Utf8 }

Protected Member Functions

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

Protected Attributes

CodeUnitArray myCodeUnits

Detailed Description

A unicode string.

DtUnicode 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.

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

Member Typedef Documentation

Member Enumeration Documentation

Enumerator:
Ascii 
Latin1 
Utf8 

Constructor & Destructor Documentation

makVrv::DtUnicode::DtUnicode ( )
inline

CTOR creates an empty string.

virtual makVrv::DtUnicode::~DtUnicode ( )
inlinevirtual

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

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

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

makVrv::DtUnicode::DtUnicode ( const DtUnicode 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.

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

Member Function Documentation

DtUnicode& makVrv::DtUnicode::operator= ( const DtUnicode 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.

static DtUnicode makVrv::DtUnicode::fromWCharArray ( const wchar_t  utf16[],
int  len = -1 
)
inlinestatic

Static create via specifying encoding.

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

static DtUnicode makVrv::DtUnicode::fromWideString ( const std::wstring &  str)
inlinestatic

Set from a std::wstring.

static DtUnicode makVrv::DtUnicode::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.

Referenced by makVrv::DtPageConfiguration::PageCollectionState::serialize().

static DtUnicode makVrv::DtUnicode::fromUtf8 ( const std::string &  utf8)
inlinestatic
static DtUnicode makVrv::DtUnicode::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.

Referenced by fromQString(), and toQString().

static DtUnicode makVrv::DtUnicode::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 DtUnicode makVrv::DtUnicode::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.

Referenced by makVrf::DtRangeRingsSettingsRecord::ColorOption::serialize(), and tr().

static DtUnicode makVrv::DtUnicode::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.

static DtUnicode makVrv::DtUnicode::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.

References fromAscii().

Referenced by makVrf::DtSimulationCommandSetGlobalWeatherDialog::broadcastTitle(), makVrf::DtCommandDialogExtensionInterface::broadcastTitle(), makVrf::DtVisualMetaDataSelectionWidget::codeVariableType(), makVrf::DtLoadoutSelectionWidget::codeVariableType(), makVrf::DtEmbeddedEntitySelectionWidget::codeVariableType(), makVrf::DtDiGuyAnimationSelectionEntryWidget::codeVariableType(), DtIntegerListEntryWidget::codeVariableType(), makVrf::DtStealthObserverViewModesWidget::codeVariableType(), makVrf::DtFormationSelectionEntryWidget::codeVariableType(), makVrf::DtDateTimeEntryWidget::codeVariableType(), makVrf::DtStealthViewModesWidget::codeVariableType(), makVrf::DtEmitterSelectionEntryWidget::codeVariableType(), makVrf::DtResourceSelectionEntryWidget::codeVariableType(), makVrf::DtRangeEntryWidget::codeVariableType(), makVrf::DtColorEntryWidget::codeVariableType(), makVrf::DtEmitterModesSelectionEntryWidget::codeVariableType(), makVrf::DtTurnRateEntryWidget::codeVariableType(), makVrf::DtAltitudeEntryWidget::codeVariableType(), makVrf::DtHeadingEntryWidget::codeVariableType(), makVrf::DtPrecisionMovementEntryWidget::codeVariableType(), makVrf::DtDepthEntryWidget::codeVariableType(), makVrf::DtRateEntryWidget::codeVariableType(), makVrf::DtSphereEntryWidget::codeVariableType(), makVrf::DtEmbarkationSlotEntryWidget::codeVariableType(), makVrf::DtSimpleLabelWidget::codeVariableType(), makVrf::DtOrientationEntryWidget::codeVariableType(), makVrf::DtForceSelectionEntryWidget::codeVariableType(), makVrf::DtNewTacticalGraphicEntryWidget::codeVariableType(), makVrf::DtWeaponSelectionWidget::codeVariableType(), makVrf::DtOffsetLocationEntryWidget::codeVariableType(), makVrf::DtTimeEntryWidget::codeVariableType(), makVrf::DtOverlayParentEntryWidget::codeVariableType(), makVrf::DtSimpleIntegerMapWidget::codeVariableType(), makVrf::DtDiGuyAppearanceSelectionEntryWidget::codeVariableType(), makVrf::DtSimpleSeparatorWidget::codeVariableType(), makVrf::DtSimpleDoubleMapWidget::codeVariableType(), makVrf::DtLocationEntryWidget::codeVariableType(), makVrf::DtDiGuyGestureSelectionEntryWidget::codeVariableType(), makVrf::DtSimpleStringMapWidget::codeVariableType(), makVrf::DtSimpleIntegerVariableWidget::codeVariableType(), makVrf::DtVrfFilteredListView::codeVariableType(), makVrf::DtSimpleDoubleVariableWidget::codeVariableType(), makVrf::DtSimpleStringVariableWidget::codeVariableType(), makVrf::DtSimpleEntityTypeVariableWidget::codeVariableType(), makVrf::DtSimpleEntityTypesVariableWidget::codeVariableType(), makVrf::DtVrfMultiSelectionFilteredListView::codeVariableType(), makVrf::DtFilenameVariableWidget::codeVariableType(), makVrf::DtVrfMultipleSelectionBroadcastFilteredListViewCreator::codeVariableType(), makVrf::DtSimpleComboVariableWidget::codeVariableType(), makVrf::DtSimpleImageComboVariableWidget::codeVariableType(), makVrf::DtSimpleCheckBoxVariableWidget::codeVariableType(), makVrf::DtSimpleRadioButtonVariableWidget::codeVariableType(), makVrf::DtSimpleSingleRadioButtonVariableWidget::codeVariableType(), and makVrf::DtVrfNameSymbolDecorationCreator::displayName().

template<typename QStringType , typename QCoreApp >
QStringType makVrv::DtUnicode::translate ( ) const
inline

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

References toUtf8().

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

Template function for setting from Qt 4 style string.

References fromUtf16().

void makVrv::DtUnicode::setFromWCharArray ( const wchar_t  utf16[],
int  len = -1 
)
inline

Initialize via specifying encoding.

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.

void makVrv::DtUnicode::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 makVrv::DtUnicode::setFromUtf8 ( const std::string &  utf8)
inline
void makVrv::DtUnicode::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.

void makVrv::DtUnicode::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.

Referenced by setFromQString().

void makVrv::DtUnicode::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 makVrv::DtUnicode::setFromAscii ( const std::string &  ascii)
inline

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

void makVrv::DtUnicode::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.

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

Template function for setting from Qt 4 style string.

References setFromUtf16().

void makVrv::DtUnicode::toAscii ( std::string &  str) const
inline

Decode via specifying encoding.

Encode to an ascii string. All non Ascii characters are skipped. Ascii is 0-127

Referenced by makVrf::DtRangeRingsSettingsRecord::ColorOption::serialize().

std::string makVrv::DtUnicode::toAscii ( ) const
inline

References toAscii().

Referenced by toAscii().

void makVrv::DtUnicode::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 makVrv::DtUnicode::toLatin1 ( ) const
inline

References toLatin1().

Referenced by toLatin1().

void makVrv::DtUnicode::toUtf8 ( std::string &  str) const
inline
std::string makVrv::DtUnicode::toUtf8 ( ) const
inline

References toUtf8().

Referenced by toUtf8(), and translate().

void makVrv::DtUnicode::toWideString ( std::wstring &  str) const
inline
std::wstring makVrv::DtUnicode::toWideString ( ) const
inline

References toWideString().

Referenced by toWideString().

template<typename QStringType >
QStringType makVrv::DtUnicode::toQString ( ) const
inline

Template function for outputting a Qt 4 style string.

References codeUnits(), fromUtf16(), and length().

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

Template function for initializing a Qt 4 style string.

References codeUnits(), and length().

DtUnicode& makVrv::DtUnicode::operator+= ( const DtUnicode str)
inline

Append a string to the end.

DtUnicode& makVrv::DtUnicode::operator+= ( const DtUnicodeChar x)
inline

Append a character to the end.

DtUnicode makVrv::DtUnicode::operator+ ( const DtUnicode str) const
inline

Append two strings together.

bool makVrv::DtUnicode::operator== ( const DtUnicode other) const
inline

Test if two strings are identical.

bool makVrv::DtUnicode::operator!= ( const DtUnicode other) const
inline

Test if two strings are not identical.

bool makVrv::DtUnicode::operator< ( const DtUnicode other) const
inline

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

Used for sorting strings.

size_t makVrv::DtUnicode::length ( ) const
inline

Get the length in Code Units.

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

Referenced by makVrv::hash_value(), sizeInBytes(), and toQString().

size_t makVrv::DtUnicode::sizeInBytes ( void  ) const
inline

Get the size in 8bit bytes.

References length().

size_t makVrv::DtUnicode::calculateCodePoints ( ) const
inline

Calculate the number of Code Points.

const CodeUnit* makVrv::DtUnicode::codeUnits ( ) const
inline

Get an array of code units.

References makVrv::DtUnicode::CodeUnitArray::begin, and myCodeUnits.

Referenced by makVrv::hash_value(), and toQString().

int makVrv::DtUnicode::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 makVrv::DtUnicode::indexOf ( const DtUnicode x,
size_t  pos = 0 
) const
inline

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

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

Create a substring starting at position, for n characters.

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

void makVrv::DtUnicode::push_back ( const DtUnicodeChar x)
inline

Append a unicode character to the string.

void makVrv::DtUnicode::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.

virtual bool makVrv::DtUnicode::containsRightToLeft ( ) const
virtual

Returns true if this text contains any right to left characters.

Member Data Documentation

CodeUnitArray makVrv::DtUnicode::myCodeUnits
protected

Referenced by codeUnits().


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

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)