Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ustl::string Class Reference

STL basic_string<char> equivalent. More...

#include <ustl.h>

Inheritance diagram for ustl::string:
ustl::memblock ustl::memlink ustl::cmemlink

Public Types

typedef char value_type
 
typedef value_type * pointer
 
typedef const value_type * const_pointer
 
typedef wchar_t wvalue_type
 
typedef wvalue_type * wpointer
 
typedef const wvalue_type * const_wpointer
 
typedef pointer iterator
 
typedef const_pointer const_iterator
 
typedef value_type & reference
 
typedef value_type const_reference
 
typedef ::ustl::reverse_iterator< iterator > reverse_iterator
 
typedef ::ustl::reverse_iterator< const_iterator > const_reverse_iterator
 
typedef utf8in_iterator< const_iterator > utf8_iterator
 
using initlist_t = std::initializer_list< value_type >
 

Public Member Functions

 string (const string &s)
 Assigns itself the value of string s.
 
 string (const string &s, size_type o, size_type n=npos)
 Assigns itself a [o,o+n) substring of s.
 
 string (const cmemlink &l)
 Assigns itself the value of string s.
 
 string (const_pointer s) noexcept
 Links to s.
 
 string (const_pointer s, size_type len)
 Copies the value of s of length len into itself.
 
 string (const_pointer s1, const_pointer s2)
 Copies into itself the string data between s1 and s2.
 
 string (size_type n, value_type c)
 Creates a string of length n filled with character c.
 
pointer data (void)
 
const_pointer data (void) const
 
const_pointer c_str (void) const
 
size_type max_size (void) const
 
size_type capacity (void) const
 
void resize (size_type n)
 Resize the string to n characters. New space contents is undefined.
 
void resize (size_type n, value_type c)
 Resize to n and fill new entries with c.
 
void clear (void)
 
iterator begin (void)
 
const_iterator begin (void) const
 
const_iterator cbegin (void) const
 
iterator end (void)
 
const_iterator end (void) const
 
const_iterator cend (void) const
 
reverse_iterator rbegin (void)
 
const_reverse_iterator rbegin (void) const
 
const_reverse_iterator crbegin (void) const
 
reverse_iterator rend (void)
 
const_reverse_iterator rend (void) const
 
const_reverse_iterator crend (void) const
 
utf8_iterator utf8_begin (void) const
 
utf8_iterator utf8_end (void) const
 
const_reference at (size_type pos) const
 
reference at (size_type pos)
 
const_iterator iat (size_type pos) const
 
iterator iat (size_type pos)
 
const_iterator wiat (size_type i) const noexcept
 Returns the beginning of character i.
 
iterator wiat (size_type i)
 
const_reference front (void) const
 
reference front (void)
 
const_reference back (void) const
 
reference back (void)
 
size_type length (void) const
 
stringappend (const_iterator i1, const_iterator i2)
 
stringappend (const_pointer s, size_type len)
 Appends to itself the value of string s of length len.
 
stringappend (const_pointer s)
 Appends to itself the value of string s of length len.
 
stringappend (size_type n, value_type c)
 Appends to itself n characters of value c.
 
stringappend (size_type n, wvalue_type c)
 
stringappend (const_wpointer s1, const_wpointer s2)
 
stringappend (const_wpointer s)
 
stringappend (const string &s)
 
stringappend (const string &s, size_type o, size_type n)
 
stringassign (const_iterator i1, const_iterator i2)
 
stringassign (const_pointer s, size_type len)
 Assigns itself the value of string s of length len.
 
stringassign (const_pointer s)
 Assigns itself the value of string s.
 
stringassign (const_wpointer s1, const_wpointer s2)
 
stringassign (const_wpointer s1)
 
stringassign (const string &s)
 
stringassign (const string &s, size_type o, size_type n)
 
stringassign (size_type n, value_type c)
 
stringassign (size_type n, wvalue_type c)
 
size_type copy (pointer p, size_type n, size_type pos=0) const noexcept
 Copies [start,start+n) into [p,n). The result is not null terminated.
 
size_type copyto (pointer p, size_type n, size_type pos=0) const noexcept
 
int compare (const string &s) const
 
int compare (size_type start, size_type len, const string &s) const
 
int compare (size_type s1, size_type l1, const string &s, size_type s2, size_type l2) const
 
int compare (const_pointer s) const
 
int compare (size_type s1, size_type l1, const_pointer s, size_type l2) const
 
int compare (size_type s1, size_type l1, const_pointer s) const
 
 operator const value_type * (void) const
 Returns the pointer to the first character.
 
 operator value_type * (void)
 Returns the pointer to the first character.
 
const stringoperator= (const string &s)
 
const stringoperator= (const_reference c)
 
const stringoperator= (const_pointer s)
 
