Name

SString — A wrapper for QString (QT Unicode string implementation).

Synopsis

class SString {
public:
  // types
  typedef Char               value_type;     
  typedef std::size_t        size_type;      
  typedef value_type &       reference;      
  typedef const value_type & const_reference;
  typedef value_type *       iterator;       
  typedef const value_type * const_iterator; 

  // construct/copy/destruct
  SString();
  SString(const SString &);
  SString(const value_type *, size_type);
  SString(const unsigned char *, size_type);
  SString(const char *);
  SString(Char);
  SString(const QString &);
  SString& operator=(const SString &);
  SString& operator=(const char *);
  ~SString();

  // public member functions

  void resize(size_type, value_type = 0) ;
  void reserve(size_type = 0) ;
  const value_type * c_str() const;
  const value_type * unicode() const;
  const value_type * data() const;
  size_type length() const;
  reference at(size_type) ;
  const_reference at(size_type) const;
  reference operator[](size_type) ;
  const_reference operator[](size_type) const;
  bool isEmpty() const;
  bool empty() const;
  bool isNull() const;
  iterator begin() ;
  const_iterator begin() const;
  iterator end() ;
  const_iterator end() const;
  SString & append(const SString &) ;
  SString & append(const SString &, size_type, size_type) ;
  SString & append(const value_type *, size_type) ;
  SString & append(const value_type *) ;
  SString & append(size_type, value_type) ;
  void push_back(value_type) ;
  SString & append(const_iterator, const_iterator) ;
  SString & insert(size_type, const SString &) ;
  SString & insert(size_type, const SString &, size_type, size_type) ;
  SString & insert(size_type, const value_type *, size_type) ;
  SString & insert(size_type, const value_type *) ;
  SString & insert(size_type, size_type, value_type) ;
  iterator insert(iterator, value_type = value_type()) ;
  void insert(iterator, size_type, value_type) ;
  void insert(iterator, const_iterator, const_iterator) ;
  SString & erase(size_type = 0, size_type = npos) ;
  iterator erase(iterator) ;
  iterator erase(iterator, iterator) ;
  SString & replace(size_type, size_type, const SString &) ;
  SString & replace(size_type, size_type, const SString &, size_type, 
                    size_type) ;
  SString & replace(size_type, size_type, const value_type *, size_type) ;
  SString & replace(size_type, size_type, const value_type *) ;
  SString & replace(size_type, size_type, size_type, value_type) ;
  SString & replace(iterator, iterator, const SString &) ;
  SString & replace(iterator, iterator, const value_type *, size_type) ;
  SString & replace(iterator, iterator, const value_type *) ;
  SString & replace(iterator, iterator, size_type, value_type) ;
  SString & replace(iterator, iterator, const_iterator, const_iterator) ;
  size_type copy(value_type *, size_type, size_type = 0) const;
  void swap(SString &) ;
  size_type find(const SString &, size_type = 0) const;
  size_type find(const value_type *, size_type, size_type) const;
  size_type find(const value_type *, size_type = 0) const;
  size_type find(value_type, size_type = 0) const;
  size_type rfind(const SString &, size_type = npos) const;
  size_type rfind(const value_type *, size_type, size_type) const;
  size_type rfind(const value_type *, size_type = npos) const;
  size_type rfind(value_type, size_type = npos) const;
  size_type find_first_of(const SString &, size_type = 0) const;
  size_type find_first_of(const value_type *, size_type, size_type) const;
  size_type find_first_of(const value_type *, size_type = 0) const;
  size_type find_first_of(value_type, size_type = 0) const;
  size_type find_last_of(const SString &, size_type = npos) const;
  size_type find_last_of(const value_type *, size_type, size_type) const;
  size_type find_last_of(const value_type *, size_type = npos) const;
  size_type find_last_of(value_type, size_type = npos) const;
  size_type find_first_not_of(const SString &, size_type = 0) const;
  size_type find_first_not_of(const value_type *, size_type, size_type) const;
  size_type find_first_not_of(const value_type *, size_type = 0) const;
  size_type find_last_not_of(const SString &, size_type = npos) const;
  size_type find_last_not_of(const value_type *, size_type, size_type) const;
  size_type find_last_not_of(const value_type *, size_type = npos) const;
  size_type find_last_not_of(value_type, size_type = npos) const;
  SString substr(size_type = 0, size_type = npos) const;
  int compare(const SString &) const;
  int compare(size_type, size_type, const SString &) const;
  int compare(size_type, size_type, const value_type *, size_type) const;
  int compare(size_type, size_type, const SString &, size_type, size_type) const;
  int compare(const value_type *) const;
  SString operator+(const SString &) const;
  SString & operator+=(const SString &) ;
  SString & operator+=(const char *) ;
  SString & operator+=(const value_type &) ;
  char * toLatin1(char * = 0, size_type = 0) const;
  char * toUtf8(char * = 0, size_type = 0) const;
  char * toLocal8Bit(char * = 0, size_type = 0) const;
  short toShort(bool * = 0, int = 10) const;
  unsigned short toUShort(bool * = 0, int = 10) const;
  int toInt(bool * = 0, int = 10) const;
  unsigned int toUInt(bool * = 0, int = 10) const;
  long toLong(bool * = 0, int = 10) const;
  unsigned long toULong(bool * = 0, int = 10) const;
  float toFloat(bool * = 0) const;
  double toDouble(bool * = 0) const;
  SString lower() const;
  SString upper() const;
  SString stripWhiteSpace() const;
  SString simplifyWhiteSpace() const;
  SString left(size_type) const;
  SString right(size_type) const;
  SString mid(size_type, size_type = npos) const;
  operator QString() const;

