PIP 5.5.3
Platform-Independent Primitives
Public Member Functions | Static Public Member Functions | Static Public Attributes | Related Functions | List of all members
PIString Class Reference

String class. More...

#include <pistring.h>

Public Member Functions

 PIString ()
 Contructs an empty string.
 
 PIString (const PIString &o)
 Contructs a copy of string.
 
 PIString (PIString &&o)
 Move constructor.
 
 PIString (const PIChar c)
 Contructs string with single character "c".
 
 PIString (const char c)
 Contructs string with single character "c".
 
 PIString (const char *str)
 Contructs string from C-string "str" (system codepage). More...
 
 PIString (const wchar_t *str)
 Contructs string from wchar_t C-string "str". More...
 
 PIString (const char16_t *str)
 Contructs string from char16_t C-string "str". More...
 
 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" (system codepage). 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 characters "c" of buffer with length "len". More...
 
PIStringoperator= (const PIString &o)
 Assign operator.
 
PIStringoperator= (PIString &&o)
 Assign move operator.
 
PIStringoperator= (const PIConstChars &o)
 Assign operator.
 
PIStringoperator= (const char *o)
 Assign operator.
 
PIStringoperator= (const char16_t *o)
 Assign 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.
 
bool operator>= (const PIString &str) const
 Compare operator.
 
bool operator>= (const PIChar c) const
 Compare operator.
 
bool operator>= (const char *str) const
 Compare operator.
 
iterator begin ()
 Iterator to the first element. More...
 
iterator end ()
 Iterator to the element following the last element. More...
 
reverse_iterator rbegin ()
 Returns a reverse iterator to the first element of the reversed array. More...
 
reverse_iterator rend ()
 Returns a reverse iterator to the element. following the last element of the reversed array. More...
 
PICharoperator[] (size_t index)
 Full access to character by index. More...
 
const PIChar at (size_t index) const
 Read only access to character by index. More...
 
PICharback ()
 Returns the last character of the string.
 
PIStringresize (size_t new_size, PIChar c=PIChar())
 Sets size of the string, new characters are copied from c. More...
 
PIStringpop_back ()
 Delete one character at the end of string.
 
PIStringpop_front ()
 Delete one character at the benig of string.
 
PIStringremove (size_t index, size_t count=1)
 Removes count characters from the string, starting at index position.
 
PIStringfill (PIChar c=PIChar())
 Assigns character 'c' to all string characters.
 
PIStringprepend (const char *str)
 Insert string "str" at the begin of string.
 
PIStringprepend (const PIString &str)
 Insert string "str" at the begin of string.
 
PIStringprepend (const PIChar c)
 Insert character c at the begin of string.
 
PIStringprepend (const char c)
 Insert character c at the begin of string.
 
PIStringpush_front (const char *str)
 Insert string "str" at the begin of string.
 
PIStringpush_front (const char16_t *str)
 Insert string "str" at the begin of string.
 
PIStringpush_front (const PIString &str)
 Insert string "str" at the begin of string.
 
PIStringpush_front (const PIChar c)
 Insert character c at the begin of string.
 
PIStringpush_front (const char c)
 Insert character c at the begin of string.
 
PIStringappend (const char *str)
 Insert string "str" at the end of string.
 
PIStringappend (const char16_t *str)
 Insert string "str" at the end of string.
 
PIStringappend (const PIString &str)
 Insert string "str" at the end of string.
 
PIStringappend (const PIChar c)
 Insert character c at the end of string.
 
PIStringappend (const char c)
 Insert character c at the end of string.
 
PIStringpush_back (const char *str)
 Insert string "str" at the end of string.
 
PIStringpush_back (const PIString &str)
 Insert string "str" at the end of string.
 
PIStringpush_back (const PIChar c)
 Insert character c at the end of string.
 
PIStringpush_back (const char c)
 Insert character c at the end of string.
 
PIString mid (int start, int len=-1) const
 Returns part of string from character at index "start" and maximum length "len". More...
 
PIString subString (int start, int len=-1) const
 Synonym of mid().
 
PIString left (int len) const
 Returns part of string from start and maximum length "len". More...
 
PIString right (int len) const
 Returns part of string at end and maximum length "len". More...
 
PIStringcutMid (int start, int len)
 Remove part of string from character as index "start" and maximum length "len" and return this string. More...
 
PIStringcutLeft (int len)
 Remove part of string from start and maximum length "len" and return this string. More...
 
PIStringcutRight (int len)
 Remove part of string at end and maximum length "len" and return this string. More...
 
PIStringtrim ()
 Remove spaces at the start and at the end of string and return this string. More...
 
PIString trimmed () const
 Returns copy of this string without spaces at the start and at the end. More...
 
