UString  0.1.0
UTF-8 C++11 string library
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
UString Class Reference

#include <UString.h>

Classes

class  IteratorBase
 
class  ReverseIteratorBase
 

Public Types

typedef UChar value_type
 
using Iterator = IteratorBase< std::string::iterator >
 
using ConstIterator = IteratorBase< std::string::const_iterator >
 
using ReverseIterator = ReverseIteratorBase< Iterator >
 
using ConstReverseIterator = ReverseIteratorBase< ConstIterator >
 
using iterator = Iterator
 
using const_iterator = ConstIterator
 
using reverse_iterator = ReverseIterator
 
using const_reverse_iterator = ConstReverseIterator
 

Public Member Functions

 UString ()
 
 UString (const UString &other) USTRING_NOEXCEPT
 
 UString (const char *cstr) USTRING_NOEXCEPT
 
 UString (const std::string &str) USTRING_NOEXCEPT
 
 UString (UChar ch) USTRING_NOEXCEPT
 
UStringinsert (const UString &other, std::size_t pos)
 
UStringassign (const UString &other)
 
UStringassign (const char *other)
 
UStringoperator= (const UString &other)
 
UStringoperator= (const char *other)
 
UStringappend (UChar ch)
 
UStringappend (const UString &str)
 
UStringappend (const char *str)
 
UStringoperator+= (const char *str)
 
UStringoperator+= (const UString &str)
 
void push_back (UChar ch)
 
void push_back (const UString &str)
 
UStringprepend (UChar ch)
 
UStringprepend (const UString &str)
 
UStringprepend (const char *str)
 
void push_front (UChar ch)
 
void push_front (const UString &str)
 
bool operator== (const UString &other) const
 
bool operator== (const char *other) const
 
bool operator!= (const UString &other) const
 
bool operator!= (const char *other) const
 
std::string toStdString () const
 
std::u16string toStdU16String () const
 
std::u32string toStdU32String () const
 
UStringtoUpper ()
 
UStringtoLower ()
 
UStringtoTitleCase ()
 
const UChar at (std::size_t idx) const
 
const UChar operator[] (std::size_t idx) const
 
UString subStr (std::size_t start, std::size_t len=npos) const
 
std::size_t find (UChar ch, std::size_t start=0) const
 
std::size_t find (const UString &what, std::size_t start=0) const
 
std::size_t findLastOf (UChar ch, std::size_t pos=npos) const
 
std::size_t findLastOf (const UString &what, std::size_t pos=npos) const
 
UStringreplace (std::size_t start, std::size_t len, const UString &with)
 
UStringreplaceAll (const UString &what, const UString &with, std::size_t start=0)
 
UStringreplaceFirst (const UString &what, const UString &with, std::size_t start=0)
 
UStringreplaceLast (const UString &what, const UString &with, std::size_t end=npos)
 
UStringerase (const Iterator &start, const Iterator &stop)
 
UStringclear ()
 
UStringerase (std::size_t start, std::size_t num=1)
 
Iterator begin ()
 
Iterator end ()
 
ConstIterator begin () const
 
ConstIterator end () const
 
ReverseIterator rbegin ()
 
ReverseIterator rend ()
 
ConstReverseIterator rbegin () const
 
ConstReverseIterator rend () const
 
std::size_t length () const
 
std::size_t size () const
 
std::size_t maxSize () const
 

Static Public Member Functions

static UString fromStdU16String (const std::u16string &str)
 
static UString fromStdU32String (const std::u32string &str)
 

Static Public Attributes

static const size_t npos = std::string::npos
 

Detailed Description

UTF-8 Encoded String

Constructor & Destructor Documentation

UString::UString ( )
inline

Default constructor which creates an empty string.

UString::UString ( const UString other)

Construct a UString as a copy of another UString.

Parameters
otherUString to copy
UString::UString ( const char *  cstr)

Construct a UString as a copy of another UString.

Parameters
cstrC-string to copy.
UString::UString ( const std::string &  str)

Construct a UString from a std::string

Parameters
strstd::string to copy.
UString::UString ( UChar  ch)
explicit

Construct a UString as a copy of a C string.

Parameters
chUChar character to assign

Member Function Documentation

