C++ Based OPC UA Client/Server/PubSub SDK  1.7.6.537
UaUniString Class Reference

OPC UA string handling class. More...

#include <uaunistring.h>

Public Member Functions

 UaUniString ()
 Default constructor. More...
 
 UaUniString (const UaByteArray &other)
 Creates a copy of a UTF-16 encoded ByteArray. More...
 
 UaUniString (const UaUniString &other)
 Creates a copy of another UaUniString. More...
 
 UaUniString (const UaUShort *other)
 Creates a copy of the native OpcUa_String. More...
 
 UaUniString (const char *other)
 Creates a UaUniString from a UTF-8 encoded char* character string.
 
 ~UaUniString ()
 Destroys the string. More...
 
UaUniStringoperator= (const UaUniString &other)
 Assigns other to this string and returns a reference to this string. More...
 
int length () const
 Returns the number of characters of this string. More...
 
int size () const
 Returns the size in bytes that the internal UTF-16 representation needs to hold this string. More...
 
bool isEmpty () const
 Returns true if the string is empty or a null string. More...
 
bool isNull () const
 Returns true if the string is a null string. More...
 
void clear ()
 Clears a UaUniString.
 
UaUniString left (int len) const
 Returns a UaUniString substring that contains the n leftmost characters of the string. More...
 
UaUniString mid (int pos, int len=-1) const
 Returns a UaUniString string that contains n characters of the string, starting at the specified position. More...
 
UaUniString right (int len) const
 Returns a UaUniString substring that contains the n rightmost characters of the string. More...
 
UaUniString arg (unsigned int num, int fieldWidth=0, int base=10)
 Returns a copy of this string with the lowest numbered place marker replaced by the given number num, i.e., %%1, %%2, ..., %%9. More...
 
UaUniString arg (int num, int fieldWidth=0, int base=10)
 Returns a copy of this string with the lowest numbered place marker replaced by the given number num, i.e., %%1, %%2, ..., %%9. More...
 
UaUniString arg (double num, int fieldWidth=0, char format= 'g', int precision=-1)
 Returns a copy of this string with the lowest numbered place marker replaced by the given floating point number num, i.e., %%1, %%2, ..., %%9. More...
 
UaUniString arg (const UaUniString &text)
 Returns a copy of this string with the lowest numbered place marker replaced by the given string text, i.e., %%1, %%2, ..., %%9. More...
 
UaUShort at (int pos) const
 Returns a read only UTF-16 character. More...
 
bool startsWith (const UaUniString &strToFind) const
 Check if the string starts with the search string. More...
 
bool endsWith (const UaUniString &strToFind) const
 Check if the string ends with the search string. More...
 
UaUniStringreplace (const UaUniString &before, const UaUniString &after)
 Replaces every occurrence of the string before with the string after. More...
 
UaUniStringreplace (const UaUShort &before, const UaUShort &after)
 Replaces every occurrence of the character before with the character after. More...
 
UaUniStringreplace (int position, int n, const UaUniString &after)
 Replaces n characters starting at index position with the string after. More...
 
UaUniStringreplace (int position, const UaUShort &after)
 Replaces the character at index position with the character after. More...
 
UaUniStringList split (const UaUniString &separator) const
 Splits the string into substrings wherever the separator occurs, and returns the list of those strings. More...
 
UaUniStringappend (const UaUniString &str)
 Appends the string str to end of this string. More...
 
UaUniStringappend (const UaUShort ch)
 Appends the character ch to end of this string. More...
 
UaUniStringprepend (const UaUniString &str)
 Prepends the string str to the beginning of this string. More...
 
UaUniStringprepend (const UaUShort ch)
 Prepends the UaUShort ch to the beginning of this string. More...
 
UaUniString trimmed () const
 Returns a copy of this string which has whitespaces removed from start and end. More...
 
int indexOf (const UaUniString &strToFind, int from=0) const
 Returns the index position of the first occurrence of the string strToFind in this string. More...
 
int indexOf (const UaUShort charToFind, int from=0) const
 Returns the index position of the first occurrence of the character charToFind in this string. More...
 
int lastIndexOf (const UaUniString &strToFind, int from=-1) const
 Returns the index position of the last occurrence of the string strToFind in this string. More...
 
int lastIndexOf (const UaUShort charToFind, int from=-1) const
 Returns the index position of the last occurrence of the character charToFind in this string. More...
 
void chop (int n)
 Removes n characters from the end of the string if n is greater than length(), the result is an empty string.
 
bool operator== (const UaUniString &other) const
 Returns true if other is equal to this. More...
 
bool operator!= (const UaUniString &other) const
 Returns true if other is not equal to this. More...
 
bool operator< (const UaUniString &other) const
 This operator is mainly used to sort strings. More...
 
bool operator> (const UaUniString &other) const
 This operator is mainly used to sort strings. More...
 
UaUniStringoperator+= (const UaUniString &other)
 Appends a string to the internal string. More...
 
