# PIP: PIString Class Reference

PIString Class Reference

String class. More...

Inherits PIDeque< T >.

## Public Member Functions

| PIString ()
| Contructs an empty string.
| PIString (const PIChar &c)
| Contructs string with single symbol "c".
| PIString (const char *str)
| Contructs string from c-string "str". More...
| PIString (const wchar_t *str)
| Contructs string from `wchar_t` c-string "str". More...
| PIString (const std::string &str)
| Contructs string from std::string "str".
| PIString (const PIByteArray &ba)
| Contructs string from byte array "ba".
| PIString (const PIChar *str, const int len)
| Contructs string from "len" characters of buffer "str".
| PIString (const char *str, const int len)
| Contructs string from "len" characters of buffer "str". More...
| PIString (const int len, const char c)
| Contructs string as sequence of characters "c" of buffer with length "len". More...
| PIString (const int len, const PIChar &c)
| Contructs string as sequence of symbols "c" of buffer with length "len". More...
| operator const char * ()
| Return c-string representation of string. More...
| operator const std::string ()
| Return std::string representation of string.
PIChar | operator[] (const int pos) const
| Return symbol at index "pos".
PIChar & | operator[] (const int pos)
| Return reference to symbol at index "pos".
bool | operator== (const PIString &str) const
| Compare operator.
bool | operator== (const PIChar c) const
| Compare operator.
bool | operator== (const char *str) const
| Compare operator.
bool | operator== (const std::string &str) const
| Compare operator.
bool | operator!= (const PIString &str) const
| Compare operator.
bool | operator!= (const PIChar c) const
| Compare operator.
bool | operator!= (const char *str) const
| Compare operator.
bool | operator!= (const std::string &str) const
| Compare operator.
bool | operator< (const PIString &str) const
| Compare operator.
bool | operator< (const PIChar c) const
| Compare operator.
bool | operator< (const char *str) const
| Compare operator.
bool | operator< (const std::string &str) const
| Compare operator.
bool | operator> (const PIString &str) const
| Compare operator.
bool | operator> (const PIChar c) const
| Compare operator.
bool | operator> (const char *str) const
| Compare operator.
bool | operator> (const std::string &str) const
| Compare operator.
bool | operator<= (const PIString &str) const
| Compare operator.
bool | operator<= (const PIChar c) const
| Compare operator.
bool | operator<= (const char *str) const
| Compare operator.
bool | operator<= (const std::string &str) const
| Compare operator.
bool | operator>= (const PIString &str) const
| Compare operator.
bool | operator>= (const PIChar c) const
| Compare operator.
bool | operator>= (const char *str) const
| Compare operator.
bool | operator>= (const std::string &str) const
| Compare operator.
PIString & | operator<< (const PIString &str)
| Append string "str" at the end of string. More...
PIString & | operator<< (const PIChar &c)
| Append symbol "c" at the end of string. More...
PIString & | operator<< (const char *str)
| Append c-string "str" at the end of string. More...
PIString & | operator<< (const wchar_t *str)
| Append `wchar_t` c-string "str" at the end of string. More...
PIString & | operator<< (const std::string &str)
| Append std::string "str" at the end of string.
PIString & | operator<< (const int &num)
| Append string representation of "num" at the end of string. More...
PIString & | operator<< (const short &num)
| Append string representation of "num" at the end of string. More...
PIString & | operator<< (const long &num)
| Append string representation of "num" at the end of string. More...
PIString & | operator<< (const float &num)
| Append string representation of "num" at the end of string. More...
PIString & | operator<< (const double &num)
| Append string representation of "num" at the end of string. More...
PIString & | prepend (const PIString &str)
| Insert string "str" at the begin of string.
PIString & | append (const PIString &str)
| Insert string "str" at the end of string.
PIString | mid (const int start, const int len=-1) const
| Return part of string from symbol at index "start" and maximum length "len". More...
PIString | left (const int len) const
| Return part of string from left and maximum length "len". More...
PIString | right (const int len) const
| Return part of string from right and maximum length "len". More...
PIString & | cutMid (const int start, const int len)
| Remove part of string from symbol as index "start" and maximum length "len" and return this string. More...
PIString & | cutLeft (const int len)
| Remove part of string from left and maximum length "len" and return this string. More...
PIString & | cutRight (const int len)
| Remove part of string from right and maximum length "len" and return this string. More...
PIString & | trim ()
| Remove spaces at the start and at the end of string and return this string. More...
PIString | trimmed () const
| Return copy of this string without spaces at the start and at the end. More...
PIString & | replace (const int from, const int count, const PIString &with)
| Replace part of string from index "from" and maximum length "len" with string "with" and return this string. More...
PIString | replaced (const int from, const int count, const PIString &with) const
| Replace part copy of this string from index "from" and maximum length "len" with string "with" and return copied string. More...
PIString & | replace (const PIString &what, const PIString &with, bool *ok=0)
| Replace first founded substring "what" with string "with" and return this string. More...
PIString | replaced (const PIString &what, const PIString &with, bool *ok=0) const
| Replace first founded substring "what" with string "with" and return copied string. More...
PIString & | replaceAll (const PIString &what, const PIString &with)
| Replace all founded substrings "what" with strings "with" and return this string. More...
PIString & | repeat (int times)
| Repeat content of string "times" times and return this string. More...
PIString | repeated (int times) const
| Returns repeated "times" times string. More...
PIString & | insert (const int index, const PIChar &c)
| Insert symbol "c" after index "index" and return this string. More...
PIString & | insert (const int index, const char &c)
| Insert symbol "c" after index "index" and return this string. More...
PIString & | insert (const int index, const PIString &str)
| Insert string "str" after index "index" and return this string. More...
PIString & | insert (const int index, const char *c)
| Insert string "str" after index "index" and return this string. More...
PIString & | expandRightTo (const int len, const PIChar &c)
| Enlarge string to length "len" by addition sequence of symbols "c" at the end of string, and return this string. More...
PIString & | expandLeftTo (const int len, const PIChar &c)
| Enlarge string to length "len" by addition sequence of symbols "c" at the beginning of string, and return this string. More...
PIString & | reverse ()
| Reverse string and return this string. More...
PIString | reversed () const
| Reverse copy of this string and return it. More...
PIString | takeMid (const int start, const int len=-1)
| Take a part of string from symbol at index "start" and maximum length "len" and return it. More...
PIString | takeLeft (const int len)
| Take a part from the begin of string with maximum length "len" and return it. More...
PIString | takeRight (const int len)
| Take a part from the end of string with maximum length "len" and return it. More...
PIString | takeSymbol ()
| Take a symbol from the begin of this string and return it. More...
PIString | takeWord ()
| Take a word from the begin of this string and return it. More...
PIString | takeCWord ()
| Take a word with letters, numbers and '_' symbols from the begin of this string and return it. More...
PIString | takeLine ()
| Take a line from the begin of this string and return it. More...
PIString | takeNumber ()
| Take a number with C-format from the begin of this string and return it. More...
PIString | takeRange (const PIChar &start, const PIChar &end, const PIChar &shield= '\\')
| Take a range between "start" and "end" symbols from the begin of this string and return it. More...
int | lengthAscii () const
| Return real bytes count of this string. More...
const char * | data () const
| Return `char` * representation of this string. More...
std::string | stdString () const
| Return `std::string` representation of this string.
PIByteArray | toByteArray () const
| Return PIByteArray contains data() of this string.
PIStringList | split (const PIString &delim) const
| Split string with delimiter "delim" to PIStringList and return it. More...
PIString | toUpperCase () const
| Convert each symbol in copyed string to upper case and return it.
PIString | toLowerCase () const
| Convert each symbol in copyed string to lower case and return it.
int | find (const char str, const int start=0) const
| Search substring "str" from symbol at index "start" and return first occur position. More...
int | find (const PIString str, const int start=0) const
| Search substring "str" from symbol at index "start" and return first occur position. More...
int | find (const char *str, const int start=0) const
| Search substring "str" from symbol at index "start" and return first occur position. More...
int | findLast (const char str, const int start=0) const
| Search substring "str" from symbol at index "start" and return last occur position. More...
int | findLast (const PIString str, const int start=0) const
| Search substring "str" from symbol at index "start" and return last occur position. More...
int | findLast (const char *str, const int start=0) const
| Search substring "str" from symbol at index "start" and return last occur position. More...
int | findWord (const PIString &word, const int start=0) const
| Search word "word" from symbol at index "start" and return first occur position. More...
int | findCWord (const PIString &word, const int start=0) const
| Search C-style word "word" from symbol at index "start" and return first occur position. More...
bool | startsWith (const PIString &str) const
| Return if string starts with "str".
bool | endsWith (const PIString &str) const
| Return if string ends with "str".
int | length () const
| Return symbols length of string.
bool | isEmpty () const
| Return `true` if string is empty, i.e. length = 0.
bool | toBool () const
| Return `true` if string equal "true", "yes", "on" or positive not null numeric value.
char | toChar () const
| Return `char` numeric value of string.
short | toShort (int base=-1, bool *ok=0) const
| Return `short` numeric value of string in base "base". More...
ushort | toUShort (int base=-1, bool *ok=0) const
| Return `ushort` numeric value of string in base "base". More...
int | toInt (int base=-1, bool *ok=0) const
| Return `int` numeric value of string in base "base". More...
uint | toUInt (int base=-1, bool *ok=0) const
| Return `uint` numeric value of string in base "base". More...
long | toLong (int base=-1, bool *ok=0) const
| Return `long` numeric value of string in base "base". More...
ulong | toULong (int base=-1, bool *ok=0) const
| Return `ulong` numeric value of string in base "base". More...
llong | toLLong (int base=-1, bool *ok=0) const
| Return `llong` numeric value of string in base "base". More...
ullong | toULLong (int base=-1, bool *ok=0) const
| Return `ullong` numeric value of string in base "base". More...
float | toFloat () const
| Return `float` numeric value of string. More...
double | toDouble () const
| Return `double` numeric value of string. More...
ldouble | toLDouble () const
| Return `ldouble` numeric value of string. More...
PIString & | setNumber (const short value, int base=10, bool *ok=0)
| Set string content to numeric representation of "value" in base "base". More...
PIString & | setNumber (const ushort value, int base=10, bool *ok=0)
| Set string content to numeric representation of "value" in base "base". More...
PIString & | setNumber (const int value, int base=10, bool *ok=0)
| Set string content to numeric representation of "value" in base "base". More...
PIString & | setNumber (const uint value, int base=10, bool *ok=0)
| Set string content to numeric representation of "value" in base "base". More...
PIString & | setNumber (const long value, int base=10, bool *ok=0)
| Set string content to numeric representation of "value" in base "base". More...
PIString & | setNumber (const ulong value, int base=10, bool *ok=0)
| Set string content to numeric representation of "value" in base "base". More...
PIString & | setNumber (const llong &value, int base=10, bool *ok=0)
| Set string content to numeric representation of "value" in base "base". More...
PIString & | setNumber (const ullong &value, int base=10, bool *ok=0)
| Set string content to numeric representation of "value" in base "base". More...
PIString & | setNumber (const float value)
| Set string content to numeric representation of "value". More...
PIString & | setNumber (const double &value)
| Set string content to numeric representation of "value". More...
PIString & | setNumber (const ldouble &value)
| Set string content to numeric representation of "value". More...
PIString & | setReadableSize (llong bytes)
| Set string content to human readable size in B/kB/MB/GB/TB. More...