UString& UString::append ( UChar  ch)

Append a character to the current string

Parameters
chCharacter to append
Returns
Reference to this object
UString& UString::append ( const UString str)

Append a string to the current string

Parameters
strString to append
Returns
Reference to this object
UString& UString::append ( const char *  str)

Append a C-string to the current string

Parameters
strC-string string to append
Returns
Reference to this object
UString& UString::assign ( const UString other)

Assigns other to this string

Parameters
otherString to assign
Returns
Reference to this object
UString& UString::assign ( const char *  other)

Assigns other to this string

Parameters
otherString to assign
Returns
Reference to this object
const UChar UString::at ( std::size_t  idx) const

Get character at position idx

Returns
Character
Iterator UString::begin ( )
inline

Returns a iterator pointing to the beginning of the string

Returns
Iterator pointing to the start of the string
ConstIterator UString::begin ( ) const
inline

Returns a constant iterator pointing to the beginning of the string

Returns
Iterator pointing to the start of the string
UString& UString::clear ( )

Clear this string

Returns
Reference to this object
Iterator UString::end ( )
inline

Returns a iterator pointing to the end of the string

Returns
Iterator pointing to the end of the string
ConstIterator UString::end ( ) const
inline

Returns a constant iterator pointing to the beginning of the string

Returns
Iterator pointing to the start of the string
UString& UString::erase ( const Iterator start,
const Iterator stop 
)

Erase character(s) at given index

Parameters
startIterator reference to position to begin erasing
stopIterator reference to position to stop erasing
Returns
Reference to this object
UString& UString::erase ( std::size_t  start,
std::size_t  num = 1 
)

Erase character(s) in given iterator range

Parameters
startIndex of character to start erasing
numNumber of characters to erase
Returns
Reference to this object
std::size_t UString::find ( UChar  ch,
std::size_t  start = 0 
) const

Find a UChar character

Parameters
chcharacter to find
startPosition to begin searching from
Returns
Position of the character if found, npos if not.
std::size_t UString::find ( const UString what,
std::size_t  start = 0 
) const

Find a string

Parameters
whatString to search for
startPosition to begin searching from
Returns
Position of the first character of the string if found, npos if not.
std::size_t UString::findLastOf ( UChar  ch,
std::size_t  pos = npos 
) const

Find the last instance of a UChar character

Parameters
chCharacter to search for
posPosition of last character to include in search
Returns
Position of the character of the string if found, npos if not.
std::size_t UString::findLastOf ( const UString what,
std::size_t  pos = npos 
) const

Find the last instance of a string

Parameters
whatString to search for
posPosition of last character to include in search
Returns
Position of the character of the string if found, npos if not.
static UString UString::fromStdU16String ( const std::u16string &  str)
static

Convert a string from UTF-16 and return a new UTF-8 encoded string

Parameters
strUTF-16 encoded string to convert
Returns
UTF-16 encoded string
static UString UString::fromStdU32String ( const std::u32string &  str)
static

Convert a string from UTF-32 and return a new UTF-8 encoded string

Parameters
strUTF-32 encoded string to convert
Returns
New UTF-8 encoded string
UString& UString::insert ( const UString other,
std::size_t  pos 
)

Inserts other string into this one at the given position

If the given position is greater than the length of this string it will be appended.

Parameters
otherString to insert
posPosition of the string to insert at
Returns
Reference to this object
std::size_t UString::length ( ) const

Returns the length of characters in the string

Returns
The length of characters in the string starting from zero
std::size_t UString::maxSize ( ) const

Returns the maximum length the string can reach

From CplusPlus.com: This is the maximum potential length the string can reach due to known system or library implementation limitations, but the object is not guaranteed to be able to reach that length: it can still fail to allocate storage at any point before that length is reached.

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

Check if this string not equals the other.

Returns
True if not equal, False if equal
bool UString::operator!= ( const char *  other) const

Check if this string not equals the other.

Returns
True if not equal, False if equal
UString& UString::operator+= ( const char *  str)

Append a C-string to the current string

Parameters
strC-string string to append
Returns
Reference to this object
UString& UString::operator+= ( const UString str)

Append a string to the current string

Parameters
strString to append
Returns
Reference to this object
UString& UString::operator= ( const UString other)