const UaUShort * toUtf16 () const
 Returns the string as a '\0'-terminated array of UTF-16 characters. More...
 
bool isBiggerThan (const UaUniString &other, bool bCaseSensitive) const
 This operator is mainly used to sort strings in alphabetical order. More...
 
bool isSmallerThan (const UaUniString &other, bool bCaseSensitive) const
 This operator is mainly used to sort strings in alphabetical order. More...
 

Detailed Description

OPC UA string handling class.

This class encapsulates an UTF16 encoded string

Constructor & Destructor Documentation

UaUniString::UaUniString ( )

Default constructor.

Creates an empty UaUniString.

UaUniString::UaUniString ( const UaByteArray other)

Creates a copy of a UTF-16 encoded ByteArray.

Parameters
otherUaByteArray.
UaUniString::UaUniString ( const UaUniString other)

Creates a copy of another UaUniString.

This operation takes constant time, because UaUniString is implicitly shared. This makes returning a UaUniString from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.

UaUniString::UaUniString ( const UaUShort *  other)

Creates a copy of the native OpcUa_String.

Parameters
otherSource string.
UaUniString::~UaUniString ( )

Destroys the string.

Member Function Documentation

UaUniString & UaUniString::append ( const UaUniString str)

Appends the string str to end of this string.

UaUniString & UaUniString::append ( const UaUShort  ch)

Appends the character ch to end of this string.

UaUniString UaUniString::arg ( unsigned int  num,
int  fieldWidth = 0,
int  base = 10 
)

Returns a copy of this string with the lowest numbered place marker replaced by the given number num, i.e., %%1, %%2, ..., %%9.

Parameters
numThe number that should be converted to string before inserted.
fieldWidthspecifies the minimum amount of space that argument a shall occupy. If a requires less space than fieldWidth, it is padded to fieldWidth with '0'.
baseThe base used for the number to string conversion. This must be in the range of 2-36.
Returns
The new string. This example shows how we might create a status string for reporting progress while processing a list of files:
unsigned int i; // current file's number
unsigned int total; // number of files to process
UaUniString fileName; // current file's name
UaUniString status = UaUniString("Processing file %1 of %2: %3")
.arg(i).arg(total).arg(fileName);
First, arg(i) replaces %1. Then arg(total) replaces %2. Finally, arg(fileName) replaces %3. One advantage of using arg() over sprintf() is that the order of the numbered place markers can change, if the application's strings are translated into other languages, but each arg() will still replace the lowest numbered unreplaced place marker, no matter where it appears. This functions always replaces the lowest number found. Place marker numbers must be in the range 1 to 9.
UaUniString UaUniString::arg ( int  num,
int  fieldWidth = 0,
int  base = 10 
)

Returns a copy of this string with the lowest numbered place marker replaced by the given number num, i.e., %%1, %%2, ..., %%9.

This function behaves like the function above, but works with signed int.

Parameters
numThe number that should be converted to string before inserted.
fieldWidthspecifies the minimum amount of space that argument a shall occupy. If a requires less space than fieldWidth, it is padded to fieldWidth with '0'.
baseThe base used for the number to string conversion. This must be in the range of 2-36.
Returns
The new string. This function overloads arg().
UaUniString UaUniString::arg ( double  num,
int  fieldWidth = 0,
char  format = 'g',
int  precision = -1 
)

Returns a copy of this string with the lowest numbered place marker replaced by the given floating point number num, i.e., %%1, %%2, ..., %%9.

This function behaves like the function above, but works with a double.

Parameters
numThe number that should be converted to string before inserted.
fieldWidthspecifies the minimum amount of space that argument a shall occupy. If a requires less space than fieldWidth, it is padded to fieldWidth with '0'.
format'g', 'f', or 'e'. This parameter conforms to the snprintf format specifier.
precisionPrecisions of the floating pointer number.
Returns
The new string. This function overloads arg().
UaUniString UaUniString::arg ( const UaUniString text)

Returns a copy of this string with the lowest numbered place marker replaced by the given string text, i.e., %%1, %%2, ..., %%9.

This function overloads arg().

Parameters
textThe text that should be inserted.
Returns
The new string.
UaUShort UaUniString::at ( int  pos) const

Returns a read only UTF-16 character.

See also
replace()
bool UaUniString::endsWith ( const UaUniString strToFind) const

Check if the string ends with the search string.

int UaUniString::indexOf ( const UaUniString strToFind,
int  from = 0 
) const

Returns the index position of the first occurrence of the string strToFind in this string.

Searching forward from index position from. Returns -1 if strToFind is not found. If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.

int UaUniString::indexOf ( const UaUShort  charToFind,
int  from = 0 
) const

Returns the index position of the first occurrence of the character charToFind in this string.

Searching forward from index position from. Returns -1 if charToFind is not found. If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.