const stringoperator= (const_wpointer s)
 
const stringoperator+= (const string &s)
 
const stringoperator+= (value_type c)
 
const stringoperator+= (const_pointer s)
 
const stringoperator+= (wvalue_type c)
 
const stringoperator+= (const_wpointer s)
 
string operator+ (const string &s) const
 Concatenates itself with s.
 
bool operator== (const string &s) const
 
bool operator== (const_pointer s) const noexcept
 Returns true if this string is equal to string s.
 
bool operator== (value_type c) const
 
bool operator!= (const string &s) const
 
bool operator!= (const_pointer s) const
 
bool operator!= (value_type c) const
 
bool operator< (const string &s) const
 
bool operator< (const_pointer s) const
 
bool operator< (value_type c) const
 
bool operator> (const_pointer s) const
 
stringinsert (size_type ip, size_type n, value_type c)
 
stringinsert (size_type ip, const_pointer s)
 
stringinsert (size_type ip, const_pointer s, size_type nlen)
 
stringinsert (size_type ip, const string &s)
 
stringinsert (size_type ip, const string &s, size_type sp, size_type slen)
 
stringinsert (size_type ip, size_type n, wvalue_type c)
 
stringinsert (size_type ip, const_wpointer first, const_wpointer last, size_type n=1)
 
iterator insert (const_iterator start, size_type n, value_type c)
 Inserts character c into this string at start.
 
iterator insert (const_iterator start, value_type c)
 
iterator insert (const_iterator start, const_pointer s, size_type n)
 Inserts count instances of string s at offset start.
 
iterator insert (const_iterator start, const_pointer first, const_iterator last, size_type n=1)
 Inserts [first,last] n times.
 
iterator erase (const_iterator epo, size_type n=1)
 Erases size bytes at ep.
 
stringerase (size_type epo=0, size_type n=npos)
 Erases n bytes at byte offset epo.
 
iterator erase (const_iterator first, const_iterator last)
 
iterator eraser (size_type first, size_type last)
 
void push_back (value_type c)
 
void push_back (wvalue_type c)
 
void pop_back (void)
 
stringreplace (const_iterator first, const_iterator last, const_pointer i1, const_pointer i2, size_type n)
 Replaces range [start, start + len] with count instances of string s.
 
template<typename InputIt >
stringreplace (const_iterator first, const_iterator last, InputIt first2, InputIt last2)
 
stringreplace (const_iterator first, const_iterator last, const string &s)
 
stringreplace (const_iterator first, const_iterator last, const_pointer s)
 Replaces range [start, start + len] with string s.
 
stringreplace (const_iterator first, const_iterator last, const_pointer s, size_type slen)
 
stringreplace (const_iterator first, const_iterator last, size_type n, value_type c)
 
stringreplace (size_type rp, size_type n, const string &s)
 
stringreplace (size_type rp, size_type n, const string &s, uoff_t sp, size_type slen)
 
stringreplace (size_type rp, size_type n, const_pointer s, size_type slen)
 
stringreplace (size_type rp, size_type n, const_pointer s)
 
stringreplace (size_type rp, size_type n, size_type count, value_type c)
 
string substr (size_type o=0, size_type n=npos) const
 
void swap (string &v)
 
size_type find (value_type c, uoff_t pos=0) const noexcept
 Returns the offset of the first occurence of c after pos.
 
size_type find (const string &s, uoff_t pos=0) const noexcept
 Returns the offset of the first occurence of substring s of length n after pos.
 
size_type find (const_pointer p, size_type pos, size_type count) const
 
size_type rfind (value_type c, uoff_t pos=npos) const noexcept
 Returns the offset of the last occurence of character c before pos.
 
size_type rfind (const string &s, uoff_t pos=npos) const noexcept
 Returns the offset of the last occurence of substring s of size n before pos.
 
size_type rfind (const_pointer p, size_type pos, size_type count) const
 
size_type find_first_of (const string &s, uoff_t pos=0) const noexcept
 Returns the offset of the first occurence of one of characters in s of size n after pos.
 
size_type find_first_of (value_type c, uoff_t pos=0) const
 
size_type find_first_of (const_pointer p, size_type pos, size_type count) const
 
size_type find_first_not_of (const string &s, uoff_t pos=0) const noexcept
 Returns the offset of the first occurence of one of characters not in s of size n after pos.
 
size_type find_first_not_of (value_type c, uoff_t pos=0) const
 
size_type find_first_not_of (const_pointer p, size_type pos, size_type count) const
 
size_type find_last_of (const string &s, uoff_t pos=npos) const noexcept
 Returns the offset of the last occurence of one of characters in s of size n before pos.
 
size_type find_last_of (value_type c, uoff_t pos=0) const
 
size_type find_last_of (const_pointer p, size_type pos, size_type count) const
 