Assigns other to this string

Parameters
otherString to assign
Returns
Reference to this object
UString& UString::operator= ( const char *  other)

Assigns other to this string

Parameters
otherString to assign
Returns
Reference to this object
bool UString::operator== ( const UString other) const

Check if this string equals the other.

Returns
True if equal, False if not
bool UString::operator== ( const char *  other) const

Check if this string equals the other.

Returns
True if equal, False if not
const UChar UString::operator[] ( std::size_t  idx) const

Get character at position idx

Returns
Character
UString& UString::prepend ( UChar  ch)

Prepend a character to the current string

Parameters
chCharacter to prepend
Returns
Reference to this object
UString& UString::prepend ( const UString str)

Prepend a string to the current string

Parameters
strString to prepend
Returns
Reference to this object
UString& UString::prepend ( const char *  str)

Prepend a C-string to the current string

Parameters
strC-string to prepend
Returns
Reference to this object
void UString::push_back ( UChar  ch)

Append a string to the current string

This is provided for STL compatibility and simply calls append()

Parameters
strString to append
void UString::push_back ( const UString str)

Append a string to the current string

This is provided for STL compatibility and simply calls append()

Parameters
strString to append
void UString::push_front ( UChar  ch)

Prepend a UChar to the current string

This is provieded for STL compatibility and simply calls prepend()

Parameters
chCharacter to append
void UString::push_front ( const UString str)

Prepend a UString to the current string

This is provieded for STL compatibility and simply calls prepend()

Parameters
strUString to append
ReverseIterator UString::rbegin ( )
inline

Returns a reverse iterator pointing to the reverse beginning of the string

Returns
Iterator pointing to the reverse beginning of the string
ConstReverseIterator UString::rbegin ( ) const
inline

Returns a constant reverse iterator pointing to the reverse beginning of the string

Returns
Iterator pointing to the reverse beginning of the string
ReverseIterator UString::rend ( )
inline

Returns a reverse iterator pointing to the reverse end of the string

Returns
Iterator pointing to the reverse end of the string
ConstReverseIterator UString::rend ( ) const
inline

Returns a constant reverse iterator pointing to the reverse end of the string

Returns
Iterator pointing to the reverse end of the string
UString& UString::replace ( std::size_t  start,
std::size_t  len,
const UString with 
)

Replace part of this string with another string

Parameters
startStart of the section to replace
lenNumber of characters to replace counting from start
withString to replace cut subsection with
Returns
Reference to this object
UString& UString::replaceAll ( const UString what,
const UString with,
std::size_t  start = 0 
)

Replace all instances of a string with another

Parameters
whatString to search for
withString to use for replacement
startThe position to begin searching at
Returns
Reference to this object
UString& UString::replaceFirst ( const UString what,
const UString with,
std::size_t  start = 0 
)

Replace first instance of a string with another

Parameters
whatString to search for
withString to use for replacement
startThe position to begin searching at
Returns
Reference to this object
UString& UString::replaceLast ( const UString what,
const UString with,
std::size_t  end = npos 
)

Replace last instance of a string with another

Parameters
whatString to search for
withString to use for replacement
endThe position to end our search at or npos
Returns
Reference to this object
std::size_t UString::size ( ) const

Returns the size of the string in bytes

Returns
The size of the string in bytes
UString UString::subStr ( std::size_t  start,
std::size_t  len = npos 
) const

Create a new string using a sub-section of this string

Parameters
startPosition to start copying characters from
lenNumber of characters to copy or until the end if len is npos
Returns
New string containing characters copied
UString& UString::toLower ( )

Convert any uppercase characters in the string to lower

Returns
Reference to this object
std::string UString::toStdString ( ) const

Convert to std::string.

Returns
std::string
std::u16string UString::toStdU16String ( ) const

Convert to UTF-16 and return it as a std::u16string

Returns
std::u16string
std::u32string UString::toStdU32String ( ) const

Convert to UTF-32 std::u32string.

Returns
std::u32string
UString& UString::toTitleCase ( )

Convert string to titleCase

Returns
Reference to this object
UString& UString::toUpper ( )

Convert any lowercase characters in the string to upper

Returns
Reference to this object

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