PIP 1.7.1 Platform-Independent Primitives

Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
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 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...
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 PIString &str) const
| Compare operator.
bool | operator!= (const PIChar c) const
| Compare operator.
bool | operator!= (const char *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 PIString &str) const
| Compare operator.
bool | operator> (const PIChar c) const
| Compare operator.
bool | operator> (const char *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 PIString &str) const
| Compare operator.
bool | operator>= (const PIChar c) const
| Compare operator.
bool | operator>= (const char *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 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...
PIString | inBrackets (const PIChar &start, const PIChar &end) const
| Return a string in brackets "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 in system codepage. More...
const char * | dataConsole () const
| Return `char` * representation of this string in terminal codepage. More...
const char * | dataUTF8 () const
| Return `char` * representation of this string in UTF-8. More...
const char * | dataAscii () const
| Return `char` * representation of this string in ASCII. More...
PIByteArray | toByteArray () const
| Return PIByteArray contains data() of this string without terminating null-char.
PIByteArray | toUTF8 () const
| Return PIByteArray contains UTF-8 data() of this string without terminating null-char.
PIByteArray | toCharset (const char *c) const
| Return PIByteArray contains custom charset representation of this string without terminating null-char.
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.
bool | contains (const char str) const
| Returns if string contains "str".
bool | contains (const PIChar str) const
| Returns if string contains "str".
bool | contains (const char *str) const
| Returns if string contains "str".
bool | contains (const PIString &str) const
| Returns if string contains "str".
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...
int | findRange (const PIChar &start, const PIChar &end, const PIChar &shield='\\', const int start_index=0, int *len=0) const
| Search range between "start" and "end" symbols at index "start_index" 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, char format='f', int precision=8)
| Set string content to numeric representation of "value". More...
PIString & | setNumber (const double &value, char format='f', int precision=8)
| Set string content to numeric representation of "value". More...
PIString & | setNumber (const ldouble &value, char format='f', int precision=8)
| 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, char format='f', int precision=8)
| Return string contains numeric representation of "value". More...
static PIString | fromNumber (const double &value, char format='f', int precision=8)
| Return string contains numeric representation of "value". More...
static PIString | fromNumber (const ldouble &value, char format='f', int precision=8)
| Return string contains numeric representation of "value". More...
static PIString | fromBool (const bool value)
| Return "true" or "false".
static PIString | fromConsole (const char *s)
| Return string constructed from terminal codepage.
static PIString | fromSystem (const char *s)
| Return string constructed from system codepage.
static PIString | fromUTF8 (const char *s)
| Return string constructed from UTF-8.
static PIString | fromUTF8 (const PIByteArray &ba)
| Return string constructed from UTF-8.
static PIString | fromAscii (const char *s)
| Return string constructed from ASCII.
static PIString | fromCodepage (const char *s, const char *c)
| Return string constructed from "c" codepage.
static PIString | readableSize (llong bytes)
| Return string contains human readable size in B/kB/MB/GB/TB. More...

## Friends
PIByteArray & | operator>> (PIByteArray &s, PIString &v)
| Input operator from PIByteArray.

## Related Functions
(Note that these are not member functions.)
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 char *str, const PIString &f)
| Return concatenated string.
PIString | operator+ (const PIString &f, const std::string &str)
| Return concatenated string.
PIString | operator+ (const std::string &str, const PIString &f)
| Return concatenated string.
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)

## 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() [1/5]

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

Contructs string from c-string "str".

"str" should be null-terminated
Example:

PIString s("string");

## ◆ PIString() [2/5]

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() [3/5]

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() [4/5]

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() [5/5]

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

## ◆ operator const char *()

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

## ◆ operator<<() [1/9]

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"

## ◆ operator<<() [2/9]

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"

## ◆ operator<<() [3/9]

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"

## ◆ operator<<() [4/9]

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"

## ◆ operator<<() [5/9]

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"

## ◆ operator<<() [6/9]

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"

## ◆ operator<<() [7/9]

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"

## ◆ operator<<() [8/9]

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"

## ◆ operator<<() [9/9]

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"

## ◆ mid()

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()

## ◆ left()

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()

## ◆ 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()

## ◆ cutMid()

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()

## ◆ cutLeft()

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()

## ◆ 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()

## ◆ trim()

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()

## ◆ 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()

## ◆ replace() [1/2]

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()

## ◆ replaced() [1/2]

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()

## ◆ replace() [2/2]

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()

## ◆ replaced() [2/2]

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()

## ◆ 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()

## ◆ repeat()

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

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

Example:

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

## ◆ repeated()

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

Returns repeated "times" times string.

Example:

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

## ◆ insert() [1/4]

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"

## ◆ insert() [2/4]

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"

## ◆ insert() [3/4]

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"

## ◆ insert() [4/4]

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"

## ◆ expandRightTo()

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()

## ◆ 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()