size_type find_last_not_of (const string &s, uoff_t pos=npos) const noexcept
 Returns the offset of the last occurence of one of characters not in s of size n before pos.
 
size_type find_last_not_of (value_type c, uoff_t pos=0) const
 
size_type find_last_not_of (const_pointer p, size_type pos, size_type count) const
 
int vformat (const char *fmt, va_list args)
 Equivalent to a vsprintf on the string.
 
int format (const char *fmt,...) __attribute__((__format__(__printf__
 Equivalent to a sprintf on the string.
 
int void read (istream &)
 Reads the object from stream os.
 
void write (ostream &os) const
 Writes the object to stream os.
 
size_t stream_size (void) const noexcept
 Returns the number of bytes required to write this object to a stream.
 
 string (string &&v)
 
 string (initlist_t v)
 
stringassign (string &&v)
 
stringassign (initlist_t v)
 
stringappend (initlist_t v)
 
stringoperator+= (initlist_t v)
 
stringoperator= (string &&v)
 
stringoperator= (initlist_t v)
 
iterator insert (const_iterator ip, initlist_t v)
 
stringreplace (const_iterator first, const_iterator last, initlist_t v)
 
- Public Member Functions inherited from ustl::memblock
 memblock (const void *p, size_type n)
 
 memblock (size_type n)
 
 memblock (const cmemlink &b)
 
 memblock (const memlink &b)
 
 memblock (const memblock &b)
 
virtual void unlink (void) noexcept override
 
void assign (const cmemlink &l)
 
const memblockoperator= (const cmemlink &l)
 
const memblockoperator= (const memlink &l)
 
const memblockoperator= (const memblock &l)
 
void swap (memblock &l) noexcept
 
void assign (const void *p, size_type n)
 Copies data from p, n.
 
void reserve (size_type newSize, bool bExact=false)
 Reallocates internal block to hold at least newSize bytes. More...
 
void resize (size_type newSize, bool bExact=true)
 resizes the block to newSize bytes, reallocating if necessary.
 
iterator insert (const_iterator start, size_type size)
 Shifts the data in the linked block from start to start + n.
 
iterator erase (const_iterator start, size_type size)
 Shifts the data in the linked block from start + n to start.
 
void clear (void) noexcept
 
size_type capacity (void) const
 
bool is_linked (void) const
 
size_type max_size (void) const
 
void manage (memlink &l)
 
void deallocate (void) noexcept
 Frees internal data.
 
void shrink_to_fit (void)
 Reduces capacity to match size.
 
void manage (void *p, size_type n) noexcept
 
void copy_link (void)
 "Instantiate" a linked block by allocating and copying the linked data.
 
void read (istream &is)
 Reads the object from stream s.
 
void read_file (const char *filename)
 Reads the entire file "filename".
 
 memblock (memblock &&b)
 
memblockoperator= (memblock &&b)
 

Static Public Member Functions

static int compare (const_iterator first1, const_iterator last1, const_iterator first2, const_iterator last2) noexcept
 
static hashvalue_t hash (const char *f1, const char *l1) noexcept
 Returns a hash value for [first, last)
 

Static Public Attributes

static const size_type npos = INT_MAX
 Value that means the end of string.
 

Additional Inherited Members

Detailed Description

STL basic_string<char> equivalent.

An STL container for text string manipulation. Differences from C++ standard:

An additional note is in order regarding the use of indexes. All indexes passed in as arguments or returned by find are byte offsets, not character offsets. Likewise, sizes are specified in bytes, not characters. The rationale is that there is no way for you to know what is in the string. There is no way for you to know how many characters are needed to express one thing or another. The only thing you can do to a localized string is search for delimiters and modify text between them as opaque blocks. If you do anything else, you are hardcoding yourself into a locale! So stop it!

Member Function Documentation

int ustl::string::compare ( const_iterator  first1,
const_iterator  last1,
const_iterator  first2,
const_iterator  last2 
)
staticnoexcept

Returns comparison value regarding string s. The return value is:

  • 1 if this string is greater (by value, not length) than string s
  • 0 if this string is equal to string s
  • -1 if this string is less than string s

References ustl::distance(), ustl::min(), and ustl::sign().

string & ustl::string::insert ( size_type  ipo,
size_type  n,
wvalue_type  c 
)

Inserts wide character c at ipo n times as a UTF-8 string.

ipo is a byte position, not a character position, and is intended to be obtained from one of the find functions. Generally you are not able to know the character position in a localized string; different languages will have different character counts, so use find instead.

References ustl::fill_n(), ustl::memblock::insert(), ustl::Utf8Bytes(), and ustl::utf8out().


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

Generated on Mon Sep 28 2015 17:58:50 for uSTL by Doxygen 1.8.10