## Static Public Member Functions

static PIString | fromNumber (const short value, int base=10, bool *ok=0)
| Return string contains numeric representation of "value" in base "base". More...
static PIString | fromNumber (const ushort value, int base=10, bool *ok=0)
| Return string contains numeric representation of "value" in base "base". More...
static PIString | fromNumber (const int value, int base=10, bool *ok=0)
| Return string contains numeric representation of "value" in base "base". More...
static PIString | fromNumber (const uint value, int base=10, bool *ok=0)
| Return string contains numeric representation of "value" in base "base". More...
static PIString | fromNumber (const long value, int base=10, bool *ok=0)
| Return string contains numeric representation of "value" in base "base". More...
static PIString | fromNumber (const ulong value, int base=10, bool *ok=0)
| Return string contains numeric representation of "value" in base "base". More...
static PIString | fromNumber (const llong &value, int base=10, bool *ok=0)
| Return string contains numeric representation of "value" in base "base". More...
static PIString | fromNumber (const ullong &value, int base=10, bool *ok=0)
| Return string contains numeric representation of "value" in base "base". More...
static PIString | fromNumber (const float value)
| Return string contains numeric representation of "value". More...
static PIString | fromNumber (const double &value)
| Return string contains numeric representation of "value". More...
static PIString | fromNumber (const ldouble &value)
| Return string contains numeric representation of "value". More...
static PIString | fromBool (const bool value)
| Return "true" or "false".
static PIString | readableSize (llong bytes)
| Return string contains human readable size in B/kB/MB/GB/TB. More...