PIStringreplace (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". More...
 
PIStringreplace (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 in string copy first founded substring "what" with string "with". More...
 
PIStringreplaceAll (const PIString &what, const PIString &with)
 Replace all founded substrings "what" with strings "with" and return this string. More...
 
PIStringreplaceAll (const PIString &what, const char with)
 Replace all founded substrings "what" with characters "with" and return this string. More...
 
PIStringreplaceAll (const char what, const char with)
 Replace all founded characters "what" with characters "with" and return this string. More...
 
PIString replacedAll (const PIString &what, const PIString &with) const
 Replace all founded substrings "what" with strings "with" in string copy. More...
 
PIString replacedAll (const PIString &what, const char with) const
 Replace all founded substrings "what" with characters "with" in string copy. More...
 
PIString replacedAll (const char what, const char with) const
 Replace all founded characters "what" with characters "with" in string copy. More...
 
PIStringremoveAll (const PIString &str)
 Remove all founded substrings "what" and return this string.
 
PIStringremoveAll (char c)
 Remove all founded characters "what" and return this string.
 
PIStringrepeat (int times)
 Repeat content of string "times" times and return this string. More...
 
PIString repeated (int times) const
 Returns repeated "times" times string. More...
 
PIStringinsert (const int index, const PIChar c)
 Insert character "c" after index "index" and return this string. More...
 
PIStringinsert (const int index, const char c)
 Insert character "c" after index "index" and return this string. More...
 
PIStringinsert (const int index, const PIString &str)
 Insert string "str" after index "index" and return this string. More...
 
PIStringinsert (const int index, const char *c)
 Insert string "str" after index "index" and return this string. More...
 
PIStringinsert (const int index, const char16_t *c)
 Insert string "str" after index "index" and return this string. More...
 
PIStringexpandRightTo (const int len, const PIChar c)
 Enlarge string to length "len" by addition characters "c" at the end, and return this string. More...
 
PIStringexpandLeftTo (const int len, const PIChar c)
 Enlarge string to length "len" by addition characters "c" at the begin, and return this string. More...
 
PIString expandedRightTo (const int len, const PIChar c) const
 Enlarge copy of this string to length "len" by addition characters "c" at the end. More...
 
PIString expandedLeftTo (const int len, const PIChar c) const
 Enlarge copy of this string to length "len" by addition characters "c" at the begin. More...
 
PIStringquote (PIChar c=PIChar('"'))
 Add "c" characters at the beginning and end, and return this string. More...
 
PIString quoted (PIChar c=PIChar('"'))
 Returns quoted copy of this string. More...
 
PIStringreverse ()
 Reverse string and return this string. More...
 
PIString reversed () const
 Reverse copy of this string. More...
 
PIStringelide (int size, float pos=ElideCenter)
 Fit string to maximum size "size" by inserting ".." at position "pos" and return this string. More...
 
PIString elided (int size, float pos=ElideCenter) const
 Fit copy of this string to maximum size "size" by inserting ".." at position "pos". More...
 
PIString takeMid (const int start, const int len=-1)
 Take a part of string from character 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 character 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 '_' characters 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 takeInteger ()
 Take a digits from the begin of this string and return it.
 
PIString takeRange (const PIChar start, const PIChar end, const PIChar shield='\\')
 Take a range between "start" and "end" characters from the begin of this string and return it. More...
 
PIString inBrackets (const PIChar start, const PIChar end) const
 Returns string in brackets "start" and "end" characters from the beginning. More...
 
const char * data () const
 Returns char * representation of this string in system codepage. More...
 
const char * dataConsole () const
 Returns char * representation of this string in terminal codepage. More...
 
const char * dataUTF8 () const
 Returns char * representation of this string in UTF-8. More...
 
const char * dataAscii () const
 Returns char * representation of this string in ASCII. More...
 
const size_t lastDataSize () const
 Returns data size of last data*() call.
 
uint hash () const
 Returns hash of string.
 
PIByteArray toByteArray () const
 Same as toUTF8().
 
PIByteArray toAscii () const
 Returns PIByteArray contains dataAscii() of this string without terminating null-char.
 
PIByteArray toSystem () const
 Returns PIByteArray contains data() of this string without terminating null-char.
 
PIByteArray toUTF8 () const
 Returns PIByteArray contains dataUTF8() of this string without terminating null-char.
 
PIByteArray toCharset (const char *c) const
 Returns PIByteArray contains custom charset representation of this string without terminating null-char.
 
PIString simplified () const
 Returns PIString with non-ASCII symbols replaced with '?'.
 
PIStringmask (const PIString &symbols, const PIChar mc='\\')
 Insert before any symbol from "symbols" symbol "mc" and return this string.
 
PIStringunmask (const PIString &symbols, const PIChar mc='\\')
 Remove symbol "mc" before any symbol from "symbols" and return this string.
 
PIStringList split (const PIString &delim) const
 Split string with delimiter "delim" to PIStringList. More...
 
PIString toUpperCase () const
 Convert each character in copied string to upper case.
 
PIString toLowerCase () const
 Convert each character in copied string to lower case.
 
bool contains (const char c) const
 Returns if string contains character "c".
 
bool contains (const PIChar c) const
 Returns if string contains character "c".
 
bool contains (const char *str) const
 Returns if string contains substring "str".
 
bool contains (const PIString &str) const
 Returns if string contains substring "str".
 
bool contains (const PIRegularExpression &regexp) const
 Returns if string match "regexp".
 
int find (const char c, const int start=0) const
 Search character "c" from character at index "start" and return first occur position. More...
 
int find (PIChar c, const int start=0) const
 Search character "c" from character at index "start" and return first occur position.
 
int find (const PIString &str, const int start=0) const
 Search substring "str" from character at index "start" and return first occur position. More...
 
int find (const char *str, const int start=0) const
 Search substring "str" from character at index "start" and return first occur position. More...
 
int find (const PIRegularExpression &regexp, const int start=0) const
 Search match of "regexp" from character at index "start" and return first occur position.
 
int findAny (const PIString &str, const int start=0) const
 Search any character of "str" from character at index "start" and return first occur position. More...
 
int findAny (const char *str, const int start=0) const
 Search any character of "str" from character at index "start" and return first occur position. More...
 
int findLast (const char c, const int start=0) const
 Search character "c" from character at index "start" and return last occur position. More...
 
int findLast (PIChar c, const int start=0) const
 Search character "c" from character at index "start" and return last occur position.
 
int findLast (const PIString &str, const int start=0) const
 Search substring "str" from character at index "start" and return last occur position. More...
 
int findLast (const char *str, const int start=0) const
 Search substring "str" from character at index "start" and return last occur position. More...
 
int findLast (const PIRegularExpression &regexp, const int start=0) const
 Search match of "regexp" from character at index "start" and return last occur position.
 
int findAnyLast (const PIString &str, const int start=0) const
 Search any character of "str" from character at index "start" and return last occur position. More...
 
int findAnyLast (const char *str, const int start=0) const
 Search any character of "str" from character at index "start" and return last occur position. More...
 
int findWord (const PIString &word, const int start=0) const
 Search word "word" from character at index "start" and return first occur position. More...
 
int findCWord (const PIString &word, const int start=0) const
 Search C-word "word" from character 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 start between "start" and "end" characters at index "start_index" and return first occur position. More...
 
int entries (const PIChar c) const
 Returns number of occurrences of character "c". More...
 
int entries (const PIString &str) const
 Returns number of occurrences of string "str". More...
 
int lineNumber (int pos) const
 Returns line number of position "pos". Lines starts from 1.
 
bool startsWith (const char c) const
 Returns if string starts with "c".
 
bool startsWith (const PIChar c) const
 Returns if string starts with "c".
 
bool startsWith (const PIString &str) const
 Returns if string starts with "str".
 
bool endsWith (const char c) const
 Returns if string ends with "c".
 
bool endsWith (const PIChar c) const
 Returns if string ends with "c".
 
bool endsWith (const PIString &str) const
 Returns if string ends with "str".
 
int length () const
 Returns characters length of string.
 
size_t size () const
 Returns characters length of string.
 
ssize_t size_s () const
 Returns characters length of string.
 
bool isEmpty () const
 Returns true if string is empty, i.e. length = 0.
 
bool isNotEmpty () const
 Returns true if string is not empty, i.e. length > 0.
 
void clear ()
 Clear string, will be empty string. More...
 
bool toBool () const
 Returns true if string equal "true", "yes", "on" or positive not null numeric value. More...
 
char toChar () const
 Returns char numeric value of string.
 
short toShort (int base=-1, bool *ok=0) const
 Returns short numeric value of string in base "base". More...
 
ushort toUShort (int base=-1, bool *ok=0) const
 Returns ushort numeric value of string in base "base". More...
 
int toInt (int base=-1, bool *ok=0) const
 Returns int numeric value of string in base "base". More...
 
uint toUInt (int base=-1, bool *ok=0) const
 Returns uint numeric value of string in base "base". More...
 
long toLong (int base=-1, bool *ok=0) const
 Returns long numeric value of string in base "base". More...
 
ulong toULong (int base=-1, bool *ok=0) const
 Returns ulong numeric value of string in base "base". More...
 
llong toLLong (int base=-1, bool *ok=0) const
 Returns llong numeric value of string in base "base". More...
 
ullong toULLong (int base=-1, bool *ok=0) const
 Returns ullong numeric value of string in base "base". More...
 
float toFloat () const
 Returns float numeric value of string. More...
 
double toDouble () const
 Returns double numeric value of string. More...
 
ldouble toLDouble () const
 Returns ldouble numeric value of string. More...
 
PIStringsetNumber (const short value, int base=10, bool *ok=0)
 Set string content to text representation of "value" in base "base" and return this string. More...
 
PIStringsetNumber (const ushort value, int base=10, bool *ok=0)
 Set string content to text representation of "value" in base "base" and return this string. More...
 
PIStringsetNumber (const int value, int base=10, bool *ok=0)
 Set string content to text representation of "value" in base "base" and return this string. More...
 
PIStringsetNumber (const uint value, int base=10, bool *ok=0)
 Set string content to text representation of "value" in base "base" and return this string. More...
 
PIStringsetNumber (const long value, int base=10, bool *ok=0)
 Set string content to text representation of "value" in base "base" and return this string. More...
 
PIStringsetNumber (const ulong value, int base=10, bool *ok=0)
 Set string content to text representation of "value" in base "base" and return this string. More...
 
PIStringsetNumber (const llong &value, int base=10, bool *ok=0)
 Set string content to text representation of "value" in base "base" and return this string. More...
 
PIStringsetNumber (const ullong &value, int base=10, bool *ok=0)
 Set string content to text representation of "value" in base "base" and return this string. More...
 
PIStringsetNumber (const float value, char format='f', int precision=8)
 Set string content to text representation of "value" with format "format" and precision "precision" and return this string. More...
 
PIStringsetNumber (const double &value, char format='f', int precision=8)
 Set string content to text representation of "value" with format "format" and precision "precision" and return this string. More...
 
PIStringsetNumber (const ldouble &value, char format='f', int precision=8)
 Set string content to text representation of "value" with format "format" and precision "precision" and return this string. More...
 
PIStringsetReadableSize (llong bytes)
 Set string content to human readable size in B/KiB/MiB/GiB/TiB/PiB. More...
 
PIString toPercentageEncoding () const
 Returns percentage-encoded string.
 
PIStringarg (const PIString &v)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string. More...
 
PIStringarg (short v, int base=10)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
 
PIStringarg (ushort v, int base=10)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
 
PIStringarg (int v, int base=10)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string. More...
 
PIStringarg (uint v, int base=10)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
 
PIStringarg (long v, int base=10)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
 
PIStringarg (ulong v, int base=10)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
 
PIStringarg (llong v, int base=10)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
 
PIStringarg (ullong v, int base=10)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
 
PIStringarg (float v, char format='f', int precision=8)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
 
PIStringarg (double v, char format='f', int precision=8)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string. More...
 
PIStringarg (ldouble v, char format='f', int precision=8)
 Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
 
void swap (PIString &str)
 Swaps string str other with this string. More...
 

Static Public Member Functions

static PIString fromNumber (const short value, int base=10, bool *ok=0)
 Returns string contains numeric representation of "value" in base "base". More...
 
static PIString fromNumber (const ushort value, int base=10, bool *ok=0)
 Returns string contains numeric representation of "value" in base "base". More...
 
static PIString fromNumber (const int value, int base=10, bool *ok=0)
 Returns string contains numeric representation of "value" in base "base". More...
 
static PIString fromNumber (const uint value, int base=10, bool *ok=0)
 Returns string contains numeric representation of "value" in base "base". More...
 
static PIString fromNumber (const long value, int base=10, bool *ok=0)
 Returns string contains numeric representation of "value" in base "base". More...
 
static PIString fromNumber (const ulong value, int base=10, bool *ok=0)
 Returns string contains numeric representation of "value" in base "base". More...
 
static PIString fromNumber (const llong &value, int base=10, bool *ok=0)
 Returns string contains numeric representation of "value" in base "base". More...
 
static PIString fromNumber (const ullong &value, int base=10, bool *ok=0)
 Returns string contains numeric representation of "value" in base "base". More...
 
static PIString fromNumber (const float value, char format='f', int precision=8)
 Returns string contains numeric representation of "value" with format "format" and precision "precision". More...
 
static PIString fromNumber (const double &value, char format='f', int precision=8)
 Returns string contains numeric representation of "value" with format "format" and precision "precision". More...
 
static PIString fromNumber (const ldouble &value, char format='f', int precision=8)
 Returns string contains numeric representation of "value" with format "format" and precision "precision". More...
 
static PIString fromBool (const bool value)
 Returns "true" or "false".
 
static PIString fromConsole (const PIByteArray &s)
 Returns string constructed from terminal codepage.
 
static PIString fromConsole (const char *s)
 Returns string constructed from terminal codepage.
 
static PIString fromSystem (const PIByteArray &s)
 Returns string constructed from system codepage.
 
static PIString fromSystem (const char *s)
 Returns string constructed from system codepage.
 
static PIString fromUTF8 (const char *s, int l=-1)
 Returns string constructed from UTF-8.
 
static PIString fromUTF8 (const PIByteArray &utf)
 Returns string constructed from UTF-8.
 
static PIString fromAscii (const char *s)
 Returns string constructed from ASCII.
 
static PIString fromAscii (const char *s, int len)
 Returns string constructed from "len" chars ASCII.
 
static PIString fromAscii (const PIByteArray &ascii)
 Returns string constructed from ASCII.
 
static PIString fromCodepage (const char *s, const char *cp)
 Returns string constructed from "cp" codepage.
 
static PIString readableSize (llong bytes)
 Returns string contains human readable size in B/KiB/MiB/GiB/TiB/PiB. More...
 
static PIString fromPercentageEncoding (const PIString &in)
 Returns string from percentage-encoded "in".
 

Static Public Attributes

static const float ElideLeft = 0.f
 Value for elide at left.
 
static const float ElideCenter = .5f
 Value for elide at center.
 
static const float ElideRight = 1.f
 Value for elide at right.
 

Related Functions

(Note that these are not member functions.)

int versionCompare (const PIString &v0, const PIString &v1, int components)
 Compare two version strings in free notation and returns 0, -1 or 1. More...
 
PIString versionNormalize (const PIString &v)
 Converts version string in free notation to classic view. More...
 
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.

Synopsis

String is a sequence of PIChar. Real memory size of string is symbols count * 2. String can be constucted from many types of data and can be converted to many types. There are many operators and handly functions to use string as you wish.

Constructor & Destructor Documentation

◆ PIString() [1/6]

PIString::PIString ( const char *  str)
inline

Contructs string from C-string "str" (system codepage).

"str" should be null-terminated

PIString s("string");
String class.
Definition: pistring.h:42

◆ PIString() [2/6]

PIString::PIString ( const wchar_t *  str)
inline

Contructs string from wchar_t C-string "str".

"str" should be null-terminated

PIString s(L"string");

◆ PIString() [3/6]

PIString::PIString ( const char16_t *  str)
inline

Contructs string from char16_t C-string "str".

"str" should be null-terminated

PIString s(u"string");

◆ PIString() [4/6]

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

Contructs string from "len" characters of buffer "str" (system codepage).

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

◆ PIString() [5/6]

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

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

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

◆ PIString() [6/6]

PIString::PIString ( const int  len,
const PIChar  c 
)
inline

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

PIString s(5, "â„–"); // s = "â„–â„–â„–â„–â„–"

Member Function Documentation

◆ begin()

iterator PIString::begin ( )
inline

Iterator to the first element.

Returns
STL-Style Iterators
See also
end(), rbegin(), rend()

◆ end()

iterator PIString::end ( )
inline

Iterator to the element following the last element.

Returns
STL-Style Iterators
See also
begin(), rbegin(), rend()

◆ rbegin()

reverse_iterator PIString::rbegin ( )
inline

Returns a reverse iterator to the first element of the reversed array.

It corresponds to the last element of the non-reversed array.

Returns
STL-Style Iterators
See also
rend(), begin(), end()

◆ rend()

reverse_iterator PIString::rend ( )
inline

Returns a reverse iterator to the element. following the last element of the reversed array.

It corresponds to the element preceding the first element of the non-reversed array.

Returns
STL-Style Iterators
See also
rbegin(), begin(), end()

◆ operator[]()

PIChar & PIString::operator[] ( size_t  index)
inline

Full access to character by index.

Сharacter index starts from 0. Сharacter index must be in range from 0 to size()-1. Otherwise will be undefined behavior.

◆ at()

const PIChar PIString::at ( size_t  index) const
inline

Read only access to character by index.

Сharacter index starts from 0. Сharacter index must be in range from 0 to size()-1. Otherwise will be undefined behavior.

◆ resize()

PIString & PIString::resize ( size_t  new_size,
PIChar  c = PIChar() 
)
inline

Sets size of the string, new characters are copied from c.

If new_size is greater than the current size(), characters are added to the end; the new characters are initialized from c. If new_size is less than the current size(), characters are removed from the end.

See also
size(), clear()

◆ mid()

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

Returns part of string from character at index "start" and maximum length "len".

If "len" < 0 then returns substring from symbol "start" to end. "start" should be >= 0.

PIString s("0123456789");
piCout << s.mid(0, -1); // s = "0123456789"
piCout << s.mid(0, 2); // s = "01"
piCout << s.mid(3); // s = "3456789"
piCout << s.mid(3, 4); // s = "3456"
piCout << s.mid(7, 1); // s = "7"
piCout << s.mid(7, 4); // s = "789"
piCout << s.mid(-1); // s = ""
#define piCout
Macro used for conditional (piDebug) output to PICout(StdOut)
Definition: picout.h:35
See also
left(), right()

◆ left()

PIString PIString::left ( int  len) const
inline

Returns part of string from start and maximum length "len".

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 ( int  len) const
inline

Returns part of string at end and maximum length "len".

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 ( int  start,
int  len 
)

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

If "len" < 0 then remove substring from symbol "start" to end. "start" should be >= 0.

PIString s("0123456789");
s.cutMid(1, 3);
piCout << s; // s = "0456789"
s.cutMid(0, 2);
piCout << s; // s = "56789"
s.cutMid(3, -1);
piCout << s; // s = "567"
s.cutMid(-1, -1);
piCout << s; // s = "567"
See also
cutLeft(), cutRight()

◆ cutLeft()

PIString & PIString::cutLeft ( int  len)
inline

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

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 ( int  len)
inline

Remove part of string at end and maximum length "len" and return this string.

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.

Remove spaces, tabulations, line feeds and null symbols: ' ', '\n', '\r', '\t', '\0'

PIString s(" \t string \n");
s.trim();
piCout << s; // s = "string"
See also
trimmed()

◆ trimmed()

PIString PIString::trimmed ( ) const

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

PIString s(" \t string \n");
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.

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

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

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 in string copy first founded substring "what" with string "with".

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

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

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

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

PIString s("substrings");
s.replaceAll("s", "_");
piCout << s; // s = "_ub_tring_"
See also
replace(), replaced(), replacedAll()

◆ replaceAll() [2/3]

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

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

PIString s("substrings");
s.replaceAll("s", '_');
piCout << s; // s = "_ub_tring_"
See also
replace(), replaced(), replacedAll()

◆ replaceAll() [3/3]

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

Replace all founded characters "what" with characters "with" and return this string.

PIString s("substrings");
s.replaceAll('s', '_');
piCout << s; // s = "_ub_tring_"
See also
replace(), replaced(), replacedAll()

◆ replacedAll() [1/3]

PIString PIString::replacedAll ( const PIString what,
const PIString with 
) const
inline

Replace all founded substrings "what" with strings "with" in string copy.

See also
replaceAll()

◆ replacedAll() [2/3]

PIString PIString::replacedAll ( const PIString what,
const char  with 
) const
inline

Replace all founded substrings "what" with characters "with" in string copy.

See also
replaceAll()

◆ replacedAll() [3/3]

PIString PIString::replacedAll ( const char  what,
const char  with 
) const
inline

Replace all founded characters "what" with characters "with" in string copy.

See also
replaceAll()

◆ repeat()

PIString & PIString::repeat ( int  times)
inline

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

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

◆ repeated()

PIString PIString::repeated ( int  times) const
inline

Returns repeated "times" times string.

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

◆ insert() [1/5]

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

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

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

◆ insert() [2/5]

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

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

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

◆ insert() [3/5]

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

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

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

◆ insert() [4/5]

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

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

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

◆ insert() [5/5]

PIString & PIString::insert ( const int  index,
const char16_t *  c 
)
inline

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

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

◆ expandRightTo()

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

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

PIString s("str");
s.expandRightTo(2, "_");
piCout << s; // s = "str"
s.expandRightTo(6, "_");
piCout << s; // s = "str___"
See also
expandLeftTo(), expandedRightTo(), expandedLeftTo()

◆ expandLeftTo()

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

Enlarge string to length "len" by addition characters "c" at the begin, and return this string.

PIString s("str");
s.expandLeftTo(2, "_");
piCout << s; // s = "str"
s.expandLeftTo(6, "_");
piCout << s; // s = "___str"
See also
expandRightTo(), expandedRightTo(), expandedLeftTo()

◆ expandedRightTo()

PIString PIString::expandedRightTo ( const int  len,
const PIChar  c 
) const
inline

Enlarge copy of this string to length "len" by addition characters "c" at the end.

PIString s("str");
piCouy << s.expandedRightTo(5, "_"); // s = "str__"
piCout << s; // s = "str"
See also
expandRightTo(), expandLeftTo(), expandedLeftTo()

◆ expandedLeftTo()

PIString PIString::expandedLeftTo ( const int  len,
const PIChar  c 
) const
inline

Enlarge copy of this string to length "len" by addition characters "c" at the begin.

PIString s("str");
piCouy << s.expandedLeftTo(5, "_"); // s = "__str"
piCout << s; // s = "str"
See also
expandRightTo(), expandLeftTo(), expandedRightTo()

◆ quote()

PIString & PIString::quote ( PIChar  c = PIChar('"'))
inline

Add "c" characters at the beginning and end, and return this string.

PIString s("str");
s.quote();
piCout << s; // s = ""str""
See also
quoted()

◆ quoted()

PIString PIString::quoted ( PIChar  c = PIChar('"'))
inline

Returns quoted copy of this string.

PIString s("str");
piCout << s.quoted(); // s = ""str""
piCout << s; // s = "str"
See also
quote()

◆ reverse()

PIString & PIString::reverse ( )
inline

Reverse string and return this string.

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

◆ reversed()

PIString PIString::reversed ( ) const
inline

Reverse copy of this string.

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

◆ elide()

PIString & PIString::elide ( int  size,
float  pos = ElideCenter 
)

Fit string to maximum size "size" by inserting ".." at position "pos" and return this string.

See also
elided()

◆ elided()

PIString PIString::elided ( int  size,
float  pos = ElideCenter 
) const
inline

Fit copy of this string to maximum size "size" by inserting ".." at position "pos".

piCout << PIString("123456789ABCDEF").elided(8, PIString::ElideLeft); // ..ABCDEF
piCout << PIString("123456789ABCDEF").elided(8, PIString::ElideCenter); // 123..DEF
piCout << PIString("123456789ABCDEF").elided(8, PIString::ElideRight); // 123456..
piCout << PIString("123456789ABCDEF").elided(8, 0.25); // 12..CDEF
static const float ElideCenter
Value for elide at center.
Definition: pistring.h:67
static const float ElideLeft
Value for elide at left.
Definition: pistring.h:63
PIString()
Contructs an empty string.
Definition: pistring.h:59
static const float ElideRight
Value for elide at right.
Definition: pistring.h:71
See also
elide()

◆ takeMid()

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

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

PIString s("0123456789");
piCout << s.takeMid(1, 3); // "123"
piCout << s; // s = "0456789"
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.

PIString s("0123456789");
piCout << s.takeLeft(3); // "012"
piCout << s; // s = "3456789"
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.

PIString s("0123456789");
piCout << s.takeRight(3); // "789"
piCout << s; // s = "0123456"
See also
takeMid(), takeLeft()

◆ takeSymbol()

PIString PIString::takeSymbol ( )

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

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.

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 '_' characters from the begin of this string and return it.

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

◆ takeLine()

PIString PIString::takeLine ( )

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

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.

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" characters from the begin of this string and return it.

"shield" symbol prevent analysis of the next symbol

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

Returns string in brackets "start" and "end" characters from the beginning.

PIString s("a(b(c)d)e");
piCout << s.inBrackets('(', ')'); // "b(c)d"
piCout << s; // s = "a(b(c)d)e"

◆ data()

const char * PIString::data ( ) const

Returns char * representation of this string in system codepage.

This function fill internal buffer by sequence of chars. Length of this buffer is count of symbols + end byte '\0'. Returned pointer is valid until next execution of this function.

piCout << PIString("0123456789").data(); // 0123456789
piCout << PIString("â„–1").data(); // â„–1
See also
dataConsole(), dataUTF8()

◆ dataConsole()

const char * PIString::dataConsole ( ) const

Returns char * representation of this string in terminal codepage.

This function fill internal buffer by sequence of chars. Length of this buffer is count of symbols + end byte '\0'. Returned pointer is valid until next execution of this function.

See also
data(), dataUTF8()

◆ dataUTF8()

const char * PIString::dataUTF8 ( ) const

Returns char * representation of this string in UTF-8.

This function fill internal buffer by sequence of chars. Length of this buffer is count of symbols + end byte '\0'. Returned pointer is valid until next execution of this function.

See also
data(), dataConsole()

◆ dataAscii()

const char * PIString::dataAscii ( ) const

Returns char * representation of this string in ASCII.

This function fill internal buffer by sequence of chars. Length of this buffer is count of symbols + end byte '\0'. Returned pointer is valid until next execution of this function.

See also
dataConsole(), dataUTF8()

◆ split()

PIStringList PIString::split ( const PIString delim) const

Split string with delimiter "delim" to PIStringList.

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

◆ find() [1/3]

int PIString::find ( const char  c,
const int  start = 0 
) const

Search character "c" from character at index "start" and return first occur position.

PIString s("012345012345");
piCout << s.find('-'); // -1
piCout << s.find('3'); // 3
piCout << s.find('3', 4); // 9
piCout << s.find('3', 10); // -1
See also
findAny(), findLast(), findAnyLast(), findWord(), findCWord(), findRange()

◆ find() [2/3]

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

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

PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("34"); // 3
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1
See also
findAny(), findLast(), findAnyLast(), findWord(), findCWord(), findRange()

◆ find() [3/3]

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

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

PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("34"); // 3
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1
See also
findAny(), findLast(), findAnyLast(), findWord(), findCWord(), findRange()

◆ findAny() [1/2]

int PIString::findAny ( const PIString str,
const int  start = 0 
) const

Search any character of "str" from character at index "start" and return first occur position.

piCout << PIString("1.str").findAny(".,:"); // 1
piCout << PIString("1,str").findAny(".,:"); // 1
piCout << PIString("1:str").findAny(".,:"); // 1
See also
find(), findLast(), findAnyLast(), findWord(), findCWord(), findRange()

◆ findAny() [2/2]

int PIString::findAny ( const char *  str,
const int  start = 0 
) const
inline

Search any character of "str" from character at index "start" and return first occur position.

piCout << PIString("1.str").findAny(".,:"); // 1
piCout << PIString("1,str").findAny(".,:"); // 1
piCout << PIString("1:str").findAny(".,:"); // 1
See also
find(), findLast(), findAnyLast(), findWord(), findCWord(), findRange()

◆ findLast() [1/3]

int PIString::findLast ( const char  c,
const int  start = 0 
) const

Search character "c" from character at index "start" and return last occur position.

PIString s("012345012345");
piCout << s.findLast('-'); // -1
piCout << s.findLast('3'); // 9
piCout << s.findLast('3', 4); // 9
piCout << s.findLast('3', 10); // -1
See also
find(), findAny(), findAnyLast(), findWord(), findCWord(), findRange()

◆ findLast() [2/3]

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

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

PIString s("012345012345");
piCout << s.findLast("-"); // -1
piCout << s.findLast("34"); // 9
piCout << s.findLast("3", 4); // 9
piCout << s.findLast("3", 10); // -1
See also
find(), findAny(), findAnyLast(), findWord(), findCWord(), findRange()

◆ findLast() [3/3]

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

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

PIString s("012345012345");
piCout << s.findLast("-"); // -1
piCout << s.findLast("34"); // 9
piCout << s.findLast("3", 4); // 9
piCout << s.findLast("3", 10); // -1
See also
find(), findAny(), findAnyLast(), findWord(), findCWord(), findRange()

◆ findAnyLast() [1/2]

int PIString::findAnyLast ( const PIString str,
const int  start = 0 
) const

Search any character of "str" from character at index "start" and return last occur position.

piCout << PIString(".str.0").findAnyLast(".,:"); // 4
piCout << PIString(".str,0").findAnyLast(".,:"); // 4
piCout << PIString(".str:0").findAnyLast(".,:"); // 4
See also
find(), findAny(), findLast(), findWord(), findCWord(), findRange()

◆ findAnyLast() [2/2]

int PIString::findAnyLast ( const char *  str,
const int  start = 0 
) const
inline

Search any character of "str" from character at index "start" and return last occur position.

piCout << PIString(".str.0").findAnyLast(".,:"); // 4
piCout << PIString(".str,0").findAnyLast(".,:"); // 4
piCout << PIString(".str:0").findAnyLast(".,:"); // 4
See also
find(), findAny(), findLast(), findWord(), findCWord(), findRange()

◆ findWord()

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

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

PIString s("this is <PIP>");
piCout << s.findWord("this"); // 0
piCout << s.findWord("is"); // 5
piCout << s.findWord("PIP", 4); // -1
piCout << s.findWord("<PIP>", 4); // 8
See also
find(), findAny(), findLast(), findAnyLast(), findCWord(), findRange()

◆ findCWord()

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

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

PIString s("this::is <PIP>");
piCout << s.findCWord("this"); // 0
piCout << s.findCWord("is"); // 6
piCout << s.findCWord("PIP", 4); // 10
piCout << s.findCWord("<PIP>", 4); // 9
See also
find(), findAny(), findLast(), findAnyLast(), findWord(), findRange()

◆ findRange()

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

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

PIString s(" {figures{inside}}");
int len = -1;
piCout << s.findRange('{', '}', '\\', 0, &len) << len << s.mid(2, len); // 2 15 figures{inside}
s = "\"text\\\"shielded\" next";
piCout << s.findRange('"', '"', '\\', 0, &len) << len << s.mid(1, len); // 1 14 text\"shielded
See also
find(), findAny(), findLast(), findAnyLast(), findWord(), findCWord()

◆ entries() [1/2]

int PIString::entries ( const PIChar  c) const

Returns number of occurrences of character "c".

piCout << PIString(".str.0").entries("."); // 2
piCout << PIString(".str.0").entries("0"); // 1

◆ entries() [2/2]

int PIString::entries ( const PIString str) const

Returns number of occurrences of string "str".

piCout << PIString("hello locale").entries("lo"); // 2
piCout << PIString("hello locale").entries("lo lo"); // 1

◆ clear()

void PIString::clear ( )
inline

Clear string, will be empty string.

Note
Reserved memory will not be released.
See also
resize()

◆ toBool()

bool PIString::toBool ( ) const

Returns true if string equal "true", "yes", "on" or positive not null numeric value.

piCout << PIString("true").toBool(); // true
piCout << PIString("Yes").toBool(); // true
piCout << PIString(" TRUE ").toBool(); // true
piCout << PIString(" 1 ").toBool(); // true
piCout << PIString("0").toBool(); // false
piCout << PIString("0.1").toBool(); // true
piCout << PIString("-1").toBool(); // false
piCout << PIString("").toBool(); // false

◆ toShort()

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

Returns short numeric value of string in base "base".

If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.

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

◆ toUShort()

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

Returns ushort numeric value of string in base "base".

If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.

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

◆ toInt()

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

Returns int numeric value of string in base "base".

If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.

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

Returns uint numeric value of string in base "base".

If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.

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

◆ toLong()

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

Returns long numeric value of string in base "base".

If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.

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

◆ toULong()

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

Returns ulong numeric value of string in base "base".

If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.

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

◆ toLLong()

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

Returns llong numeric value of string in base "base".

If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.

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

◆ toULLong()

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

Returns ullong numeric value of string in base "base".

If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10.

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

◆ toFloat()

float PIString::toFloat ( ) const

Returns float numeric value of string.

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

◆ toDouble()

double PIString::toDouble ( ) const

Returns double numeric value of string.

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

◆ toLDouble()

ldouble PIString::toLDouble ( ) const

Returns ldouble numeric value of string.

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

◆ setNumber() [1/11]

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

Set string content to text representation of "value" in base "base" and return this string.

s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B
PIString & setNumber(const short value, int base=10, bool *ok=0)
Set string content to text representation of "value" in base "base" and return this string.
Definition: pistring.h:1518

◆ setNumber() [2/11]

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

Set string content to text representation of "value" in base "base" and return this string.

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 text representation of "value" in base "base" and return this string.

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 text representation of "value" in base "base" and return this string.

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 text representation of "value" in base "base" and return this string.

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 text representation of "value" in base "base" and return this string.

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 text representation of "value" in base "base" and return this string.

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 text representation of "value" in base "base" and return this string.

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 text representation of "value" with format "format" and precision "precision" and return this string.

s.setNumber(12.3);
piCout << s; // 12.30000000
s.setNumber(12.3, 'f', 3);
piCout << s; // 12.300
s.setNumber(12.123456, 'f', 3);
piCout << s; // 12.123
s.setNumber(123456789., 'g', 2);
piCout << s; // 1.2e+08
s.setNumber(123456789., 'f', 0);
piCout << s; // 123456789

◆ setNumber() [10/11]

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

Set string content to text representation of "value" with format "format" and precision "precision" and return this string.

s.setNumber(12.3);
piCout << s; // 12.30000000
s.setNumber(12.3, 'f', 3);
piCout << s; // 12.300
s.setNumber(12.123456, 'f', 3);
piCout << s; // 12.123
s.setNumber(123456789., 'g', 2);
piCout << s; // 1.2e+08
s.setNumber(123456789., 'f', 0);
piCout << s; // 123456789

◆ setNumber() [11/11]

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

Set string content to text representation of "value" with format "format" and precision "precision" and return this string.

s.setNumber(12.3);
piCout << s; // 12.30000000
s.setNumber(12.3, 'f', 3);
piCout << s; // 12.300
s.setNumber(12.123456, 'f', 3);
piCout << s; // 12.123
s.setNumber(123456789., 'g', 2);
piCout << s; // 1.2e+08
s.setNumber(123456789., 'f', 0);
piCout << s; // 123456789

◆ setReadableSize()

PIString & PIString::setReadableSize ( llong  bytes)

Set string content to human readable size in B/KiB/MiB/GiB/TiB/PiB.

See also
PIString::readableSize()

Example:

piCout << s; // 512 B
piCout << s; // 5.0 KiB
s.setReadableSize(512000);
piCout << s; // 500.0 KiB
s.setReadableSize(5120000);
piCout << s; // 4.8 MiB
s.setReadableSize(512000000);
piCout << s; // 488.2 MiB
s.setReadableSize(51200000000);
piCout << s; // 47.6 GiB
PIString & setReadableSize(llong bytes)
Set string content to human readable size in B/KiB/MiB/GiB/TiB/PiB.
Definition: pistring.cpp:1807

◆ arg() [1/3]

PIString & PIString::arg ( const PIString v)

Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.

piCout << PIString("color %1 is not %2, but %1").arg("red").arg("green"); // color red is not green, but red

◆ arg() [2/3]

PIString & PIString::arg ( int  v,
int  base = 10 
)
inline

Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.

piCout << PIString("ten = %1").arg(10); // ten = 10
piCout << PIString("'%1' is max hex letter (%2 in dec)").arg(0xF, 16).arg(0xF); // 'F' is max hex letter (15 in dec)

◆ arg() [3/3]

PIString & PIString::arg ( double  v,
char  format = 'f',
int  precision = 8 
)
inline

Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.

piCout << PIString("light speed = %1 %2").arg(M_LIGHT_SPEED, 'g', 4).arg("m/s"); // light speed = 2.998e+08 m/s

◆ fromNumber() [1/11]

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

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

piCout << PIString::fromNumber(123, 16); // 7B
static PIString fromNumber(const short value, int base=10, bool *ok=0)
Returns string contains numeric representation of "value" in base "base".
Definition: pistring.h:1776

◆ fromNumber() [2/11]

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

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

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

◆ fromNumber() [3/11]

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

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

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

◆ fromNumber() [4/11]

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

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

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

◆ fromNumber() [5/11]

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

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

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

◆ fromNumber() [6/11]

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

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

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

◆ fromNumber() [7/11]

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

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

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

◆ fromNumber() [8/11]

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

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

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

◆ fromNumber() [9/11]

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

Returns string contains numeric representation of "value" with format "format" and precision "precision".

piCout << PIString::fromNumber(12.3); // 12.30000000
piCout << PIString::fromNumber(12.3, 'f', 3); // 12.300
piCout << PIString::fromNumber(12.123456, 'f', 3); // 12.123
piCout << PIString::fromNumber(123456789., 'g', 2); // 1.2e+08
piCout << PIString::fromNumber(123456789., 'f', 0); // 123456789

◆ fromNumber() [10/11]

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

Returns string contains numeric representation of "value" with format "format" and precision "precision".

piCout << PIString::fromNumber(12.3); // 12.30000000
piCout << PIString::fromNumber(12.3, 'f', 3); // 12.300
piCout << PIString::fromNumber(12.123456, 'f', 3); // 12.123
piCout << PIString::fromNumber(123456789., 'g', 2); // 1.2e+08
piCout << PIString::fromNumber(123456789., 'f', 0); // 123456789

◆ fromNumber() [11/11]

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

Returns string contains numeric representation of "value" with format "format" and precision "precision".

piCout << PIString::fromNumber(12.3); // 12.30000000
piCout << PIString::fromNumber(12.3, 'f', 3); // 12.300
piCout << PIString::fromNumber(12.123456, 'f', 3); // 12.123
piCout << PIString::fromNumber(123456789., 'g', 2); // 1.2e+08
piCout << PIString::fromNumber(123456789., 'f', 0); // 123456789

◆ readableSize()

PIString PIString::readableSize ( llong  bytes)
static

Returns string contains human readable size in B/KiB/MiB/GiB/TiB/PiB.

See also
PIString::setReadableSize()

Example:

piCout << PIString::readableSize(512); // 512 B
piCout << PIString::readableSize(5120); // 5.0 KiB
piCout << PIString::readableSize(512000); // 500.0 KiB
piCout << PIString::readableSize(5120000); // 4.8 MiB
piCout << PIString::readableSize(512000000); // 488.2 MiB
piCout << PIString::readableSize(51200000000); // 47.6 GiB
static PIString readableSize(llong bytes)
Returns string contains human readable size in B/KiB/MiB/GiB/TiB/PiB.
Definition: pistring.cpp:456

◆ swap()

void PIString::swap ( PIString str)
inline

Swaps string str other with this string.

This operation is very fast and never fails.

Friends And Related Function Documentation

◆ versionCompare()

int versionCompare ( const PIString v0,
const PIString v1,
int  components 
)
related

Compare two version strings in free notation and returns 0, -1 or 1.

This function parse version to number codes and labels. Then it compare no more than "components" codes. If there is no difference, compare labels. Each label has corresponding integer value, so "prealpha" < "alpha" < "prebeta" < "beta" < "rc[N]" < "" < "r[N]". Example:

piCout << versionCompare("1.0.0_rc2-999", "1.0.1_rc2-999"); // -1, <
piCout << versionCompare("1.0.0", "0.9.2"); // 1, >
piCout << versionCompare("1.0.0_r1", "1.0.0"); // 1, >
piCout << versionCompare("1.0.0_r1", "1.0.0", 3); // 0, =
piCout << versionCompare("1.0.0_r2", "1.0.0", 3); // 0, =
piCout << versionCompare(".2-alpha", "0.2_alpha"); // 0, =
piCout << versionCompare("1_prebeta", "1.0_alpha"); // 1, >
int versionCompare(const PIString &v0, const PIString &v1, int components)
Compare two version strings in free notation and returns 0, -1 or 1.
Definition: pistring.cpp:1982
Returns
  • 0 - equal
  • 1 - v0 > v1
  • -1 - v0 < v1

◆ versionNormalize()

PIString versionNormalize ( const PIString v)
related

Converts version string in free notation to classic view.

Parse version as described in versionCompare() and returns classic view of codes and labels: major.minor.revision[-build][_label]. Example:

piCout << versionNormalize(""); // 0.0.0
piCout << versionNormalize("1"); // 1.0.0
piCout << versionNormalize("1.2"); // 1.2.0
piCout << versionNormalize("1.2.3"); // 1.2.3
piCout << versionNormalize("1.2+rc1.99"); // 1.2.99_rc1
piCout << versionNormalize("1.2-alpha"); // 1.2.0_alpha
piCout << versionNormalize("1..4_rc2-999"); // 1.0.4-999_rc2
PIString versionNormalize(const PIString &v)
Converts version string in free notation to classic view.
Definition: pistring.cpp:2030