  // public static functions

  SString number(long, int = 10) ;
  SString number(unsigned, int = 10) ;
  SString number(int, int = 10) ;
  SString number(unsigned, int = 10) ;
  SString number(double, char = 'g', int = 6) ;

  static const size_type npos;
};

Description

SString construct/copy/destruct

  1. SString();

    Constructs null string.


  2. SString(const SString & );

    Constructs string from another string.


  3. SString(const value_type * data, size_type len);

    Construct String from Unicode buffer data with length len.


  4. SString(const unsigned char * data, size_type len);

    Create SString from ASCII string.


  5. SString(const char * data);


  6. SString(Char c);

    Construct SString from single Unicode character.


  7. SString(const QString & );

    Construct SString from QString.


  8. SString& operator=(const SString & );


  9. SString& operator=(const char * );


  10. ~SString();


SString public member functions

  1. void resize(size_type , value_type c = 0) ;

    Resize string to the given length; pad end with c.


  2. void reserve(size_type new_cap = 0) ;

    ensures capacity of the string


  3. const value_type * c_str() const;

    Returns pointer to the start of Unicode data of the string (null terminated).


  4. const value_type * unicode() const;

    Returns pointer to the start of Unicode data of the string.


  5. const value_type * data() const;

    Returns pointer to the start of Unicode data of the string.


  6. size_type length() const;

    Returns length of the string.


  7. reference at(size_type pos) ;

    Returns reference to the character at given position.


  8. const_reference at(size_type pos) const;

    Returns reference to the character at given position.


  9. reference operator[](size_type pos) ;


  10. const_reference operator[](size_type pos) const;


  11. bool isEmpty() const;

    Returns TRUE if the string is empty (has zero length)


  12. bool empty() const;

    Returns TRUE if the string is empty (has zero length)


  13. bool isNull() const;

    Returns TRUE if the string is null. Note that null string is not the same as empty string (when S = "", S is empty, not null)


  14. iterator begin() ;

    Returns

    iterator that points to the beginning of string


  15. const_iterator begin() const;

    Returns

    const iterator that points to the beginning of string


  16. iterator end() ;

    Returns

    iterator that points just beyond the end of string


  17. const_iterator end() const;

    Returns

    const iterator that points just beyond the end of string


  18. SString & append(const SString & str) ;

    equivalent to the

     operator+=(\a str) 
    


  19. SString & append(const SString & str, size_type pos, size_type n) ;

    appends n chars from str starting at pos


  20. SString & append(const value_type * s, size_type n) ;

    appends n chars from a sequence pointed to by s


  21. SString & append(const value_type * s) ;

    appends T::length(s) chars from a sequence pointed to by s


  22. SString & append(size_type n, value_type c) ;

    appends n c characters

            SString<char> s("ab");
            s.append(3, 'x'); \n s.c_str() == "abxxx"; 
    


  23. void push_back(value_type c) ;

    appends c character, allows std::back_inserter<E> to be used

            std::istreambuf_iterator start(cin), end; \n SString<char> s;
            std::copy(start, end, back_inserter<char>(s)); 
    

    inserts characters from cin into s until EOF is reached


  24. SString & append(const_iterator first, const_iterator last) ;

    appends sequence of elements designated by [first, last)


  25. SString & insert(size_type pos, const SString & str) ;

    inserts contents of the string str at position pos


  26. SString & insert(size_type pos1, const SString & str, size_type pos2,                  size_type n) ;

    n characters of str starting at pos2 will be inserted at pos //!

     SString<char> s("abcd"), str("1234");
     s.insert(1, str, 2, 2); s.c_str() == "a34bcd"; 
    
    Throws


  27. SString & insert(size_type pos, const value_type * s, size_type n) ;

    inserts n characters pointed to by s at position pos

    Throws


  28. SString & insert(size_type pos, const value_type * s) ;

    inserts T::length(s) characters pointed to by null-terminated sequence pointed to by s at position pos

    Throws


  29. SString & insert(size_type pos, size_type n, value_type c) ;

    inserts n characters c at position pos

    Throws


  30. iterator insert(iterator p, value_type c = value_type()) ;

    equivalent to

     insert(p - begin(), 1, c) 
    


  31. void insert(iterator p, size_type n, value_type c) ;

    equivalent to

     insert(p - begin(), n, c) 
    


  32. void insert(iterator p, const_iterator first, const_iterator last) ;

    inserts copy of sequence designated by [first, last) at position corresponding to iterator p


  33. SString & erase(size_type pos = 0, size_type n = npos) ;

    removes n characters starting at position pos

    Throws


  34. iterator erase(iterator pos) ;

    equivalent to

     erase(pos - begin(), 1); 
    
    Returns

    pos


  35. iterator erase(iterator first, iterator last) ;

    erases characters in range [first, last)

    Returns

    first


  36. SString & replace(size_type pos, size_type n, const SString & str) ;

    replaces n chars starting at position pos by contents of str

    Throws


  37. SString & replace(size_type pos1, size_type n1, const SString & str,                   size_type pos2, size_type n2) ;

    replaces n1 chars starting at position pos1 by sequence of chars from range str[pos2, pos2 + n2)

    Throws


  38. SString & replace(size_type pos, size_type n1, const value_type * s,                   size_type n2) ;

    replaces n1 chars starting at position pos by sequence of chars from range [s, s + n2)

    Throws


  39. SString & replace(size_type pos, size_type n, const value_type * s) ;

    replaces n chars starting at position pos by T::length(s) chars //! from null-terminated sequence pointed to by s

    Throws


  40. SString & replace(size_type pos, size_type n1, size_type n2, value_type c) ;

    replaces n1 chars starting at position pos by n2 chars c

    Throws


  41. SString & replace(iterator i1, iterator i2, const SString & str) ;

    replaces sequence of chars designated by [i1, i2) by contents of the string str


  42. SString & replace(iterator i1, iterator i2, const value_type * s, size_type n) ;

    replaces sequence of chars designated by [i1, i2) by sequence of chars from range [s, s + n)


  43. SString & replace(iterator i1, iterator i2, const value_type * s) ;

    replaces sequence of chars designated by [i1, i2) by T::length(s) chars from null-terminated sequence pointed by s


  44. SString & replace(iterator i1, iterator i2, size_type n, value_type c) ;

    replaces sequence of chars designated by [i1, i2) by n characters c


  45. SString & replace(iterator i1, iterator i2, const_iterator j1,                   const_iterator j2) ;

    replaces sequence of chars designated by [i1, i2) by sequence designated by [j1, j2)


  46. size_type copy(value_type * s, size_type n, size_type pos = 0) const;

    copies n characters starting at position pos into the buffer pointed to by s


  47. void swap(SString & rhs) ;

    swaps contents of the string with contents of rhs


  48. size_type find(const SString & str, size_type pos = 0) const;

    finds the occurrence of str. search starts from position pos

    Returns

    position where str occurs or npos if search fails


  49. size_type find(const value_type * s, size_type pos, size_type n) const;

    finds the occurrence of sequence [s, s + n). search starts from position pos.

    Returns

    position where str occurs or npos if search fails


  50. size_type find(const value_type * s, size_type pos = 0) const;

    finds the occurrence of sequence [s, s + T::length(s)). search starts from position pos.

    Returns

    position where str occurs or npos if search fails


  51. size_type find(value_type c, size_type pos = 0) const;

    finds occurrence of char c, starting from position pos


  52. size_type rfind(const SString & str, size_type pos = npos) const;

    finds backward for the occurrence of str. search starts from position pos

    Returns

    position where str occurs or npos if search fails


  53. size_type rfind(const value_type * s, size_type pos, size_type n) const;

    finds backward the occurrence of sequence [s, s + n). search starts from position pos.

    Returns

    position where str occurs or npos if search fails


  54. size_type rfind(const value_type * s, size_type pos = npos) const;

    finds backward the occurrence of sequence [s, s + T::length(s)). search starts from position pos.

    Returns

    position where str occurs or npos if search fails


  55. size_type rfind(value_type c, size_type pos = npos) const;

    finds backward occurrence of char c, starting from position pos


  56. size_type find_first_of(const SString & str, size_type pos = 0) const;

    finds the first occurrence of any character from str. search starts from position pos returns position where char occurs or npos if search fails


  57. size_type find_first_of(const value_type * s, size_type pos, size_type n) const;

    finds the first occurrence of any character from [s, s + n). search starts from position pos.

    Returns

    position where char occurs or npos if search fails


  58. size_type find_first_of(const value_type * s, size_type pos = 0) const;

    finds the first occurrence of any character from sequence [s, s + T::length(s)). search starts from position pos.

    Returns

    position where char occurs or npos if search fails


  59. size_type find_first_of(value_type c, size_type pos = 0) const;

    finds the first occurrence of char c, starting from pos


  60. size_type find_last_of(const SString & str, size_type pos = npos) const;

    finds the last occurrence of any character from str. search starts from position pos returns position where char occurs or npos if search fails


  61. size_type find_last_of(const value_type * s, size_type pos, size_type n) const;

    finds the last occurrence of any char from sequence [s, s + n). /// search starts from position pos.

    Returns

    position where char occurs or npos if search fails


  62. size_type find_last_of(const value_type * s, size_type pos = npos) const;

    finds the last occurrence of any char from sequence [s, s + T::length(s)) search starts from position pos.

    Returns

    position where char occurs or npos if search fails


  63. size_type find_last_of(value_type c, size_type pos = npos) const;

    finds the last occurrence of char c, starting from pos


  64. size_type find_first_not_of(const SString & str, size_type pos = 0) const;

    finds the first occurrence of char not from str. search starts from position pos

    Returns

    position where char occurs or npos otherwise


  65. size_type find_first_not_of(const value_type * s, size_type pos, size_type n) const;

    finds the first occurrence of any char not from sequence [s, s + n). search starts from position pos.

    Returns

    position where char occurs or npos if search fails


  66. size_type find_first_not_of(const value_type * s, size_type pos = 0) const;

    finds the first occurrence of any character not from sequence [s, s + T::length(s)). search starts from position pos.

    Returns

    position where char occurs or npos if search fails


  67. size_type find_last_not_of(const SString & str, size_type pos = npos) const;

    finds the first occurrence of char that's not c, starting from pos size_type find_first_not_of(value_type c, size_type pos = 0) const; finds the last occurrence of char not from str. search starts from position pos

    Returns

    position where char occurs or npos otherwise


  68. size_type find_last_not_of(const value_type * s, size_type pos, size_type n) const;

    finds the last occurrence of any char not from sequence [s, s + n). search starts from position pos

    Returns

    position where char occurs or npos if search fails


  69. size_type find_last_not_of(const value_type * s, size_type pos = npos) const;

    finds the last occurrence of any character not from sequence [s, s + T::length(s)). search starts from position pos.

    Returns

    position where char occurs or npos if search fails


  70. size_type find_last_not_of(value_type c, size_type pos = npos) const;

    finds the last occurrence of char that's not c, starting from pos


  71. SString substr(size_type pos = 0, size_type n = npos) const;

    returns copy of n characters starting from position pos

    Throws


  72. int compare(const SString & str) const;

    Returns

    x such that x < 0 if str is greater than *this, x == 0 if str is equal to *this, and x > 0 if str is less than this


  73. int compare(size_type pos, size_type n, const SString & str) const;

    equivalent to

     SString(*this, pos, n).compare(str); 
    


  74. int compare(size_type pos1, size_type n1, const value_type * s, size_type n2) const;

    equivalent to

            SString(*this, pos1, n1).compare(SString(s, n2));
    


  75. int compare(size_type pos1, size_type n1, const SString & str, size_type pos2,             size_type n2) const;

    equivalent to

            SString(*this, pos1, n1).compare(SString(str, pos2, n2));
    


  76. int compare(const value_type * s) const;

    equivalent to

     compare(SString(s)); 
    


  77. SString operator+(const SString & rhs) const;

    returns string that's concatenation of *this and rhs


  78. SString & operator+=(const SString & s) ;

    returns string that's concatenation of *this and s


  79. SString & operator+=(const char * s) ;

    returns string that's concatenation of *this and s


  80. SString & operator+=(const value_type & c) ;

    returns string that's concatenation of *this and c


  81. char * toLatin1(char * buf = 0, size_type maxlen = 0) const;

    Translate string to latin_1, with max size maxlen. This function always returns buf. If buf = 0, then internal static buffer is used (use with caution!)


  82. char * toUtf8(char * buf = 0, size_type maxlen = 0) const;

    Translate string to utf8.


  83. char * toLocal8Bit(char * buf = 0, size_type maxlen = 0) const;

    Translate string to local8bit.


  84. short toShort(bool * ok = 0, int base = 10) const;

    converts string to numbers


  85. unsigned short toUShort(bool * ok = 0, int base = 10) const;

    converts string to numbers


  86. int toInt(bool * ok = 0, int base = 10) const;

    converts string to numbers


  87. unsigned int toUInt(bool * ok = 0, int base = 10) const;

    converts string to numbers


  88. long toLong(bool * ok = 0, int base = 10) const;

    converts string to numbers


  89. unsigned long toULong(bool * ok = 0, int base = 10) const;

    converts string to numbers


  90. float toFloat(bool * ok = 0) const;

    converts string to numbers


  91. double toDouble(bool * ok = 0) const;

    converts string to numbers


  92. SString lower() const;

    Returns a lowercase copy of the string.


  93. SString upper() const;

    Returns an uppercase copy of the string.


  94. SString stripWhiteSpace() const;

    Returns a string that has whitespace removed from the start and the end.

    Whitespace means any character for which Char::isSpace() returns TRUE. This includes Unicode characters with decimal values 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR) and 32 (Space), and may also include other Unicode characters.

    See also: simplifyWhiteSpace()


  95. SString simplifyWhiteSpace() const;

    Returns a string that has whitespace removed from the start and the end, and which has each sequence of internal whitespace replaced with a single space.

    Whitespace means any character for which Char::isSpace() returns TRUE. This includes Unicode characters with decimal values 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR), and 32 (Space).

    See also: stripWhiteSpace()


  96. SString left(size_type len) const;

    Returns a substring that contains the len leftmost characters of the string.

    The whole string is returned if len exceeds the length of the string. See also: right(), mid(), isEmpty()


  97. SString right(size_type len) const;

    Returns a string that contains the len rightmost characters of the string.

    If len is greater than the length of the string then the whole string is returned.

    left(), mid(), isEmpty()


  98. SString mid(size_type index, size_type len = npos) const;

    Returns a string that contains the len characters of this string, starting at position index.

    Returns a null string if the string is empty or index is out of range. Returns the whole string from index if index + len exceeds the length of the string.

    left(), right()


  99. operator QString() const;


SString public static functions

  1. SString number(long , int base = 10) ;


  2. SString number(unsigned long, int base = 10) ;


  3. SString number(int , int base = 10) ;


  4. SString number(unsigned int, int base = 10) ;


  5. SString number(double , char f = 'g', int prec = 6) ;