## Related Functions

(Note that these are not member functions.)
std::ostream & | operator<< (std::ostream &s, const PIString &v)
| Output operator to std::ostream (cout)
std::istream & | operator>> (std::istream &s, PIString &v)
| Input operator from std::istream (cin)
PIString | operator+ (const PIString &str, const PIString &f)
| Return concatenated string.
PIString | operator+ (const PIString &f, const char *str)
| Return concatenated string.
PIString | operator+ (const PIString &f, const std::string &str)
| Return concatenated string.
PIString | operator+ (const char *str, const PIString &f)
| Return concatenated string.
PIString | operator+ (const std::string &str, const PIString &f)
| Return concatenated string.

## Detailed Description

String class.

PIP use this class for use string information.

# Synopsis

This class based on PIVector to store information. String is a sequence of PIChar and can contain multibyte symbols. Therefore real memory size of string is symbols count * 4. String can be constucted from many types of data and can be converted to many types. There are man operators and handly functions to use string as you wish.

# To/from data convertions

Most common constructor is PIString(const char * str), where "str" is null-terminated string, e.g. `"string"`. This is 7 chars with last char = 0. Also you can constructs PIString from single PIChar, PIByteArray, other PIString or sequency of the same characters with custom length.
This class has implicit conversions to `const char *` and `std::string`. Also there are functions to make same convertions:

- data() - to `const char *` ,
- stdString() - to `std::string`,
- toByteArray() - to PIByteArray.

# Numeric operations

You can get symbolic representation of any numeric value with function setNumber(any integer value, int base = 10, bool * ok = 0). Default arguments are set for decimal base system, but you can choose any system from 2 to 40. There are the same static functions fromNumber(), that returns PIString.
Also there is function setReadableSize() which is set human-readable size in bytes, Kb, Mb, Gb or Pb. Static analog is readableSize().

## Constructor & Destructor Documentation

PIString::PIString | ( | const char * | str | ) |

inline

Contructs string from c-string "str".

"str" should be null-terminated
Example:

PIString s("string");

PIString::PIString | ( | const wchar_t * | str | ) |

inline

Contructs string from `wchar_t` c-string "str".

"str" should be null-terminated
Example:

PIString s(L"string");

PIString::PIString | ( | const char * | str,
|  | const int | len
| ) |  |

inline

Contructs string from "len" characters of buffer "str".