## ◆ reverse()

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

Reverse string and return this string.

Example:

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

See also
  reversed()

## ◆ 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()

## ◆ takeMid()

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()

## ◆ takeLeft()

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()

## ◆ 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()

## ◆ takeSymbol()

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()

## ◆ takeWord()

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()

## ◆ takeCWord()

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()

## ◆ takeLine()

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()

## ◆ takeNumber()

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()

## ◆ 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()

## ◆ inBrackets()

PIString PIString::inBrackets | ( | const PIChar & | start,
|  | const PIChar & | end
| ) |  | const

Return a string in brackets "start" and "end" symbols from the begin of this string and return it.

Example: string = "a(b(c)d)e"; inBrackets('(', ')') = "b(c)d";

## ◆ lengthAscii()

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

Return real bytes count of this string.

It`s equivalent length of char sequence returned by function data() - 1, without terminating null-char
Example:

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

See also
  data()

## ◆ data()

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

Return `char` * representation of this string in system codepage.

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
  dataConsole(), dataUTF8()

## ◆ dataConsole()

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

Return `char` * representation of this string in terminal codepage.

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.

See also
  data(), dataUTF8()

## ◆ dataUTF8()

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

Return `char` * representation of this string in UTF-8.

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.

See also
  data(), dataConsole()

## ◆ dataAscii()

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

Return `char` * representation of this string in ASCII.

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.

## ◆ split()

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"}

## ◆ find() [1/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

## ◆ find() [2/3]

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

## ◆ find() [3/3]

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

## ◆ findLast() [1/3]

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

## ◆ findLast() [2/3]

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

## ◆ findLast() [3/3]

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

## ◆ findWord()

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

## ◆ findCWord()

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

## ◆ findRange()

int PIString::findRange | ( | const PIChar & | start,
|  | const PIChar & | end,
|  | const PIChar & | shield = `'\\'`,
|  | const int | start_index = `0`,
|  | int * | len = `0`
| ) |  | const

Search range between "start" and "end" symbols at index "start_index" and return first occur position.

Example:

## ◆ toShort()

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

## ◆ toUShort()

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

## ◆ toInt()

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

## ◆ toUInt()

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

## ◆ toLong()

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

## ◆ toULong()

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

## ◆ toLLong()

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

## ◆ toULLong()

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

## ◆ toFloat()

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

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

## ◆ toDouble()

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

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

## ◆ toLDouble()

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

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

## ◆ setNumber() [1/11]

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

## ◆ setNumber() [2/11]

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

## ◆ setNumber() [3/11]

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

## ◆ setNumber() [4/11]

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

## ◆ setNumber() [5/11]

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

## ◆ setNumber() [6/11]

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

## ◆ setNumber() [7/11]

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

## ◆ setNumber() [8/11]

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

## ◆ setNumber() [9/11]

PIString& PIString::setNumber | ( | const float | value,
|  | char | format = `'f'`,
|  | int | precision = `8`
| ) |  |
| inline

Set string content to numeric representation of "value".

Example:

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

## ◆ setNumber() [10/11]

PIString& PIString::setNumber | ( | const double & | value,
|  | char | format = `'f'`,
|  | int | precision = `8`
| ) |  |
| inline

Set string content to numeric representation of "value".

Example:

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

## ◆ setNumber() [11/11]

PIString& PIString::setNumber | ( | const ldouble & | value,
|  | char | format = `'f'`,
|  | int | precision = `8`
| ) |  |
| inline

Set string content to numeric representation of "value".

Example:

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

## ◆ setReadableSize()

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

## ◆ fromNumber() [1/11]

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

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

Example:

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

## ◆ fromNumber() [2/11]

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

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

Example:

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

## ◆ fromNumber() [3/11]

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

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

Example:

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

## ◆ fromNumber() [4/11]

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

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

Example:

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

## ◆ fromNumber() [5/11]

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

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

Example:

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

## ◆ fromNumber() [6/11]

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

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

Example:

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

## ◆ fromNumber() [7/11]

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

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

Example:

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

## ◆ fromNumber() [8/11]

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

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

Example:

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

## ◆ fromNumber() [9/11]

static PIString PIString::fromNumber | ( | const float | value,
|  | char | format = `'f'`,
|  | int | precision = `8`
| ) |  |
| inline static

Return string contains numeric representation of "value".

Example:

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

## ◆ fromNumber() [10/11]

static PIString PIString::fromNumber | ( | const double & | value,
|  | char | format = `'f'`,
|  | int | precision = `8`
| ) |  |
| inline static

Return string contains numeric representation of "value".

Example:

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

## ◆ fromNumber() [11/11]

static PIString PIString::fromNumber | ( | const ldouble & | value,
|  | char | format = `'f'`,
|  | int | precision = `8`
| ) |  |
| inline static

Return string contains numeric representation of "value".

Example:

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

## ◆ readableSize()

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

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