bool UaUniString::isBiggerThan ( const UaUniString other,
bool  bCaseSensitive 
) const

This operator is mainly used to sort strings in alphabetical order.

Parameters
bCaseSensitiveFlag indicating if the comparison is case sensitive or not. This method will return false if both string are equal.
otherOther string to compare with.
bool UaUniString::isEmpty ( ) const

Returns true if the string is empty or a null string.

bool UaUniString::isNull ( ) const

Returns true if the string is a null string.

Returns false if the string is an empty string.

bool UaUniString::isSmallerThan ( const UaUniString other,
bool  bCaseSensitive 
) const

This operator is mainly used to sort strings in alphabetical order.

Parameters
bCaseSensitiveFlag indicating if the comparison is case sensitive or not.
otherSource string. This method will return false if both string are equal.
int UaUniString::lastIndexOf ( const UaUniString strToFind,
int  from = -1 
) const

Returns the index position of the last occurrence of the string strToFind in this string.

Searching backward from index position from. Returns -1 if strToFind is not found. If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.

int UaUniString::lastIndexOf ( const UaUShort  charToFind,
int  from = -1 
) const

Returns the index position of the last occurrence of the character charToFind in this string.

Searching backward from index position from. If from is -1 (the default), the search starts at the last character. If form is -2, at the next to last character and so on. Returns -1 if str is not found.

UaUniString UaUniString::left ( int  len) const

Returns a UaUniString substring that contains the n leftmost characters of the string.

If len is greater than the string length or less than zero the entire string is returned

int UaUniString::length ( ) const

Returns the number of characters of this string.

You will need this function for displaying it. With UTF-16 strings the number of characters and the size in bytes will differ.

UaUniString UaUniString::mid ( int  pos,
int  len = -1 
) const

Returns a UaUniString string that contains n characters of the string, starting at the specified position.

If pos is bigger than the length a null string is returned If len is greater than the stringlength-pos or len == -1 than all characters from the position are returned.

bool UaUniString::operator!= ( const UaUniString other) const

Returns true if other is not equal to this.

See also
operator==
UaUniString & UaUniString::operator+= ( const UaUniString other)

Appends a string to the internal string.

This creates a copy of the string because the internal data needs to changed.

bool UaUniString::operator< ( const UaUniString other) const

This operator is mainly used to sort strings.

That is e.g. necessary to use it as a key in a binary tree. Note that this comparison is based on the length of the strings and on the numeric Unicode values - not alphabetical.

UaUniString & UaUniString::operator= ( const UaUniString other)

Assigns other to this string and returns a reference to this string.

bool UaUniString::operator== ( const UaUniString other) const

Returns true if other is equal to this.

See also
operator!=
bool UaUniString::operator> ( const UaUniString other) const

This operator is mainly used to sort strings.

That is e.g. necessary to use it as a key in a binary tree. Note that this comparison is based on the length of the strings and on the numeric Unicode values - not alphabetical.

Parameters
otherOther string to compare with.
UaUniString & UaUniString::prepend ( const UaUniString str)

Prepends the string str to the beginning of this string.

Parameters
strthe string to prepend to.
Returns
a new created string.
UaUniString & UaUniString::prepend ( const UaUShort  ch)

Prepends the UaUShort ch to the beginning of this string.

Parameters
chthe string to prepend to.
Returns
a new created string.
UaUniString & UaUniString::replace ( const UaUniString before,
const UaUniString after 
)

Replaces every occurrence of the string before with the string after.

UaUniString & UaUniString::replace ( const UaUShort &  before,
const UaUShort &  after 
)

Replaces every occurrence of the character before with the character after.

UaUniString & UaUniString::replace ( int  position,
int  n,
const UaUniString after 
)

Replaces n characters starting at index position with the string after.

UaUniString & UaUniString::replace ( int  position,
const UaUShort &  after 
)

Replaces the character at index position with the character after.

UaUniString UaUniString::right ( int  len) const

Returns a UaUniString substring that contains the n rightmost characters of the string.

If len is greater than the string length or less than zero the entire string is returned

int UaUniString::size ( ) const

Returns the size in bytes that the internal UTF-16 representation needs to hold this string.

You will only need this function, if you want to allocate a native UTF-16 string that should be big enough to hold this string.

UaUniStringList UaUniString::split ( const UaUniString separator) const

Splits the string into substrings wherever the separator occurs, and returns the list of those strings.

If the separator does not match anywhere in the string, split() returns a single-element list containing this string.

bool UaUniString::startsWith ( const UaUniString strToFind) const

Check if the string starts with the search string.

const UaUShort * UaUniString::toUtf16 ( ) const

Returns the string as a '\0'-terminated array of UTF-16 characters.

The result remains valid until the string is modified.

UaUniString UaUniString::trimmed ( ) const

Returns a copy of this string which has whitespaces removed from start and end.

This also removes ASCII characters '\n', '\t', '\v', '\f', '\r', and ' '.


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