Example:

PIString s("string", 3); // s = "str"

PIString::PIString | ( | const int | len,
|  | const char | c
| ) |  |

inline

Contructs string as sequence of characters "c" of buffer with length "len".

Example:

PIString s(5, 'p'); // s = "ppppp"

PIString::PIString | ( | const int | len,
|  | const PIChar & | c
| ) |  |

inline

Contructs string as sequence of symbols "c" of buffer with length "len".

Example:

PIString s(5, "№"); // s = "№№№№№"

## Member Function Documentation

PIString::operator const char * | ( |  | ) |

inline

Return c-string representation of string.

Converts content of string to c-string and return pointer to first char. This buffer is valid until new convertion or execution data() or toByteArray().
Example:

PIString s("pip");
cout << (char*)s << endl; // pip

PIString& PIString::operator<< | ( | const PIString & | str | ) |

inline

Append string "str" at the end of string.

Example:

PIString s("this"), s1(" is"), s2(" string");
s << s1 << s2; // s = "this is string"

PIString& PIString::operator<< | ( | const PIChar & | c | ) |

inline

Append symbol "c" at the end of string.

Example:

PIString s("stri");
s << PIChar('n') << PIChar('g'); // s = "string"

PIString& PIString::operator<< | ( | const char * | str | ) |

inline

Append c-string "str" at the end of string.

Example:

PIString s("this");
s << " is" << " string"; // s = "this is string"

PIString& PIString::operator<< | ( | const wchar_t * | str | ) |

inline

Append `wchar_t` c-string "str" at the end of string.

Example:

PIString s;
s << L"№ -" << " number"; // s = "№ - number"

PIString& PIString::operator<< | ( | const int & | num | ) |

inline

Append string representation of "num" at the end of string.

Example:

PIString s("ten - ");
s << 10; // s = "ten - 10"

PIString& PIString::operator<< | ( | const short & | num | ) |

inline

Append string representation of "num" at the end of string.

Example:

PIString s("ten - ");
s << 10; // s = "ten - 10"

PIString& PIString::operator<< | ( | const long & | num | ) |

inline

Append string representation of "num" at the end of string.

Example:

PIString s("ten - ");
s << 10; // s = "ten - 10"

PIString& PIString::operator<< | ( | const float & | num | ) |

inline

Append string representation of "num" at the end of string.

Example:

PIString s("ten - ");
s << 10; // s = "ten - 10"

PIString& PIString::operator<< | ( | const double & | num | ) |

inline

Append string representation of "num" at the end of string.

Example:

PIString s("ten - ");
s << 10; // s = "ten - 10"

PIString PIString::mid | ( | const int | start,
|  | const int | len = `-1`
| ) |  | const

Return part of string from symbol at index "start" and maximum length "len".

All variants demonstrated in example:

PIString s("0123456789");
piCout << s.mid(-2, -1); // s = "0123456789"
piCout << s.mid(-2, 4); // s = "01"
piCout << s.mid(3, -1); // s = "3456789"
piCout << s.mid(3, 4); // s = "3456"

See also
  left(), right()

PIString PIString::left | ( | const int | len | ) | const

inline

Return part of string from left and maximum length "len".

Example:

PIString s("0123456789");
piCout << s.left(-1); // s = ""
piCout << s.left(1); // s = "0"
piCout << s.left(5); // s = "01234"
piCout << s.left(15); // s = "0123456789"

See also
  mid(), right()

PIString PIString::right | ( | const int | len | ) | const

inline

Return part of string from right and maximum length "len".

Example:

PIString s("0123456789");
piCout << s.right(-1); // s = ""
piCout << s.right(1); // s = "9"
piCout << s.right(5); // s = "56789"
piCout << s.right(15); // s = "0123456789"

See also
  mid(), left()

PIString & PIString::cutMid | ( | const int | start,
|  | const int | len
| ) |  |

Remove part of string from symbol as index "start" and maximum length "len" and return this string.

All variants demonstrated in example:

PIString s("0123456789");
s.cutMid(1, 3);
piCout << s; // s = "0456789"
s.cutMid(-1, 3);
piCout << s; // s = "56789"
s.cutMid(3, -1);
piCout << s; // s = "567"

See also
  cutLeft(), cutRight()

PIString& PIString::cutLeft | ( | const int | len | ) |

inline

Remove part of string from left and maximum length "len" and return this string.

Example:

PIString s("0123456789");
s.cutLeft(1);
piCout << s; // s = "123456789"
s.cutLeft(3);
piCout << s; // s = "456789"
s.cutLeft(30);
piCout << s; // s = ""

See also
  cutMid(), cutRight()

PIString& PIString::cutRight | ( | const int | len | ) |

inline

Remove part of string from right and maximum length "len" and return this string.

Example:

PIString s("0123456789");
s.cutRight(1);
piCout << s; // s = "012345678"
s.cutRight(3);
piCout << s; // s = "012345"
s.cutRight(30);
piCout << s; // s = ""

See also
  cutMid(), cutLeft()

PIString & PIString::trim | ( |  | ) |

Remove spaces at the start and at the end of string and return this string.

Example:

PIString s(" string ");
s.trim();
piCout << s; // s = "string"

See also
  trimmed()

PIString PIString::trimmed | ( |  | ) | const

Return copy of this string without spaces at the start and at the end.

Example:

PIString s(" string ");
piCout << s.trimmed(); // s = "string"
piCout << s; // s = " string "

See also
  trim()

PIString & PIString::replace | ( | const int | from,
|  | const int | count,
|  | const PIString & | with
| ) |  |

Replace part of string from index "from" and maximum length "len" with string "with" and return this string.

Example:

PIString s("0123456789");
s.replace(2, 3, "_cut_");
piCout << s; // s = "01_cut_56789"
s.replace(0, 1, "one_");
piCout << s; // s = "one_1_cut_56789"

See also
  replaced(), replaceAll()

PIString PIString::replaced | ( | const int | from,
|  | const int | count,
|  | const PIString & | with
| ) |  | const

inline

Replace part copy of this string from index "from" and maximum length "len" with string "with" and return copied string.

Example:

PIString s("0123456789");
piCout << s.replaced(2, 3, "_cut_"); // s = "01_cut_56789"
piCout << s.replaced(0, 1, "one_"); // s = "one_123456789"

See also
  replace(), replaceAll()

PIString & PIString::replace | ( | const PIString & | what,
|  | const PIString & | with,
|  | bool * | ok = `0`
| ) |  |

Replace first founded substring "what" with string "with" and return this string.

If "ok" is not null, it set to "true" if something was replaced
Example:

PIString s("pip string");
bool ok;
s.replace("string", "conf", &ok);
piCout << s << ok; // s = "pip conf", true
s.replace("PIP", "PlInPr", &ok);
piCout << s << ok; // s = "pip conf", false

See also
  replaced(), replaceAll()

PIString PIString::replaced | ( | const PIString & | what,
|  | const PIString & | with,
|  | bool * | ok = `0`
| ) |  | const

inline

Replace first founded substring "what" with string "with" and return copied string.

If "ok" is not null, it set to "true" if something was replaced
Example:

PIString s("pip string");
bool ok;
piCout << s.replace("string", "conf", &ok); // s = "pip conf", true
piCout << s.replace("PIP", "PlInPr", &ok); // s = "pip string", false

See also
  replaced(), replaceAll()

PIString & PIString::replaceAll | ( | const PIString & | what,
|  | const PIString & | with
| ) |  |

Replace all founded substrings "what" with strings "with" and return this string.

Example:

PIString s("substrings");
s.replaceAll("s", "_");
piCout << s; // s = "_ub_tring_"

See also
  replace(), replaced()

PIString& PIString::repeat | ( | int | times | ) |

inline

Repeat content of string "times" times and return this string.

Example:

PIString s(" :-) ");
s.repeat(3);
piCout << s; // :-) :-) :-)

PIString PIString::repeated | ( | int | times | ) | const

inline

Returns repeated "times" times string.

Example:

PIString s(" :-) ");
piCout << s.repeated(3); // :-) :-) :-)
piCout << s; // :-)

PIString& PIString::insert | ( | const int | index,
|  | const PIChar & | c
| ) |  |

inline

Insert symbol "c" after index "index" and return this string.

Example:

PIString s("pp");
s.insert(1, "i");
piCout << s; // s = "pip"

PIString& PIString::insert | ( | const int | index,
|  | const char & | c
| ) |  |

inline

Insert symbol "c" after index "index" and return this string.

Example:

PIString s("pp");
s.insert(1, 'i');
piCout << s; // s = "pip"

PIString & PIString::insert | ( | const int | index,
|  | const PIString & | str
| ) |  |

Insert string "str" after index "index" and return this string.

Example:

PIString s("stg");
s.insert(2, "rin");
piCout << s; // s = "string"

PIString& PIString::insert | ( | const int | index,
|  | const char * | c
| ) |  |

inline

Insert string "str" after index "index" and return this string.

Example:

PIString s("stg");
s.insert(2, "rin");
piCout << s; // s = "string"

PIString& PIString::expandRightTo | ( | const int | len,
|  | const PIChar & | c
| ) |  |

inline

Enlarge string to length "len" by addition sequence of symbols "c" at the end of string, and return this string.

Example:

PIString s("str");
s.expandRightTo(2, "_");
piCout << s; // s = "str"
s.expandRightTo(6, "_");
piCout << s; // s = "str___"

See also
  expandLeftTo()

PIString& PIString::expandLeftTo | ( | const int | len,
|  | const PIChar & | c
| ) |  |

inline

Enlarge string to length "len" by addition sequence of symbols "c" at the beginning of string, and return this string.

Example:

PIString s("str");
s.expandLeftTo(2, "_");
piCout << s; // s = "str"
s.expandLeftTo(6, "_");
piCout << s; // s = "___str"

See also
  expandRightTo()

PIString& PIString::reverse | ( |  | ) |

inline

Reverse string and return this string.

Example:

PIString s("0123456789");
s.reverse();
piCout << s; // s = "9876543210"

See also
  reversed()

PIString PIString::reversed | ( |  | ) | const

inline

Reverse copy of this string and return it.

Example:

PIString s("0123456789");
piCout << s.reversed(); // s = "9876543210"
piCout << s; // s = "0123456789"

See also
  reverse()

PIString PIString::takeMid | ( | const int | start,
|  | const int | len = `-1`
| ) |  |

inline

Take a part of string from symbol at index "start" and maximum length "len" and return it.

Example:

See also
  takeLeft, takeRight()

PIString PIString::takeLeft | ( | const int | len | ) |

inline

Take a part from the begin of string with maximum length "len" and return it.

Example:

See also
  takeMid(), takeRight()

PIString PIString::takeRight | ( | const int | len | ) |

inline

Take a part from the end of string with maximum length "len" and return it.

Example:

See also
  takeMid(), takeLeft()

PIString PIString::takeSymbol | ( |  | ) |

Take a symbol from the begin of this string and return it.

Example:

PIString s("\t ! word");
piCout << s.takeSymbol(); // "!"
piCout << s.takeSymbol(); // "w"
piCout << s.takeSymbol(); // "o"
piCout << s; // "rd"

See also
  takeWord(), takeCWord(), takeLine(), takeNumber(), takeRange()

PIString PIString::takeWord | ( |  | ) |

Take a word from the begin of this string and return it.

Example:

PIString s("some words\nnew line ");
piCout << s.takeWord(); // "some"
piCout << s.takeWord(); // "words"
piCout << s.takeWord(); // "new"
piCout << s; // " line "

See also
  takeSymbol(), takeCWord(), takeLine(), takeNumber(), takeRange()

PIString PIString::takeCWord | ( |  | ) |

Take a word with letters, numbers and '_' symbols from the begin of this string and return it.

Example:

See also
  takeSymbol(), takeWord(), takeLine(), takeNumber(), takeRange()

PIString PIString::takeLine | ( |  | ) |

Take a line from the begin of this string and return it.

Example:

PIString s("some words\nnew line \n\nend");
piCout << s.takeLine(); // "some words"
piCout << s.takeLine(); // "new line "
piCout << s.takeLine(); // ""
piCout << s; // "end"

See also
  takeSymbol(), takeWord(), takeCWord(), takeNumber(), takeRange()

PIString PIString::takeNumber | ( |  | ) |

Take a number with C-format from the begin of this string and return it.

Example:

PIString s(" 0xFF -99 1.2E+5f 1000L");
piCout << s.takeNumber(); // "0xFF"
piCout << s.takeNumber(); // "-99"
piCout << s.takeNumber(); // "1.2E+5f"
piCout << s.takeNumber(); // "1000L"
piCout << s; // ""

See also
  takeSymbol(), takeWord(), takeCWord(), takeLine(), takeRange()

PIString PIString::takeRange | ( | const PIChar & | start,
|  | const PIChar & | end,
|  | const PIChar & | shield = `'\\'`
| ) |  |

Take a range between "start" and "end" symbols from the begin of this string and return it.

"Shield" symbol prevent analysis of the next symbol. Example:

PIString s(" {figures{inside}}");
piCout << s.takeRange('{', '}'); // "figures{inside}"
piCout << s; // ""
s = "\"text\\\"shielded\" next";
piCout << s.takeRange('"', '"'); // "text\"shielded"
piCout << s; // " next"

See also
  takeSymbol(), takeWord(), takeLine(), takeNumber()

int PIString::lengthAscii | ( |  | ) | const

Return real bytes count of this string.

It`s equivalent length of char sequence returned by function data()
Example:

piCout << PIString("0123456789").lengthAscii(); // 10
piCout << PIString("№1").lengthAscii(); // 3

See also
  data()

const char * PIString::data | ( |  | ) | const

Return `char` * representation of this string.

This function fill buffer by sequence of chars. Minimum length of this buffer is count of symbols. Returned `char` * is valid until next execution of this function.
Example:

piCout << PIString("0123456789").data(); // 0123456789
piCout << PIString("№1").data(); // №1

See also
  lengthAscii()

PIStringList PIString::split | ( | const PIString & | delim | ) | const

Split string with delimiter "delim" to PIStringList and return it.

Example:

PIString s("1 2 3");
piCout << s.split(" "); // {"1", "2", "3"}

int PIString::find | ( | const char | str,
|  | const int | start = `0`
| ) |  | const

Search substring "str" from symbol at index "start" and return first occur position.

Example:

PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("3"); // 3
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1

int PIString::find | ( | const PIString | str,
|  | const int | start = `0`
| ) |  | const

Search substring "str" from symbol at index "start" and return first occur position.

Example:

PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("3"); // 3
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1

int PIString::find | ( | const char * | str,
|  | const int | start = `0`
| ) |  | const

inline

Search substring "str" from symbol at index "start" and return first occur position.

Example:

PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("3"); // 3
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1

int PIString::findLast | ( | const char | str,
|  | const int | start = `0`
| ) |  | const

Search substring "str" from symbol at index "start" and return last occur position.

Example:

PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("3"); // 9
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1

int PIString::findLast | ( | const PIString | str,
|  | const int | start = `0`
| ) |  | const

Search substring "str" from symbol at index "start" and return last occur position.

Example:

PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("3"); // 9
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1

int PIString::findLast | ( | const char * | str,
|  | const int | start = `0`
| ) |  | const

inline

Search substring "str" from symbol at index "start" and return last occur position.

Example:

PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("3"); // 9
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1

int PIString::findWord | ( | const PIString & | word,
|  | const int | start = `0`
| ) |  | const

Search word "word" from symbol at index "start" and return first occur position.

Example:

PIString s("this is <PIP>");
piCout << s.find("this"); // 0
piCout << s.find("is"); // 5
piCout << s.find("PIP", 4); // -1
piCout << s.find("<PIP>", 10); // 8

int PIString::findCWord | ( | const PIString & | word,
|  | const int | start = `0`
| ) |  | const

Search C-style word "word" from symbol at index "start" and return first occur position.

Example:

PIString s("this::is <PIP>");
piCout << s.find("this"); // 0
piCout << s.find("is"); // 6
piCout << s.find("PIP", 4); // 10
piCout << s.find("<PIP>", 10); // 9

short PIString::toShort | ( | int | base = `-1`,
|  | bool * | ok = `0`
| ) |  | const

inline

Return `short` numeric value of string in base "base".

Example:

piCout << PIString("123").toInt(); // 123
piCout << PIString("123").toInt(16); // 291
piCout << PIString("0x123").toInt(); // 291
piCout << PIString("1001").toInt(2); // 9

ushort PIString::toUShort | ( | int | base = `-1`,
|  | bool * | ok = `0`
| ) |  | const

inline

Return `ushort` numeric value of string in base "base".

Example:

piCout << PIString("123").toInt(); // 123
piCout << PIString("123").toInt(16); // 291
piCout << PIString("0x123").toInt(); // 291
piCout << PIString("1001").toInt(2); // 9

int PIString::toInt | ( | int | base = `-1`,
|  | bool * | ok = `0`
| ) |  | const

inline

Return `int` numeric value of string in base "base".

Example:

piCout << PIString("123").toInt(); // 123
piCout << PIString("123").toInt(16); // 291
piCout << PIString("0x123").toInt(); // 291
piCout << PIString("1001").toInt(2); // 9

uint PIString::toUInt | ( | int | base = `-1`,
|  | bool * | ok = `0`
| ) |  | const

inline

Return `uint` numeric value of string in base "base".

Example:

piCout << PIString("123").toInt(); // 123
piCout << PIString("123").toInt(16); // 291
piCout << PIString("0x123").toInt(); // 291
piCout << PIString("1001").toInt(2); // 9

long PIString::toLong | ( | int | base = `-1`,
|  | bool * | ok = `0`
| ) |  | const

inline

Return `long` numeric value of string in base "base".

Example:

piCout << PIString("123").toInt(); // 123
piCout << PIString("123").toInt(16); // 291
piCout << PIString("0x123").toInt(); // 291
piCout << PIString("1001").toInt(2); // 9

ulong PIString::toULong | ( | int | base = `-1`,
|  | bool * | ok = `0`
| ) |  | const

inline

Return `ulong` numeric value of string in base "base".

Example:

piCout << PIString("123").toInt(); // 123
piCout << PIString("123").toInt(16); // 291
piCout << PIString("0x123").toInt(); // 291
piCout << PIString("1001").toInt(2); // 9

llong PIString::toLLong | ( | int | base = `-1`,
|  | bool * | ok = `0`
| ) |  | const

inline

Return `llong` numeric value of string in base "base".

Example:

piCout << PIString("123").toInt(); // 123
piCout << PIString("123").toInt(16); // 291
piCout << PIString("0x123").toInt(); // 291
piCout << PIString("1001").toInt(2); // 9

ullong PIString::toULLong | ( | int | base = `-1`,
|  | bool * | ok = `0`
| ) |  | const

inline

Return `ullong` numeric value of string in base "base".

Example:

piCout << PIString("123").toInt(); // 123
piCout << PIString("123").toInt(16); // 291
piCout << PIString("0x123").toInt(); // 291
piCout << PIString("1001").toInt(2); // 9

float PIString::toFloat | ( |  | ) | const

inline

Return `float` numeric value of string.

Example:

piCout << PIString("123").toFloat(); // 123
piCout << PIString("1.2E+2").toFloat(); // 120
piCout << PIString("0.01").toFloat(); // 0.01

double PIString::toDouble | ( |  | ) | const

inline

Return `double` numeric value of string.

Example:

piCout << PIString("123").toFloat(); // 123
piCout << PIString("1.2E+2").toFloat(); // 120
piCout << PIString("0.01").toFloat(); // 0.01

ldouble PIString::toLDouble | ( |  | ) | const

inline

Return `ldouble` numeric value of string.

Example:

piCout << PIString("123").toFloat(); // 123
piCout << PIString("1.2E+2").toFloat(); // 120
piCout << PIString("0.01").toFloat(); // 0.01

PIString& PIString::setNumber | ( | const short | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inline

Set string content to numeric representation of "value" in base "base".

Example:

PIString s;
s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B

PIString& PIString::setNumber | ( | const ushort | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inline

Set string content to numeric representation of "value" in base "base".

Example:

PIString s;
s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B

PIString& PIString::setNumber | ( | const int | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inline

Set string content to numeric representation of "value" in base "base".

Example:

PIString s;
s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B

PIString& PIString::setNumber | ( | const uint | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inline

Set string content to numeric representation of "value" in base "base".

Example:

PIString s;
s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B

PIString& PIString::setNumber | ( | const long | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inline

Set string content to numeric representation of "value" in base "base".

Example:

PIString s;
s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B

PIString& PIString::setNumber | ( | const ulong | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inline

Set string content to numeric representation of "value" in base "base".

Example:

PIString s;
s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B

PIString& PIString::setNumber | ( | const llong & | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inline

Set string content to numeric representation of "value" in base "base".

Example:

PIString s;
s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B

PIString& PIString::setNumber | ( | const ullong & | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inline

Set string content to numeric representation of "value" in base "base".

Example:

PIString s;
s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B

PIString& PIString::setNumber | ( | const float | value | ) |

inline

Set string content to numeric representation of "value".

Example:

PIString s;
s.setNumber(12.3);
piCout << s; // 12.3

PIString& PIString::setNumber | ( | const double & | value | ) |

inline

Set string content to numeric representation of "value".

Example:

PIString s;
s.setNumber(12.3);
piCout << s; // 12.3

PIString& PIString::setNumber | ( | const ldouble & | value | ) |

inline

Set string content to numeric representation of "value".

Example:

PIString s;
s.setNumber(12.3);
piCout << s; // 12.3

PIString & PIString::setReadableSize | ( | llong | bytes | ) |

Set string content to human readable size in B/kB/MB/GB/TB.

Example:

PIString s;
s.setReadableSize(512);
piCout << s; // 512 B
s.setReadableSize(5120);
piCout << s; // 5.0 kB
s.setReadableSize(512000);
piCout << s; // 500.0 kB
s.setReadableSize(5120000);
piCout << s; // 4.8 MB
s.setReadableSize(512000000);
piCout << s; // 488.2 MB
s.setReadableSize(51200000000);
piCout << s; // 47.6 GB

static PIString PIString::fromNumber | ( | const short | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inlinestatic

Return string contains numeric representation of "value" in base "base".

Example:

piCout << PIString::fromNumber(123); // 123
piCout << PIString::fromNumber(123, 16); // 7B

static PIString PIString::fromNumber | ( | const ushort | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inlinestatic

Return string contains numeric representation of "value" in base "base".

Example:

piCout << PIString::fromNumber(123); // 123
piCout << PIString::fromNumber(123, 16); // 7B

static PIString PIString::fromNumber | ( | const int | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inlinestatic

Return string contains numeric representation of "value" in base "base".

Example:

piCout << PIString::fromNumber(123); // 123
piCout << PIString::fromNumber(123, 16); // 7B

static PIString PIString::fromNumber | ( | const uint | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inlinestatic

Return string contains numeric representation of "value" in base "base".

Example:

piCout << PIString::fromNumber(123); // 123
piCout << PIString::fromNumber(123, 16); // 7B

static PIString PIString::fromNumber | ( | const long | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inlinestatic

Return string contains numeric representation of "value" in base "base".

Example:

piCout << PIString::fromNumber(123); // 123
piCout << PIString::fromNumber(123, 16); // 7B

static PIString PIString::fromNumber | ( | const ulong | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inlinestatic

Return string contains numeric representation of "value" in base "base".

Example:

piCout << PIString::fromNumber(123); // 123
piCout << PIString::fromNumber(123, 16); // 7B

static PIString PIString::fromNumber | ( | const llong & | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inlinestatic

Return string contains numeric representation of "value" in base "base".

Example:

piCout << PIString::fromNumber(123); // 123
piCout << PIString::fromNumber(123, 16); // 7B

static PIString PIString::fromNumber | ( | const ullong & | value,
|  | int | base = `10`,
|  | bool * | ok = `0`
| ) |  |

inlinestatic

Return string contains numeric representation of "value" in base "base".

Example:

piCout << PIString::fromNumber(123); // 123
piCout << PIString::fromNumber(123, 16); // 7B

static PIString PIString::fromNumber | ( | const float | value | ) |

inlinestatic

Return string contains numeric representation of "value".

Example:

piCout << PIString::fromNumber(12.3); // 12.3

static PIString PIString::fromNumber | ( | const double & | value | ) |

inlinestatic

Return string contains numeric representation of "value".

Example:

piCout << PIString::fromNumber(12.3); // 12.3

static PIString PIString::fromNumber | ( | const ldouble & | value | ) |

inlinestatic

Return string contains numeric representation of "value".

Example:

piCout << PIString::fromNumber(12.3); // 12.3

static PIString PIString::readableSize | ( | llong | bytes | ) |

inlinestatic

Return string contains human readable size in B/kB/MB/GB/TB.

Example:

piCout << PIString::readableSize(512); // 512 B
piCout << PIString::readableSize(5120); // 5.0 kB
piCout << PIString::readableSize(512000); // 500.0 kB
piCout << PIString::readableSize(5120000); // 4.8 MB
piCout << PIString::readableSize(512000000); // 488.2 MB
piCout << PIString::readableSize(51200000000); // 47.6 GB