string doc

This commit is contained in:
2022-04-04 16:17:23 +03:00
parent f83d08cf56
commit fb282d405d
5 changed files with 1435 additions and 821 deletions

View File

@@ -1,348 +0,0 @@
#include "pip.h"
void _() {
//! [PIString(char * )]
PIString s("string");
//! [PIString(char * )]
//! [PIString(wchar_t * )]
PIString s(L"string");
//! [PIString(wchar_t * )]
//! [PIString(char * , int)]
PIString s("string", 3); // s = "str"
//! [PIString(char * , int)]
//! [PIString(int, char)]
PIString s(5, 'p'); // s = "ppppp"
//! [PIString(int, char)]
//! [PIString(int, PIChar)]
PIString s(5, ""); // s = "№№№№№"
//! [PIString(int, PIChar)]
//! [PIString::char*]
PIString s("pip");
cout << (char*)s << endl; // pip
//! [PIString::char*]
//! [PIString::<<(PIString)]
PIString s("this"), s1(" is"), s2(" string");
s << s1 << s2; // s = "this is string"
//! [PIString::<<(PIString)]
//! [PIString::<<(PIChar)]
PIString s("stri");
s << PIChar('n') << PIChar('g'); // s = "string"
//! [PIString::<<(PIChar)]
//! [PIString::<<(char * )]
PIString s("this");
s << " is" << " string"; // s = "this is string"
//! [PIString::<<(char * )]
//! [PIString::<<(wchar_t * )]
PIString s;
s << L"№ -" << " number"; // s = "№ - number"
//! [PIString::<<(wchar_t * )]
//! [PIString::<<(int)]
PIString s("ten - ");
s << 10; // s = "ten - 10"
//! [PIString::<<(int)]
//! [PIString::mid]
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"
//! [PIString::mid]
//! [PIString::left]
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"
//! [PIString::left]
//! [PIString::right]
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"
//! [PIString::right]
//! [PIString::cutMid]
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"
//! [PIString::cutMid]
//! [PIString::cutLeft]
PIString s("0123456789");
s.cutLeft(1);
piCout << s; // s = "123456789"
s.cutLeft(3);
piCout << s; // s = "456789"
s.cutLeft(30);
piCout << s; // s = ""
//! [PIString::cutLeft]
//! [PIString::cutRight]
PIString s("0123456789");
s.cutRight(1);
piCout << s; // s = "012345678"
s.cutRight(3);
piCout << s; // s = "012345"
s.cutRight(30);
piCout << s; // s = ""
//! [PIString::cutRight]
//! [PIString::trim]
PIString s(" string ");
s.trim();
piCout << s; // s = "string"
//! [PIString::trim]
//! [PIString::trimmed]
PIString s(" string ");
piCout << s.trimmed(); // s = "string"
piCout << s; // s = " string "
//! [PIString::trimmed]
//! [PIString::replace_0]
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"
//! [PIString::replace_0]
//! [PIString::replaced_0]
PIString s("0123456789");
piCout << s.replaced(2, 3, "_cut_"); // s = "01_cut_56789"
piCout << s.replaced(0, 1, "one_"); // s = "one_123456789"
//! [PIString::replaced_0]
//! [PIString::replace_1]
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
//! [PIString::replace_1]
//! [PIString::replaced_1]
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
//! [PIString::replaced_1]
//! [PIString::replaceAll]
PIString s("substrings");
s.replaceAll("s", "_");
piCout << s; // s = "_ub_tring_"
//! [PIString::replaceAll]
//! [PIString::repeat]
PIString s(" :-) ");
s.repeat(3);
piCout << s; // :-) :-) :-)
//! [PIString::repeat]
//! [PIString::repeated]
PIString s(" :-) ");
piCout << s.repeated(3); // :-) :-) :-)
piCout << s; // :-)
//! [PIString::repeated]
//! [PIString::insert_0]
PIString s("pp");
s.insert(1, "i");
piCout << s; // s = "pip"
//! [PIString::insert_0]
//! [PIString::insert_1]
PIString s("pp");
s.insert(1, 'i');
piCout << s; // s = "pip"
//! [PIString::insert_1]
//! [PIString::insert_2]
PIString s("stg");
s.insert(2, "rin");
piCout << s; // s = "string"
//! [PIString::insert_2]
//! [PIString::expandRightTo]
PIString s("str");
s.expandRightTo(2, "_");
piCout << s; // s = "str"
s.expandRightTo(6, "_");
piCout << s; // s = "str___"
//! [PIString::expandRightTo]
//! [PIString::expandLeftTo]
PIString s("str");
s.expandLeftTo(2, "_");
piCout << s; // s = "str"
s.expandLeftTo(6, "_");
piCout << s; // s = "___str"
//! [PIString::expandLeftTo]
//! [PIString::reverse]
PIString s("0123456789");
s.reverse();
piCout << s; // s = "9876543210"
//! [PIString::reverse]
//! [PIString::reversed]
PIString s("0123456789");
piCout << s.reversed(); // s = "9876543210"
piCout << s; // s = "0123456789"
//! [PIString::reversed]
//! [PIString::elided]
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
//! [PIString::elided]
//! [PIString::lengthAscii]
piCout << PIString("0123456789").lengthAscii(); // 10
piCout << PIString("№1").lengthAscii(); // 3
//! [PIString::lengthAscii]
//! [PIString::data]
piCout << PIString("0123456789").data(); // 0123456789
piCout << PIString("№1").data(); // №1
//! [PIString::data]
//! [PIString::split]
PIString s("1 2 3");
piCout << s.split(" "); // {"1", "2", "3"}
//! [PIString::split]
//! [PIString::find]
PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("3"); // 3
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1
//! [PIString::find]
//! [PIString::findLast]
PIString s("012345012345");
piCout << s.find("-"); // -1
piCout << s.find("3"); // 9
piCout << s.find("3", 4); // 9
piCout << s.find("3", 10); // -1
//! [PIString::findLast]
//! [PIString::findAny]
piCout << PIString("1.str").findAny(".,:"); // 1
piCout << PIString("1,str").findAny(".,:"); // 1
piCout << PIString("1:str").findAny(".,:"); // 1
//! [PIString::findAny]
//! [PIString::findAnyLast]
piCout << PIString("str.0").findAny(".,:"); // 3
piCout << PIString("str,0").findAny(".,:"); // 3
piCout << PIString("str:0").findAny(".,:"); // 3
//! [PIString::findAnyLast]
//! [PIString::findWord]
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
//! [PIString::findWord]
//! [PIString::findCWord]
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
//! [PIString::findCWord]
//! [PIString::toNumber]
piCout << PIString("123").toInt(); // 123
piCout << PIString("123").toInt(16); // 291
piCout << PIString("0x123").toInt(); // 291
piCout << PIString("1001").toInt(2); // 9
//! [PIString::toNumber]
//! [PIString::toFloat]
piCout << PIString("123").toFloat(); // 123
piCout << PIString("1.2E+2").toFloat(); // 120
piCout << PIString("0.01").toFloat(); // 0.01
//! [PIString::toFloat]
//! [PIString::setNumber]
PIString s;
s.setNumber(123);
piCout << s; // 123
s.setNumber(123, 16);
piCout << s; // 7B
//! [PIString::setNumber]
//! [PIString::setFloat]
PIString s;
s.setNumber(12.3);
piCout << s; // 12.3
//! [PIString::setFloat]
//! [PIString::setReadableSize]
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
//! [PIString::setReadableSize]
//! [PIString::fromNumber]
piCout << PIString::fromNumber(123); // 123
piCout << PIString::fromNumber(123, 16); // 7B
//! [PIString::fromNumber]
//! [PIString::fromFloat]
piCout << PIString::fromNumber(12.3); // 12.3
//! [PIString::fromFloat]
//! [PIString::readableSize]
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
//! [PIString::readableSize]
//! [PIString::takeSymbol]
PIString s("\t ! word");
piCout << s.takeSymbol(); // "!"
piCout << s.takeSymbol(); // "w"
piCout << s.takeSymbol(); // "o"
piCout << s; // "rd"
//! [PIString::takeSymbol]
//! [PIString::takeWord]
PIString s("some words\nnew line ");
piCout << s.takeWord(); // "some"
piCout << s.takeWord(); // "words"
piCout << s.takeWord(); // "new"
piCout << s; // " line "
//! [PIString::takeWord]
//! [PIString::takeLine]
PIString s("some words\nnew line \n\nend");
piCout << s.takeLine(); // "some words"
piCout << s.takeLine(); // "new line "
piCout << s.takeLine(); // ""
piCout << s; // "end"
//! [PIString::takeLine]
//! [PIString::takeNumber]
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; // ""
//! [PIString::takeNumber]
//! [PIString::takeRange]
PIString s(" {figures{inside}}");
piCout << s.takeRange('{', '}'); // "figures{inside}"
piCout << s; // ""
s = "\"text\\\"shielded\" next";
piCout << s.takeRange('"', '"'); // "text\"shielded"
piCout << s; // " next"
//! [PIString::takeRange]
//! [PIStringList::join]
PIStringList sl("1", "2");
sl << "3";
piCout << sl.join(" < "); // 1 < 2 < 3
//! [PIStringList::join]
//! [PIStringList::removeStrings]
PIStringList sl("1", "2");
sl << "1" << "2" << "3";
piCout << sl; // {"1", "2", "1", "2", "3"}
piCout << sl.removeStrings("1"); // {"2", "2", "3"}
//! [PIStringList::removeStrings]
//! [PIStringList::removeDuplicates]
PIStringList sl("1", "2");
sl << "1" << "2" << "3";
piCout << sl; // {"1", "2", "1", "2", "3"}
piCout << sl.removeDuplicates(); // {"1", "2", "3"}
//! [PIStringList::removeDuplicates]
};

View File

@@ -28,7 +28,6 @@
//! \~\brief
//! \~english The %PIByteArray class provides an array of bytes
//! \~russian Класс %PIByteArray представляет собой массив байтов
//! \}
//!
//! \~\details
//! \~english
@@ -99,6 +98,7 @@
//! метов \a append().
//! \~\snippet pibytearray.cpp 3
//!
//! \}
static const uchar base64Table[64] = {

View File

@@ -35,81 +35,32 @@
# endif
#endif
/*! \class PIString
* \brief String class
* \details PIP use this class for use string information.
*
* \section PIString_sec0 Synopsis
* This class based on \a PIVector to store information.
* String is a sequence of \a 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.
*
* \section PIString_sec1 To/from data convertions
* Most common constructor is \a PIString(const char * str), where "str"
* is null-terminated string, e.g. \c "string". This is 7 chars with last char = 0.
* Also you can constructs \a PIString from single \a PIChar, \a PIByteArray,
* other \a PIString or sequency of the same characters with custom length.\n \n
* This class has implicit conversions to <tt>const char * </tt> and
* \c std::string. Also there are functions to make same convertions:
* * \a data() - to <tt>const char * </tt>,
* * \a stdString() - to \c std::string,
* * \a toByteArray() - to \a PIByteArray.
*
* \section PIString_sec2 Numeric operations
* You can get symbolic representation of any numeric value with function
* \a 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 \a fromNumber(), that
* returns \a PIString. \n
* Also there is function \a setReadableSize() which is set human-readable
* size in bytes, Kb, Mb, Gb or Pb. Static analog is \a readableSize().
*
*/
//! \addtogroup Core
//! \{
//! \class PIString pistring.h
//! \brief
//! \~english String class
//! \~russian Класс строки
//!
//! \~\details
//! \~english \section PIString_sec0 Synopsis
//! \~russian \section PIString_sec0 Краткий обзор
//!
//! \~english
//! String is a sequence of \a 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.
//!
//! \~russian
//! Строка состоит из последовательности \a PIChar. Реальный объем памяти,
//! занимаемый строкой, равен количеству символов * 2. Строка может быть
//! создана из множества типов и преобразована в несколько типов.
//! Имеет множество методов для манипуляций.
//!
//! \}
/*! \fn int versionCompare(const PIString & v0, const PIString & v1, int components = 6)
* \relatesalso PIString
* \brief Compare two version strings in free notation and returns 0, -1 or 1
* \details 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" < "rcN" < "" < "rN".
* Example:
* \code
* 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_r1", "1.0.0", 3); // 0
* piCout << versionCompare(".2-alpha", "0.2_alpha"); // 0
* piCout << versionCompare("1_prebeta", "1.0_alpha"); // 1
* \endcode
* \return
* * 0 - equal
* * 1 - v0 > v1
* * -1 - v0 < v1
*
*
* \fn PIString versionNormalize(const PIString & v)
* \relatesalso PIString
* \brief Converts version string in free notation to classic view
* \details Parse version as described in \a versionCompare() and
* returns classic view of codes and labels: major.minor.revision[-build][_label].
* Example:
* \code
* 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
* \endcode
*
*/
const char PIString::toBaseN[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
@@ -376,6 +327,19 @@ PIString PIString::fromCodepage(const char * s, const char * c) {
}
//! \~\details
//! \~english
//! Example:
//! \~russian
//! Пример:
//! \~\code
//! 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
//! \endcode
PIString PIString::readableSize(llong bytes) {
PIString s;
s.setReadableSize(bytes);
@@ -458,28 +422,6 @@ void PIString::trimsubstr(int &st, int &fn) const {
}
const char * PIString::dataConsole() const {
buildData(__sysoemname__ );
return (const char *)(data_.data());
}
const char * PIString::dataUTF8() const {
buildData(__utf8name__);
return (const char *)(data_.data());
}
const char * PIString::dataAscii() const {
data_.clear();
for (int i = 0; i < size_s(); ++i) {
data_.push_back(uchar(at(i).ch));
}
data_.push_back(uchar('\0'));
return (const char *)data_.data();
}
uint PIString::hash() const {
return piHashData((const uchar*)PIDeque<PIChar>::data(), size() * sizeof(PIChar));
}
@@ -579,6 +521,21 @@ bool PIString::operator >(const PIString & str) const {
}
//! \~\details
//! \~english
//! If "len" < 0 then returns substring from symbol "start" to end.
//! \~russian
//! Если "len" < 0 тогда возвращается подстрока от символа "start" и до конца.
//! \~\code
//! 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"
//! piCout << s.mid(7, 1); // s = "7"
//! piCout << s.mid(7, 4); // s = "789"
//! \endcode
//! \~\sa \a left(), \a right()
PIString PIString::mid(const int start, const int len) const {
//PIString str;
int s = start, l = len;
@@ -597,6 +554,17 @@ PIString PIString::mid(const int start, const int len) const {
}
//! \~\details
//! \~\code
//! 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"
//! \endcode
//! \~\sa \a cutLeft(), \a cutRight()
PIString & PIString::cutMid(const int start, const int len) {
int s = start, l = len;
if (l == 0) return *this;
@@ -614,6 +582,16 @@ PIString & PIString::cutMid(const int start, const int len) {
}
//! \~\details
//! \~english Remove spaces, tabulations, line feeds and null symbols:
//! \~russian Удаляет пробелы, табуляцию, переводы строк и нулевые символы:
//! \~ ' ', '\\n', '\\r', '\\t', '\\0'
//! \~\code
//! PIString s(" \t string \n");
//! s.trim();
//! piCout << s; // s = "string"
//! \endcode
//! \~\sa \a trimmed()
PIString & PIString::trim() {
int st = -1, fn = 0;
trimsubstr(st, fn);
@@ -635,6 +613,15 @@ PIString PIString::trimmed() const {
}
//! \~\details
//! \~\code
//! 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"
//! \endcode
//! \~\sa \a replaced(), \a replaceAll()
PIString & PIString::replace(int from, int count, const PIString & with) {
count = piMini(count, length() - from);
if (count == with.size_s()) {
@@ -647,6 +634,18 @@ PIString & PIString::replace(int from, int count, const PIString & with) {
}
//! \~\details
//! \~english If "ok" is not null, it set to "true" if something was replaced
//! \~russian Если "ok" не null, то устанавливает в "true" если замена произведена
//! \~\code
//! 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
//! \endcode
//! \~\sa \a replaced(), \a replaceAll()
PIString & PIString::replace(const PIString & what, const PIString & with, bool * ok) {
if (what.isEmpty()) {
if (ok != 0) *ok = false;
@@ -659,6 +658,13 @@ PIString & PIString::replace(const PIString & what, const PIString & with, bool
}
//! \~\details
//! \~\code
//! PIString s("substrings");
//! s.replaceAll("s", "_");
//! piCout << s; // s = "_ub_tring_"
//! \endcode
//! \~\sa \a replace(), \a replaced(), \a replacedAll()
PIString & PIString::replaceAll(const PIString & what, const PIString & with) {
if (what.isEmpty() || what == with) return *this;
if (with.isEmpty()) {
@@ -683,6 +689,13 @@ PIString & PIString::replaceAll(const PIString & what, const PIString & with) {
}
//! \~\details
//! \~\code
//! PIString s("substrings");
//! s.replaceAll("s", '_');
//! piCout << s; // s = "_ub_tring_"
//! \endcode
//! \~\sa \a replace(), \a replaced(), \a replacedAll()
PIString & PIString::replaceAll(const PIString & what, const char with) {
if (what.isEmpty()) return *this;
int l = what.length(), dl = what.length() - 1;
@@ -702,6 +715,13 @@ PIString & PIString::replaceAll(const PIString & what, const char with) {
}
//! \~\details
//! \~\code
//! PIString s("substrings");
//! s.replaceAll('s', '_');
//! piCout << s; // s = "_ub_tring_"
//! \endcode
//! \~\sa \a replace(), \a replaced(), \a replacedAll()
PIString & PIString::replaceAll(const char what, const char with) {
int l = length();
for (int i = 0; i < l; ++i) {
@@ -767,6 +787,15 @@ PIStringList PIString::split(const PIString & delim) const {
}
//! \~\details
//! \~\code
//! PIString s("012345012345");
//! piCout << s.find('-'); // -1
//! piCout << s.find('3'); // 3
//! piCout << s.find('3', 4); // 9
//! piCout << s.find('3', 10); // -1
//! \endcode
//! \~\sa \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
int PIString::find(const char c, const int start) const {
for (int i = start; i < length(); ++i) {
if (at(i) == c) return i;
@@ -775,6 +804,15 @@ int PIString::find(const char c, const int start) const {
}
//! \~\details
//! \~\code
//! PIString s("012345012345");
//! piCout << s.find("-"); // -1
//! piCout << s.find("34"); // 3
//! piCout << s.find("3", 4); // 9
//! piCout << s.find("3", 10); // -1
//! \endcode
//! \~\sa \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
int PIString::find(const PIString & str, const int start) const {
int l = str.length();
for (int i = start; i < length() - l + 1; ++i) {
@@ -784,6 +822,30 @@ int PIString::find(const PIString & str, const int start) const {
}
//! \~\details
//! \~\code
//! piCout << PIString("1.str").findAny(".,:"); // 1
//! piCout << PIString("1,str").findAny(".,:"); // 1
//! piCout << PIString("1:str").findAny(".,:"); // 1
//! \endcode
//! \~\sa \a find(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
int PIString::findAny(const PIString & str, const int start) const {
for (int i = start; i < length(); ++i) {
if (str.contains(at(i))) return i;
}
return -1;
}
//! \~\details
//! \~\code
//! PIString s("012345012345");
//! piCout << s.findLast('-'); // -1
//! piCout << s.findLast('3'); // 9
//! piCout << s.findLast('3', 4); // 9
//! piCout << s.findLast('3', 10); // -1
//! \endcode
//! \~\sa \a find(), \a findAny(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
int PIString::findLast(const char c, const int start) const {
for (int i = length() - 1; i >= start; --i) {
if (at(i) == c) return i;
@@ -792,6 +854,15 @@ int PIString::findLast(const char c, const int start) const {
}
//! \~\details
//! \~\code
//! PIString s("012345012345");
//! piCout << s.findLast("-"); // -1
//! piCout << s.findLast("34"); // 9
//! piCout << s.findLast("3", 4); // 9
//! piCout << s.findLast("3", 10); // -1
//! \endcode
//! \~\sa \a find(), \a findAny(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
int PIString::findLast(const PIString & str, const int start) const {
int l = str.length();
for (int i = length() - l; i >= start; --i) {
@@ -801,6 +872,30 @@ int PIString::findLast(const PIString & str, const int start) const {
}
//! \~\details
//! \~\code
//! piCout << PIString(".str.0").findAnyLast(".,:"); // 4
//! piCout << PIString(".str,0").findAnyLast(".,:"); // 4
//! piCout << PIString(".str:0").findAnyLast(".,:"); // 4
//! \endcode
//! \~\sa \a find(), \a findAny(), \a findLast(), \a findWord(), \a findCWord(), \a findRange()
int PIString::findAnyLast(const PIString & str, const int start) const {
for (int i = length() - 1; i >= start; --i) {
if (str.contains(at(i))) return i;
}
return -1;
}
//! \~\details
//! \~\code
//! 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
//! \endcode
//! \~\sa \a find(), \a findAny(), \a findLast(), \a findAnyLast(), \a findCWord(), \a findRange()
int PIString::findWord(const PIString & word, const int start) const {
int f = start - 1, tl = length(), wl = word.length();
while ((f = find(word, f + 1)) >= 0) {
@@ -826,6 +921,15 @@ int PIString::findWord(const PIString & word, const int start) const {
}
//! \~\details
//! \~\code
//! 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
//! \endcode
//! \~\sa \a find(), \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findRange()
int PIString::findCWord(const PIString & word, const int start) const {
int f = start - 1, tl = length(), wl = word.length();
while ((f = find(word, f + 1)) >= 0) {
@@ -851,6 +955,15 @@ int PIString::findCWord(const PIString & word, const int start) const {
}
//! \~\details
//! \~\code
//! 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
//! \endcode
//! \~\sa \a find(), \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord()
int PIString::findRange(const PIChar start, const PIChar end, const PIChar shield, const int start_index, int * len) const {
if (len) *len = 0;
bool trim_ = (start != ' ' && start != '\t' && start != '\n' && start != '\r'), eq = (start == end);
@@ -891,22 +1004,6 @@ int PIString::findRange(const PIChar start, const PIChar end, const PIChar shiel
}
int PIString::findAny(const PIString & str, const int start) const {
for (int i = start; i < length(); ++i) {
if (str.contains(at(i))) return i;
}
return -1;
}
int PIString::findAnyLast(const PIString & str, const int start) const {
for (int i = length() - 1; i >= start; --i) {
if (str.contains(at(i))) return i;
}
return -1;
}
int PIString::entries(const PIChar c) const {
int sz = size_s(), ret = 0;
for (int i = 0; i < sz; ++i) {
@@ -928,6 +1025,17 @@ bool PIString::endsWith(const PIString & str) const {
}
//! \~\details
//! \~\code
//! 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
//! \endcode
bool PIString::toBool() const {
static const PIString s_true = PIStringAscii("true");
static const PIString s_yes = PIStringAscii("yes" );
@@ -941,6 +1049,15 @@ bool PIString::toBool() const {
}
//! \~\details
//! \~\code
//! PIString s("\t ! word");
//! piCout << s.takeSymbol(); // "!"
//! piCout << s.takeSymbol(); // "w"
//! piCout << s.takeSymbol(); // "o"
//! piCout << s; // "rd"
//! \endcode
//! \~\sa \a takeWord(), \a takeCWord(), \a takeLine(), \a takeNumber(), \a takeRange()
PIString PIString::takeSymbol() {
PIString ret;
int sz = size_s(), ss = -1;
@@ -957,6 +1074,15 @@ PIString PIString::takeSymbol() {
}
//! \~\details
//! \~\code
//! PIString s("some words\nnew line ");
//! piCout << s.takeWord(); // "some"
//! piCout << s.takeWord(); // "words"
//! piCout << s.takeWord(); // "new"
//! piCout << s; // " line "
//! \endcode
//! \~\sa \a takeSymbol(), \a takeCWord(), \a takeLine(), \a takeNumber(), \a takeRange()
PIString PIString::takeWord() {
int sz = size_s(), ws = -1, we = -1;
for (int i = 0; i < sz; ++i) {
@@ -977,6 +1103,10 @@ PIString PIString::takeWord() {
}
//! \~\details
//! \~\code
//! \endcode
//! \~\sa \a takeSymbol(), \a takeWord(), \a takeLine(), \a takeNumber(), \a takeRange()
PIString PIString::takeCWord() {
PIString ret;
int sz = size_s(), ws = -1, we = -1;
@@ -1009,6 +1139,15 @@ PIString PIString::takeCWord() {
}
//! \~\details
//! \~\code
//! PIString s("some words\nnew line \n\nend");
//! piCout << s.takeLine(); // "some words"
//! piCout << s.takeLine(); // "new line "
//! piCout << s.takeLine(); // ""
//! piCout << s; // "end"
//! \endcode
//! \~\sa \a takeSymbol(), \a takeWord(), \a takeCWord(), \a takeNumber(), \a takeRange()
PIString PIString::takeLine() {
int sz = size_s(), le = -1;
for (int i = 0; i < sz; ++i) {
@@ -1029,6 +1168,16 @@ PIString PIString::takeLine() {
}
//! \~\details
//! \~\code
//! 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; // ""
//! \endcode
//! \~\sa \a takeSymbol(), \a takeWord(), \a takeCWord(), \a takeLine(), \a takeRange()
PIString PIString::takeNumber() {
PIString ret;
int sz = size_s(), ls = -1, le = -1, phase = 0;
@@ -1123,6 +1272,18 @@ PIString PIString::takeNumber() {
}
//! \~\details
//! \~english "shield" symbol prevent analysis of the next symbol
//! \~russian Символ "shield" экранирует следующий символ
//! \~\code
//! PIString s(" {figures{inside}}");
//! piCout << s.takeRange('{', '}'); // "figures{inside}"
//! piCout << s; // ""
//! s = "\"text\\\"shielded\" next";
//! piCout << s.takeRange('"', '"'); // "text\"shielded"
//! piCout << s; // " next"
//! \endcode
//! \~\sa \a takeSymbol(), \a takeWord(), \a takeLine(), \a takeNumber()
PIString PIString::takeRange(const PIChar start, const PIChar end, const PIChar shield) {
PIString ret;
bool trim_ = (start != ' ' && start != '\t' && start != '\n' && start != '\r'), eq = (start == end);
@@ -1170,6 +1331,12 @@ PIString PIString::takeRange(const PIChar start, const PIChar end, const PIChar
}
//! \~\details
//! \~\code
//! PIString s("a(b(c)d)e");
//! piCout << s.inBrackets('(', ')'); // "b(c)d"
//! piCout << s; // s = "a(b(c)d)e"
//! \endcode
PIString PIString::inBrackets(const PIChar start, const PIChar end) const {
int slen = length();
int st = -1, bcnt = 0;
@@ -1189,6 +1356,96 @@ PIString PIString::inBrackets(const PIChar start, const PIChar end) const {
}
//! \~\details
//! \~english It`s equivalent length of char sequence returned by function \a data() - 1, without terminating null-char
//! \~russian Эквивалентно длине данных, возвращаемых \a data() - 1, без завершающего нулевого байта
//! \~\code
//! piCout << PIString("0123456789").lengthAscii(); // 10
//! piCout << PIString("№1").lengthAscii(); // 3
//! \endcode
//! \~\sa \a data()
int PIString::lengthAscii() const {
buildData(__syslocname__);
return data_.size_s() - 1;
}
//! \~\details
//! \~english
//! This function fill internal buffer by sequence
//! of chars. Minimum length of this buffer is count
//! of symbols. Returned pointer is valid until next
//! execution of this function
//! \~russian
//! Этот метод заполняет внутренный байтовый буфер. Минимальный размер
//! этого буфера равен количеству символов строки. Возвращаемый указатель
//! действителен до следующего вызова этого метода
//! \~\code
//! piCout << PIString("0123456789").data(); // 0123456789
//! piCout << PIString("№1").data(); // №1
//! \endcode
//! \~\sa \a dataConsole(), \a dataUTF8()
const char * PIString::data() const {
buildData(__syslocname__);
return (const char *)(data_.data());
}
//! \~\details
//! \~english
//! This function fill internal buffer by sequence
//! of chars. Minimum length of this buffer is count
//! of symbols. Returned pointer is valid until next
//! execution of this function
//! \~russian
//! Этот метод заполняет внутренный байтовый буфер. Минимальный размер
//! этого буфера равен количеству символов строки. Возвращаемый указатель
//! действителен до следующего вызова этого метода
//! \~\sa \a data(), \a dataUTF8()
const char * PIString::dataConsole() const {
buildData(__sysoemname__ );
return (const char *)(data_.data());
}
//! \~\details
//! \~english
//! This function fill internal buffer by sequence
//! of chars. Minimum length of this buffer is count
//! of symbols. Returned pointer is valid until next
//! execution of this function
//! \~russian
//! Этот метод заполняет внутренный байтовый буфер. Минимальный размер
//! этого буфера равен количеству символов строки. Возвращаемый указатель
//! действителен до следующего вызова этого метода
//! \~\sa \a data(), \a dataConsole()
const char * PIString::dataUTF8() const {
buildData(__utf8name__);
return (const char *)(data_.data());
}
//! \~\details
//! \~english
//! This function fill internal buffer by sequence
//! of chars. Length of this buffer is count
//! of symbols. Returned pointer is valid until next
//! execution of this function
//! \~russian
//! Этот метод заполняет внутренный байтовый буфер. Размер
//! этого буфера равен количеству символов строки. Возвращаемый указатель
//! действителен до следующего вызова этого метода
//! \~\sa \a dataConsole(), \a dataUTF8()
const char * PIString::dataAscii() const {
data_.clear();
for (int i = 0; i < size_s(); ++i) {
data_.push_back(uchar(at(i).ch));
}
data_.push_back(uchar('\0'));
return (const char *)data_.data();
}
PIString PIString::toUpperCase() const {
PIString str(*this);
int l = str.size();
@@ -1243,6 +1500,26 @@ ldouble PIString::toLDouble() const {
}
//! \~\details
//! \~english
//! Example:
//! \~russian
//! Пример:
//! \~\code
//! 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
//! \endcode
PIString & PIString::setReadableSize(llong bytes) {
clear();
if (bytes < 1024) {
@@ -1351,6 +1628,38 @@ int versionLabelValue(PIString s) {
}
//! \relatesalso PIString
//! \~\details
//! \~english
//! 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:
//! \~russian
//! Этот метод разбирает версии на числовые части и метку. Затем сравнивает
//! не более чем "components" частей. Если различий нет, то сравниваются
//! метки. Каждой метке соответствует своё значение так, что
//! "prealpha" < "alpha" < "prebeta" < "beta" < "rc[N]" < "" < "r[N]".
//! Пример:
//! \~\code
//! 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, >
//! \endcode
//! \~\return
//! \~english
//! * 0 - equal
//! * 1 - v0 > v1
//! * -1 - v0 < v1
//! \~russian
//! * 0 - равны
//! * 1 - v0 > v1
//! * -1 - v0 < v1
int versionCompare(const PIString & v0, const PIString & v1, int components) {
PIStringList strs[2]; PIVector<int> codes[2];
parseVersion(v0.toLowerCase(), codes[0], strs[0]);
@@ -1379,6 +1688,25 @@ int versionCompare(const PIString & v0, const PIString & v1, int components) {
}
//! \relatesalso PIString
//! \~\details
//! \~english
//! Parse version as described in \a versionCompare() and returns
//! classic view of codes and labels: major.minor.revision[-build][_label].
//! Example:
//! \~russian
//! Разбирает версию по описанию \a versionCompare() и возвращает
//! классическое представление версии и метки: major.minor.revision[-build][_label].
//! Пример:
//! \~\code
//! 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
//! \endcode
PIString versionNormalize(const PIString & v) {
PIStringList strs; PIVector<int> codes;
parseVersion(v.toLowerCase(), codes, strs);
@@ -1407,4 +1735,3 @@ PICout operator <<(PICout s, const PIString & v) {
s.quote();
return s;
}

View File

@@ -37,11 +37,20 @@ class PIP_EXPORT PIString: public PIDeque<PIChar>
{
friend PIByteArray & operator >>(PIByteArray & s, PIString & v);
public:
//! Contructs an empty string
//! \~english Contructs an empty string
//! \~russian Создает пустую строку
PIString(): PIDeque<PIChar>() {}
//! \~english Value for elide at left
//! \~russian Значение для пропуска слева
static const float ElideLeft ;
//! \~english Value for elide at center
//! \~russian Значение для пропуска в середине
static const float ElideCenter;
//! \~english Value for elide at right
//! \~russian Значение для пропуска справа
static const float ElideRight ;
PIString & operator +=(const PIChar c) {push_back(c); return *this;}
@@ -51,683 +60,1272 @@ public:
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;}
PIString & operator +=(const PIString & str);
//! \~english Contructs a copy of string
//! \~russian Создает копию строки
PIString(const PIString & o): PIDeque<PIChar>(o) {}
PIString(PIString && o): PIDeque<PIChar>(std::move(o)) {}
//! Contructs string with single symbol "c"
//! \~english Contructs string with single symbol "c"
//! \~russian Создает строку из одного символа "c"
PIString(const PIChar c): PIDeque<PIChar>() {*this += c;}
//! \~english Contructs string with single symbol "c"
//! \~russian Создает строку из одного символа "c"
PIString(const char c): PIDeque<PIChar>() {*this += PIChar(c);}
/*! \brief Contructs string from c-string "str"
* \details "str" should be null-terminated\n
* Example: \snippet pistring.cpp PIString(char * ) */
//! \~english Contructs string from C-string "str" (system codepage)
//! \~russian Создает строку из C-строки "str" (кодировка системы)
//! \~\details
//! \~english
//! "str" should be null-terminated\n
//! \~russian
//! "str" должна заканчиваться нулевым байтом\n
//! \~\code
//! PIString s("string");
//! \endcode
PIString(const char * str): PIDeque<PIChar>() {*this += str;}
/*! \brief Contructs string from \c wchar_t c-string "str"
* \details "str" should be null-terminated\n
* Example: \snippet pistring.cpp PIString(wchar_t * ) */
//! \~english Contructs string from \c wchar_t C-string "str"
//! \~russian Создает строку из \c wchar_t C-строки "str"
//! \~\details
//! \~english
//! "str" should be null-terminated
//! \~russian
//! "str" должна заканчиваться нулевым \c wchar_t
//! \~\code
//! PIString s(L"string");
//! \endcode
PIString(const wchar_t * str): PIDeque<PIChar>() {*this += str;}
//! Contructs string from byte array "ba"
//! \~english Contructs string from byte array "ba" (as UTF-8)
//! \~russian Создает строку из байтового массива "ba" (как UTF-8)
PIString(const PIByteArray & ba): PIDeque<PIChar>() {*this += ba;}
//! \brief Contructs string from "len" characters of buffer "str"
//! \~english Contructs string from "len" characters of buffer "str"
//! \~russian Создает строку из "len" символов массива "str"
PIString(const PIChar * str, const int len): PIDeque<PIChar>(str, size_t(len)) {}
/*! \brief Contructs string from "len" characters of buffer "str"
* \details Example: \snippet pistring.cpp PIString(char * , int) */
//! \~english Contructs string from "len" characters of buffer "str" (system codepage)
//! \~russian Создает строку из "len" символов массива "str" (кодировка системы)
//! \~\details
//! \~\code
//! PIString s("string", 3); // s = "str"
//! \endcode
PIString(const char * str, const int len): PIDeque<PIChar>() {appendFromChars(str, len);}
/*! \brief Contructs string as sequence of characters "c" of buffer with length "len"
* \details Example: \snippet pistring.cpp PIString(int, char) */
//! \~english Contructs string as sequence of characters "c" of buffer with length "len"
//! \~russian Создает строку как последовательность длиной "len" символа "c"
//! \~\details
//! \~\code
//! PIString s(5, 'p'); // s = "ppppp"
//! \endcode
PIString(const int len, const char c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) push_back(c);}
/*! \brief Contructs string as sequence of symbols "c" of buffer with length "len"
* \details Example: \snippet pistring.cpp PIString(int, PIChar) */
//! \~english Contructs string as sequence of symbols "c" of buffer with length "len"
//! \~russian Создает строку как последовательность длиной "len" символа "c"
//! \~\details
//! \~\code
//! PIString s(5, "№"); // s = "№№№№№"
//! \endcode
PIString(const int len, const PIChar c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) push_back(c);}
~PIString() {}
//! \~english Assign operator
//! \~russian Оператор присваивания
PIString & operator =(const PIString & o) {if (this == &o) return *this; clear(); *this += o; return *this;}
PIString & operator =(PIString && o) {swap(o); return *this;}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator ==(const PIString & str) const;
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator ==(const PIChar c) const {if (size_s() != 1) return false; return at(0) == c;}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator ==(const char * str) const {return *this == PIString(str);}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator !=(const PIString & str) const;
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator !=(const PIChar c) const {if (size_s() != 1) return true; return at(0) != c;}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator !=(const char * str) const {return *this != PIString(str);}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator <(const PIString & str) const;
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator <(const PIChar c) const {if (size_s() != 1) return size_s() < 1; return at(0) < c;}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator <(const char * str) const {return *this < PIString(str);}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator >(const PIString & str) const;
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator >(const PIChar c) const {if (size_s() != 1) return size_s() > 1; return at(0) > c;}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator >(const char * str) const {return *this > PIString(str);}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator <=(const PIString & str) const {return !(*this > str);}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator <=(const PIChar c) const {return !(*this > c);}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator <=(const char * str) const {return *this <= PIString(str);}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator >=(const PIString & str) const {return !(*this < str);}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator >=(const PIChar c) const {return !(*this < c);}
//! Compare operator
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator >=(const char * str) const {return *this >= PIString(str);}
/*! \brief Append string "str" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(PIString) */
//! \~english Append string "str" at the end of string
//! \~russian Добавляет в конец строку "str"
//! \~\details
//! \~\code
//! PIString s("this"), s1(" is"), s2(" string");
//! s << s1 << s2; // s = "this is string"
//! \endcode
PIString & operator <<(const PIString & str) {*this += str; return *this;}
/*! \brief Append symbol "c" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(PIChar) */
//! \~english Append symbol "c" at the end of string
//! \~russian Добавляет в конец символ "c"
//! \~\details
//! \~\code
//! PIString s("stri");
//! s << PIChar('n') << PIChar('g'); // s = "string"
//! \endcode
PIString & operator <<(const PIChar c) {*this += c; return *this;}
/*! \brief Append symbol "c" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(PIChar) */
//! \~english Append symbol "c" at the end of string
//! \~russian Добавляет в конец символ "c"
//! \~\details
//! \~\code
//! PIString s("stri");
//! s << 'n' << 'g'; // s = "string"
//! \endcode
PIString & operator <<(const char c) {*this += PIChar(c); return *this;}
/*! \brief Append c-string "str" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(char * ) */
//! \~english Append С-string "str" at the end of string
//! \~russian Добавляет в конец C-строку "str"
//! \~\details
//! \~\code
//! PIString s("this");
//! s << " is" << " string"; // s = "this is string"
//! \endcode
PIString & operator <<(const char * str) {*this += str; return *this;}
/*! \brief Append \c wchar_t c-string "str" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(wchar_t * ) */
//! \~english Append \c wchar_t C-string "str" at the end of string
//! \~russian Добавляет в конец \c wchar_t C-строку "str"
//! \~\details
//! \~\code
//! PIString s;
//! s << L"№ -" << " number"; // s = "№ - number"
//! \endcode
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
/*! \brief Append string representation of "num" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(int) */
//! \~english Append string representation of "num" at the end of string
//! \~russian Добавляет в конец строковое представление "num"
//! \~\details
//! \~\code
//! PIString s("ten - ");
//! s << 10; // s = "ten - 10"
//! \endcode
PIString & operator <<(const int & num) {*this += PIString::fromNumber(num); return *this;}
PIString & operator <<(const uint & num) {*this += PIString::fromNumber(num); return *this;}
/*! \brief Append string representation of "num" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(int) */
//! \~english Append string representation of "num" at the end of string
//! \~russian Добавляет в конец строковое представление "num"
//! \~\details
//! \~\code
//! PIString s("ten - ");
//! s << 10; // s = "ten - 10"
//! \endcode
PIString & operator <<(const long & num) {*this += PIString::fromNumber(num); return *this;}
PIString & operator <<(const ulong & num) {*this += PIString::fromNumber(num); return *this;}
PIString & operator <<(const llong & num) {*this += PIString::fromNumber(num); return *this;}
PIString & operator <<(const ullong & num) {*this += PIString::fromNumber(num); return *this;}
/*! \brief Append string representation of "num" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(int) */
//! \~english Append string representation of "num" at the end of string
//! \~russian Добавляет в конец строковое представление "num"
//! \~\details
//! \~\code
//! PIString s("1/10 - ");
//! s << 0.1; // s = "1/10 - 0.1"
//! \endcode
PIString & operator <<(const float & num) {*this += PIString::fromNumber(num); return *this;}
/*! \brief Append string representation of "num" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(int) */
//! \~english Append string representation of "num" at the end of string
//! \~russian Добавляет в конец строковое представление "num"
//! \~\details
//! \~\code
//! PIString s("1/10 - ");
//! s << 0.1; // s = "1/10 - 0.1"
//! \endcode
PIString & operator <<(const double & num) {*this += PIString::fromNumber(num); return *this;}
//! \brief Insert string "str" at the begin of string
//! \~english Insert string "str" at the begin of string
//! \~russian Вставляет "str" в начало строки
PIString & prepend(const PIString & str) {insert(0, str); return *this;}
//! \brief Insert string "str" at the end of string
//! \~english Insert string "str" at the end of string
//! \~russian Вставляет "str" в конец строки
PIString & append(const PIString & str) {*this += str; return *this;}
/*! \brief Return part of string from symbol at index "start" and maximum length "len"
* \details All variants demonstrated in example: \snippet pistring.cpp PIString::mid
* \sa \a left(), \a right() */
//! \~english Returns part of string from symbol at index "start" and maximum length "len"
//! \~russian Возвращает подстроку от символа "start" и максимальной длиной "len"
PIString mid(const int start, const int len = -1) const;
/*! \brief Return sub-string of string from symbol at index "start" and maximum length "len" */
//! \~english Synonym of \a mid()
//! \~russian Аналог \a mid()
PIString subString(const int start, const int len = -1) const {return mid(start, len);}
/*! \brief Return part of string from left and maximum length "len"
* \details Example: \snippet pistring.cpp PIString::left
* \sa \a mid(), \a right() */
//! \~english Returns part of string from start and maximum length "len"
//! \~russian Возвращает подстроку от начала и максимальной длиной "len"
//! \~\details
//! \~\code
//! 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"
//! \endcode
//! \~\sa \a mid(), \a right()
PIString left(const int len) const {return len <= 0 ? PIString() : mid(0, len);}
/*! \brief Return part of string from right and maximum length "len"
* \details Example: \snippet pistring.cpp PIString::right
* \sa \a mid(), \a left() */
//! \~english Returns part of string at end and maximum length "len"
//! \~russian Возвращает подстроку максимальной длиной "len" и до конца
//! \~\details
//! \~\code
//! 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"
//! \endcode
//! \~\sa \a mid(), \a left()
PIString right(const int len) const {return len <= 0 ? PIString() : mid(size() - len, len);}
/*! \brief Remove part of string from symbol as index "start" and maximum length "len"
* and return this string
* \details All variants demonstrated in example: \snippet pistring.cpp PIString::cutMid
* \sa \a cutLeft(), \a cutRight() */
//! \~english Remove part of string from symbol as index "start" and maximum length "len" and return this string
//! \~russian Удаляет часть строки от символа "start" и максимальной длины "len", возвращает эту строку
PIString & cutMid(const int start, const int len);
/*! \brief Remove part of string from left and maximum length "len" and return this string
* \details Example: \snippet pistring.cpp PIString::cutLeft
* \sa \a cutMid(), \a cutRight() */
//! \~english Remove part of string from start and maximum length "len" and return this string
//! \~russian Удаляет часть строки от начала и максимальной длины "len", возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("0123456789");
//! s.cutLeft(1);
//! piCout << s; // s = "123456789"
//! s.cutLeft(3);
//! piCout << s; // s = "456789"
//! s.cutLeft(30);
//! piCout << s; // s = ""
//! \endcode
//! \~\sa \a cutMid(), \a cutRight()
PIString & cutLeft(const int len) {return len <= 0 ? *this : cutMid(0, len);}
/*! \brief Remove part of string from right and maximum length "len" and return this string
* \details Example: \snippet pistring.cpp PIString::cutRight
* \sa \a cutMid(), \a cutLeft() */
//! \~english Remove part of string at end and maximum length "len" and return this string
//! \~russian Удаляет часть строки максимальной длины "len" от конца, возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("0123456789");
//! s.cutRight(1);
//! piCout << s; // s = "012345678"
//! s.cutRight(3);
//! piCout << s; // s = "012345"
//! s.cutRight(30);
//! piCout << s; // s = ""
//! \endcode
//! \~\sa \a cutMid(), \a cutLeft()
PIString & cutRight(const int len) {return len <= 0 ? *this : cutMid(size() - len, len);}
/*! \brief Remove spaces at the start and at the end of string and return this string
* \details Example: \snippet pistring.cpp PIString::trim
* \sa \a trimmed() */
//! \~english Remove spaces at the start and at the end of string and return this string
//! \~russian Удаляет пробельные символы с начала и конца строки и возвращает эту строку
PIString & trim();
/*! \brief Return copy of this string without spaces at the start and at the end
* \details Example: \snippet pistring.cpp PIString::trimmed
* \sa \a trim() */
//! \~english Returns copy of this string without spaces at the start and at the end
//! \~russian Возвращает копию этой строки без пробельных символов с начала и конца
//! \~\details
//! \~\code
//! PIString s(" \t string \n");
//! piCout << s.trimmed(); // s = "string"
//! piCout << s; // s = " string "
//! \endcode
//! \~\sa \a trim()
PIString trimmed() const;
/*! \brief Replace part of string from index "from" and maximum length "len"
* with string "with" and return this string
* \details Example: \snippet pistring.cpp PIString::replace_0
* \sa \a replaced(), \a replaceAll() */
//! \~english Replace part of string from index "from" and maximum length "len" with string "with" and return this string
//! \~russian Заменяет часть строки от символа "from" и максимальной длины "len" строкой "with", возвращает эту строку
PIString & replace(const int from, const int count, const PIString & with);
/*! \brief Replace part copy of this string from index "from" and maximum length "len"
* with string "with" and return copied string
* \details Example: \snippet pistring.cpp PIString::replaced_0
* \sa \a replace(), \a replaceAll() */
//! \~english Replace part copy of this string from index "from" and maximum length "len" with string "with"
//! \~russian Заменяет часть копии этой строки от символа "from" и максимальной длины "len" строкой "with"
//! \~\details
//! \~\code
//! PIString s("0123456789");
//! piCout << s.replaced(2, 3, "_cut_"); // s = "01_cut_56789"
//! piCout << s.replaced(0, 1, "one_"); // s = "one_123456789"
//! \endcode
//! \~\sa \a replace(), \a replaceAll()
PIString replaced(const int from, const int count, const PIString & with) const {PIString str(*this); str.replace(from, count, with); return str;}
/*! \brief Replace first founded substring "what" with string "with" and return this string
* \details If "ok" is not null, it set to "true" if something was replaced\n
* Example: \snippet pistring.cpp PIString::replace_1
* \sa \a replaced(), \a replaceAll() */
//! \~english Replace first founded substring "what" with string "with" and return this string
//! \~russian Заменяет первую найденную подстроку "what" строкой "with", возвращает эту строку
PIString & replace(const PIString & what, const PIString & with, bool * ok = 0);
/*! \brief Replace first founded substring "what" with string "with" and return copied string
* \details If "ok" is not null, it set to "true" if something was replaced\n
* Example: \snippet pistring.cpp PIString::replaced_1
* \sa \a replaced(), \a replaceAll() */
//! \~english Replace in string copy first founded substring "what" with string "with"
//! \~russian Заменяет в копии строки первую найденную подстроку "what" строкой "with"
//! \~\details
//! \~english If "ok" is not null, it set to "true" if something was replaced
//! \~russian Если "ok" не null, то устанавливает в "true" если замена произведена
//! \~\code
//! 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
//! \endcode
//! \~\sa \a replaced(), \a replaceAll()
PIString replaced(const PIString & what, const PIString & with, bool * ok = 0) const {PIString str(*this); str.replace(what, with, ok); return str;}
/*! \brief Replace all founded substrings "what" with strings "with" and return this string
* \details Example: \snippet pistring.cpp PIString::replaceAll
* \sa \a replace(), \a replaced() */
//! \~english Replace all founded substrings "what" with strings "with" and return this string
//! \~russian Заменяет все найденные подстроки "what" строками "with", возвращает эту строку
PIString & replaceAll(const PIString & what, const PIString & with);
/*! \brief Replace all founded substrings "what" with symbol "with" and return this string
* \details Example: \snippet pistring.cpp PIString::replaceAll
* \sa \a replace(), \a replaced() */
//! \~english Replace all founded substrings "what" with symbols "with" and return this string
//! \~russian Заменяет все найденные подстроки "what" символами "with", возвращает эту строку
PIString & replaceAll(const PIString & what, const char with);
/*! \brief Replace all founded symbols "what" with symbol "with" and return this string
* \details Example: \snippet pistring.cpp PIString::replaceAll
* \sa \a replace(), \a replaced() */
//! \~english Replace all founded symbols "what" with symbols "with" and return this string
//! \~russian Заменяет все найденные символы "what" символами "with", возвращает эту строку
PIString & replaceAll(const char what, const char with);
//! \~english Replace all founded substrings "what" with strings "with" in string copy
//! \~russian Заменяет в копии строки все найденные подстроки "what" строками "with"
//! \~\sa \a replaceAll()
PIString replacedAll(const PIString & what, const PIString & with) const {PIString str(*this); str.replaceAll(what, with); return str;}
//! \~english Replace all founded substrings "what" with symbols "with" in string copy
//! \~russian Заменяет в копии строки все найденные подстроки "what" символами "with"
//! \~\sa \a replaceAll()
PIString replacedAll(const PIString & what, const char with) const {PIString str(*this); str.replaceAll(what, with); return str;}
//! \~english Replace all founded symbols "what" with symbols "with" in string copy
//! \~russian Заменяет в копии строки все найденные символы "what" символами "with"
//! \~\sa \a replaceAll()
PIString replacedAll(const char what, const char with) const {PIString str(*this); str.replaceAll(what, with); return str;}
//! \~english Remove all founded substrings "what" and return this string
//! \~russian Удаляет все найденные подстроки "what", возвращает эту строку
PIString & removeAll(const PIString & str);
//! \~english Remove all founded symbols "what" and return this string
//! \~russian Удаляет все найденные символы "what", возвращает эту строку
PIString & removeAll(char c) {PIDeque<PIChar>::removeAll(PIChar(c)); return *this;}
/*! \brief Repeat content of string "times" times and return this string
* \details Example: \snippet pistring.cpp PIString::repeat */
//! \~english Repeat content of string "times" times and return this string
//! \~russian Повторяет содержимое строки "times" раз и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s(" :-) ");
//! s.repeat(3);
//! piCout << s; // :-) :-) :-)
//! \endcode
//! \~\sa \a repeated()
PIString & repeat(int times) {PIString ss(*this); times--; piForTimes (times) *this += ss; return *this;}
/*! \brief Returns repeated "times" times string
* \details Example: \snippet pistring.cpp PIString::repeated */
//! \~english Returns repeated "times" times string
//! \~russian Возвращает повторённую "times" раз строку
//! \~\details
//! \~\code
//! PIString s(" :-) ");
//! piCout << s.repeated(3); // :-) :-) :-)
//! piCout << s; // :-)
//! \endcode
//! \~\sa \a repeat()
PIString repeated(int times) const {PIString ss(*this); return ss.repeat(times);}
/*! \brief Insert symbol "c" after index "index" and return this string
* \details Example: \snippet pistring.cpp PIString::insert_0 */
//! \~english Insert symbol "c" after index "index" and return this string
//! \~russian Вставляет символ "c" после позиции "index" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("pp");
//! s.insert(1, "i");
//! piCout << s; // s = "pip"
//! \endcode
PIString & insert(const int index, const PIChar c) {PIDeque<PIChar>::insert(index, c); return *this;}
/*! \brief Insert symbol "c" after index "index" and return this string
* \details Example: \snippet pistring.cpp PIString::insert_1 */
//! \~english Insert symbol "c" after index "index" and return this string
//! \~russian Вставляет символ "c" после позиции "index" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("pp");
//! s.insert(1, 'i');
//! piCout << s; // s = "pip"
//! \endcode
PIString & insert(const int index, const char c) {return insert(index, PIChar(c));}
/*! \brief Insert string "str" after index "index" and return this string
* \details Example: \snippet pistring.cpp PIString::insert_2 */
//! \~english Insert string "str" after index "index" and return this string
//! \~russian Вставляет строку "str" после позиции "index" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("stg");
//! s.insert(2, "rin");
//! piCout << s; // s = "string"
//! \endcode
PIString & insert(const int index, const PIString & str);
/*! \brief Insert string "str" after index "index" and return this string
* \details Example: \snippet pistring.cpp PIString::insert_2 */
//! \~english Insert string "str" after index "index" and return this string
//! \~russian Вставляет строку "str" после позиции "index" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("stg");
//! s.insert(2, "rin");
//! piCout << s; // s = "string"
//! \endcode
PIString & insert(const int index, const char * c) {return insert(index, PIString(c));}
/*! \brief Enlarge string to length "len" by addition sequence of symbols
* "c" at the end of string, and return this string
* \details Example: \snippet pistring.cpp PIString::expandRightTo
* \sa \a expandLeftTo() */
//! \~english Enlarge string to length "len" by addition symbols "c" at the end, and return this string
//! \~russian Увеличивает длину строки до "len" добавлением символов "c" в конец и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("str");
//! s.expandRightTo(2, "_");
//! piCout << s; // s = "str"
//! s.expandRightTo(6, "_");
//! piCout << s; // s = "str___"
//! \endcode
//! \~\sa \a expandLeftTo(), \a expandedRightTo(), \a expandedLeftTo()
PIString & expandRightTo(const int len, const PIChar c) {if (len > length()) resize(len, c); return *this;}
/*! \brief Enlarge string to length "len" by addition sequence of symbols
* "c" at the beginning of string, and return this string
* \details Example: \snippet pistring.cpp PIString::expandLeftTo
* \sa \a expandRightTo() */
//! \~english Enlarge string to length "len" by addition symbols "c" at the begin, and return this string
//! \~russian Увеличивает длину строки до "len" добавлением символов "c" в начало и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("str");
//! s.expandLeftTo(2, "_");
//! piCout << s; // s = "str"
//! s.expandLeftTo(6, "_");
//! piCout << s; // s = "___str"
//! \endcode
//! \~\sa \a expandRightTo(), \a expandedRightTo(), \a expandedLeftTo()
PIString & expandLeftTo(const int len, const PIChar c) {if (len > length()) insert(0, PIString(len - length(), c)); return *this;}
/*! \brief Enlarge and returns copy of this string to length "len"
* by addition sequence of symbols "c" at the end of string
* \sa \a expandRightTo() */
//! \~english Enlarge copy of this string to length "len" by addition symbols "c" at the end
//! \~russian Увеличивает длину копии этой строки до "len" добавлением символов "c" в конец
//! \~\details
//! \~\code
//! PIString s("str");
//! piCouy << s.expandedRightTo(5, "_"); // s = "str__"
//! piCout << s; // s = "str"
//! \endcode
//! \~\sa \a expandRightTo(), \a expandLeftTo(), \a expandedLeftTo()
PIString expandedRightTo(const int len, const PIChar c) const {return PIString(*this).expandRightTo(len, c);}
/*! \brief Enlarge and returns copy of this string to length "len"
* by addition sequence of symbols "c" at the beginning of string
* \sa \a expandLeftTo() */
//! \~english Enlarge copy of this string to length "len" by addition symbols "c" at the begin
//! \~russian Увеличивает длину копии этой строки до "len" добавлением символов "c" в начало
//! \~\details
//! \~\code
//! PIString s("str");
//! piCouy << s.expandedLeftTo(5, "_"); // s = "__str"
//! piCout << s; // s = "str"
//! \endcode
//! \~\sa \a expandRightTo(), \a expandLeftTo(), \a expandedRightTo()
PIString expandedLeftTo(const int len, const PIChar c) const {return PIString(*this).expandLeftTo(len, c);}
/*! \brief Add "c" symbols at the beginning and end of the string, and return this string
* \sa \a quoted() */
//! \~english Add "c" symbols at the beginning and end, and return this string
//! \~russian Добавляет символ "c" в начало и конец и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("str");
//! s.quote();
//! piCout << s; // s = ""str""
//! \endcode
//! \~\sa \a quoted()
PIString & quote(PIChar c = PIChar('"')) {insert(0, c); *this += c; return *this;}
/*! \brief Return quoted copy of this string
* \sa \a quote() */
//! \~english Returns quoted copy of this string
//! \~russian Возвращает копию строки с добавленным в начало и конец символом "c"
//! \~\details
//! \~\code
//! PIString s("str");
//! piCout << s.quoted(); // s = ""str""
//! piCout << s; // s = "str"
//! \endcode
//! \~\sa \a quote()
PIString quoted(PIChar c = PIChar('"')) {return PIString(*this).quote(c);}
/*! \brief Reverse string and return this string
* \details Example: \snippet pistring.cpp PIString::reverse
* \sa \a reversed() */
//! \~english Reverse string and return this string
//! \~russian Разворачивает и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s("0123456789");
//! s.reverse();
//! piCout << s; // s = "9876543210"
//! \endcode
//! \~\sa \a reversed()
PIString & reverse() {PIString str(*this); clear(); piForeachCR (PIChar c, str) push_back(c); return *this;}
/*! \brief Reverse copy of this string and return it
* \details Example: \snippet pistring.cpp PIString::reversed
* \sa \a reverse() */
//! \~english Reverse copy of this string
//! \~russian Разворачивает копию этой строки
//! \~\details
//! \~\code
//! PIString s("0123456789");
//! piCout << s.reversed(); // s = "9876543210"
//! piCout << s; // s = "0123456789"
//! \endcode
//! \~\sa \a reverse()
PIString reversed() const {PIString str(*this); str.reverse(); return str;}
/*! \brief Elide string to maximum size \"size\" and return this string
* \sa \a elided() */
//! \~english Fit string to maximum size "size" by inserting ".." at position "pos" and return this string
//! \~russian Уменьшает строку до размера "size", вставляя ".." в положение "pos" и возвращает эту строку
//! \~\sa \a elided()
PIString & elide(int size, float pos = ElideCenter);
/*! \brief Elide copy of this string to maximum size \"size\" and return it
* \details Example: \snippet pistring.cpp PIString::elided
* \sa \a elide() */
//! \~english Fit copy of this string to maximum size "size" by inserting ".." at position "pos"
//! \~russian Уменьшает копию этой строки до размера "size", вставляя ".." в положение "pos"
//! \~\details
//! \~\code
//! 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
//! \endcode
//! \~\sa \a elide()
PIString elided(int size, float pos = ElideCenter) const {PIString str(*this); str.elide(size, pos); return str;}
/*! \brief Take a part of string from symbol at index "start" and maximum length "len" and return it
* \sa \a takeLeft, \a takeRight() */
//! \~english Take a part of string from symbol at index "start" and maximum length "len" and return it
//! \~russian Извлекает часть строки от символа "start" максимальной длины "len" и возвращает её
//! \~\details
//! \~\code
//! PIString s("0123456789");
//! piCout << s.takeMid(1, 3); // "123"
//! piCout << s; // s = "0456789"
//! \endcode
//! \~\sa \a takeLeft, \a takeRight()
PIString takeMid(const int start, const int len = -1) {PIString ret(mid(start, len)); cutMid(start, len); return ret;}
/*! \brief Take a part from the begin of string with maximum length "len" and return it
* \sa \a takeMid(), \a takeRight() */
//! \~english Take a part from the begin of string with maximum length "len" and return it
//! \~russian Извлекает часть строки от начала максимальной длины "len" и возвращает её
//! \~\details
//! \~\code
//! PIString s("0123456789");
//! piCout << s.takeLeft(3); // "012"
//! piCout << s; // s = "3456789"
//! \endcode
//! \~\sa \a takeMid(), \a takeRight()
PIString takeLeft(const int len) {PIString ret(left(len)); cutLeft(len); return ret;}
/*! \brief Take a part from the end of string with maximum length "len" and return it
* \sa \a takeMid(), \a takeLeft() */
//! \~english Take a part from the end of string with maximum length "len" and return it
//! \~russian Извлекает часть строки с конца максимальной длины "len" и возвращает её
//! \~\details
//! \~\code
//! PIString s("0123456789");
//! piCout << s.takeRight(3); // "789"
//! piCout << s; // s = "0123456"
//! \endcode
//! \~\sa \a takeMid(), \a takeLeft()
PIString takeRight(const int len) {PIString ret(right(len)); cutRight(len); return ret;}
/*! \brief Take a symbol from the begin of this string and return it
* \details Example: \snippet pistring.cpp PIString::takeSymbol
* \sa \a takeWord(), \a takeCWord(), \a takeLine(), \a takeNumber(), \a takeRange() */
//! \~english Take a symbol from the begin of this string and return it
//! \~russian Извлекает символ с начала строки и возвращает его как строку
PIString takeSymbol();
/*! \brief Take a word from the begin of this string and return it
* \details Example: \snippet pistring.cpp PIString::takeWord
* \sa \a takeSymbol(), \a takeCWord(), \a takeLine(), \a takeNumber(), \a takeRange() */
//! \~english Take a word from the begin of this string and return it
//! \~russian Извлекает слово с начала строки и возвращает его
PIString takeWord();
/*! \brief Take a word with letters, numbers and '_' symbols from the
* begin of this string and return it
* \details Example: \snippet pistring.cpp PIString::takeCWord
* \sa \a takeSymbol(), \a takeWord(), \a takeLine(), \a takeNumber(), \a takeRange() */
//! \~english Take a word with letters, numbers and '_' symbols from the begin of this string and return it
//! \~russian Извлекает слово из букв, цифр и симолов '_' с начала строки и возвращает его
PIString takeCWord();
/*! \brief Take a line from the begin of this string and return it
* \details Example: \snippet pistring.cpp PIString::takeLine
* \sa \a takeSymbol(), \a takeWord(), \a takeCWord(), \a takeNumber(), \a takeRange() */
//! \~english Take a line from the begin of this string and return it
//! \~russian Извлекает строку текста (до новой строки) с начала строки и возвращает её
PIString takeLine();
/*! \brief Take a number with C-format from the begin of this string and return it
* \details Example: \snippet pistring.cpp PIString::takeNumber
* \sa \a takeSymbol(), \a takeWord(), \a takeCWord(), \a takeLine(), \a takeRange() */
//! \~english Take a number with C-format from the begin of this string and return it
//! \~russian Извлекает число в C-формате с начала строки и возвращает его как строку
PIString takeNumber();
/*! \brief Take a range between "start" and "end" symbols from the begin of this
* string and return it.
* \details "Shield" symbol prevent analysis of the next symbol.
* Example: \snippet pistring.cpp PIString::takeRange
* \sa \a takeSymbol(), \a takeWord(), \a takeLine(), \a takeNumber() */
//! \~english Take a range between "start" and "end" symbols from the begin of this string and return it
//! \~russian Извлекает диапазон между символами "start" и "end" с начала строки и возвращает его
PIString takeRange(const PIChar start, const PIChar end, const PIChar shield = '\\');
/*! \brief Return a string in brackets "start" and "end" symbols from the begin of this
* string and return it.
* \details Example: string = "a(b(c)d)e"; inBrackets('(', ')') = "b(c)d"; */
//! \~english Returns string in brackets "start" and "end" symbols from the beginning
//! \~russian Возвращает строку между символами "start" и "end" с начала строки
PIString inBrackets(const PIChar start, const PIChar end) const;
/*! \brief Return real bytes count of this string
* \details It`s equivalent length of char sequence
* returned by function \a data() - 1, without terminating null-char \n
* Example: \snippet pistring.cpp PIString::lengthAscii
* \sa \a data() */
int lengthAscii() const {buildData(__syslocname__); return data_.size_s() - 1;}
//! \~english Returns bytes count of this string in system codepage
//! \~russian Возвращает объем строки в системной кодировке
int lengthAscii() const;
/*! \brief Return \c char * representation of this string in system codepage
* \details This function fill buffer by sequence
* of chars. Minimum length of this buffer is count
* of symbols. Returned \c char * is valid until next
* execution of this function.\n
* Example: \snippet pistring.cpp PIString::data
* \sa \a dataConsole(), \a dataUTF8() */
const char * data() const {buildData(__syslocname__); return (const char *)(data_.data());}
//! \~english Returns \c char * representation of this string in system codepage
//! \~russian Возвращает \c char * представление строки в системной кодировке
const char * data() const;
/*! \brief Return \c char * representation of this string in terminal codepage
* \details This function fill buffer by sequence
* of chars. Minimum length of this buffer is count
* of symbols. Returned \c char * is valid until next
* execution of this function.\n
* \sa \a data(), \a dataUTF8() */
//! \~english Returns \c char * representation of this string in terminal codepage
//! \~russian Возвращает \c char * представление строки в кодировке консоли
const char * dataConsole() const;
/*! \brief Return \c char * representation of this string in UTF-8
* \details This function fill buffer by sequence
* of chars. Minimum length of this buffer is count
* of symbols. Returned \c char * is valid until next
* execution of this function.\n
* \sa \a data(), \a dataConsole() */
//! \~english Returns \c char * representation of this string in UTF-8
//! \~russian Возвращает \c char * представление строки в кодировке UTF-8
const char * dataUTF8() const;
/*! \brief Return \c char * representation of this string in ASCII
* \details This function fill buffer by sequence
* of chars. Minimum length of this buffer is count
* of symbols. Returned \c char * is valid until next
* execution of this function.\n */
//! \~english Returns \c char * representation of this string in ASCII
//! \~russian Возвращает \c char * представление строки в кодировке ASCII
const char * dataAscii() const;
//! Returns hash
//! \~english Returns hash
//! \~russian Возвращает хэш
uint hash() const;
//! \brief Return \a PIByteArray contains \a data() of this string without terminating null-char
//! \~english Returns \a PIByteArray contains \a data() of this string without terminating null-char
//! \~russian Возвращает \a PIByteArray содержащий \a data() строки без завершающего нулевого байта
PIByteArray toByteArray() const {buildData(__utf8name__); return data_.resized(data_.size_s() - 1);}
//! \brief Return \a PIByteArray contains UTF-8 \a data() of this string without terminating null-char
//! \~english Returns \a PIByteArray contains \a dataUTF8() of this string without terminating null-char
//! \~russian Возвращает \a PIByteArray содержащий \a dataUTF8() строки без завершающего нулевого байта
PIByteArray toUTF8() const;
//! \brief Return \a PIByteArray contains custom charset representation of this string without terminating null-char
//! \~english Returns \a PIByteArray contains custom charset representation of this string without terminating null-char
//! \~russian Возвращает \a PIByteArray содержащий строку в указанной кодировке без завершающего нулевого байта
PIByteArray toCharset(const char * c) const;
/*! \brief Split string with delimiter "delim" to \a PIStringList and return it
* \details Example: \snippet pistring.cpp PIString::split */
//! \~english Split string with delimiter "delim" to \a PIStringList
//! \~russian Разделяет строку в \a PIStringList через разделитель "delim"
//! \~\details
//! \~\code
//! PIString s("1 2 3");
//! piCout << s.split(" "); // {"1", "2", "3"}
//! \endcode
PIStringList split(const PIString & delim) const;
//! \brief Convert each symbol in copyed string to upper case and return it
//! \~english Convert each symbol in copied string to upper case
//! \~russian Преобразует каждый символ в скопированной строке в верхний регистр
PIString toUpperCase() const;
//! \brief Convert each symbol in copyed string to lower case and return it
//! \~english Convert each symbol in copied string to lower case
//! \~russian Преобразует каждый символ в скопированной строке в нижний регистр
PIString toLowerCase() const;
PIString toNativeDecimalPoints() const;
//! \brief Returns if string contains "c"
//! \~english Returns if string contains symbol "c"
//! \~russian Возвращает содержит ли строка символ "c"
bool contains(const char c) const {return PIDeque<PIChar>::contains(PIChar(c));}
//! \brief Returns if string contains "str"
//! \~english Returns if string contains substring "str"
//! \~russian Возвращает содержит ли строка подстроку "str"
bool contains(const char * str) const {return contains(PIString(str));}
//! \brief Returns if string contains "str"
//! \~english Returns if string contains substring "str"
//! \~russian Возвращает содержит ли строка подстроку "str"
bool contains(const PIString & str) const {return find(str) >= 0;}
//! \brief Search symbol "c" from symbol at index "start" and return first occur position
//! \details Example: \snippet pistring.cpp PIString::find
//! \~english Search symbol "c" from symbol at index "start" and return first occur position
//! \~russian Ищет символ "c" от символа "start" и возвращает первое вхождение
int find(const char c, const int start = 0) const;
//! \brief Search substring "str" from symbol at index "start" and return first occur position
//! \details Example: \snippet pistring.cpp PIString::find
//! \~english Search substring "str" from symbol at index "start" and return first occur position
//! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение
int find(const PIString & str, const int start = 0) const;
//! \brief Search substring "str" from symbol at index "start" and return first occur position
//! \details Example: \snippet pistring.cpp PIString::find
//! \~english Search substring "str" from symbol at index "start" and return first occur position
//! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение
//! \~\details
//! \~\code
//! PIString s("012345012345");
//! piCout << s.find("-"); // -1
//! piCout << s.find("34"); // 3
//! piCout << s.find("3", 4); // 9
//! piCout << s.find("3", 10); // -1
//! \endcode
//! \~\sa \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
int find(const char * str, const int start = 0) const {return find(PIString(str), start);}
//! \brief Search symbol "c" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findLast
int findLast(const char c, const int start = 0) const;
//! \brief Search substring "str" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findLast
int findLast(const PIString & str, const int start = 0) const;
//! \brief Search substring "str" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findLast
int findLast(const char * str, const int start = 0) const {return findLast(PIString(str), start);}
//! \brief Search word "word" from symbol at index "start" and return first occur position.
//! \details Example: \snippet pistring.cpp PIString::findWord
int findWord(const PIString & word, const int start = 0) const;
//! \brief Search C-style word "word" from symbol at index "start" and return first occur position.
//! \details Example: \snippet pistring.cpp PIString::findCWord
int findCWord(const PIString & word, const int start = 0) const;
//! \brief Search range between "start" and "end" symbols at index "start_index" and return first occur position.
//! \details Example: \snippet pistring.cpp PIString::findRange
int findRange(const PIChar start, const PIChar end, const PIChar shield = '\\', const int start_index = 0, int * len = 0) const;
//! \brief Search any symbol of "str" from symbol at index "start" and return first occur position
//! \details Example: \snippet pistring.cpp PIString::findAny
//! \~english Search any symbol of "str" from symbol at index "start" and return first occur position
//! \~russian Ищет любой символ строки "str" от симола "start" и возвращает первое вхождение
int findAny(const PIString & str, const int start = 0) const;
//! \brief Search any symbol of "str" from symbol at index "start" and return first occur position
//! \details Example: \snippet pistring.cpp PIString::findAny
//! \~english Search any symbol of "str" from symbol at index "start" and return first occur position
//! \~russian Ищет любой символ строки "str" от симола "start" и возвращает первое вхождение
//! \~\details
//! \~\code
//! piCout << PIString("1.str").findAny(".,:"); // 1
//! piCout << PIString("1,str").findAny(".,:"); // 1
//! piCout << PIString("1:str").findAny(".,:"); // 1
//! \endcode
//! \~\sa \a find(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
int findAny(const char * str, const int start = 0) const {return findAny(PIString(str), start);}
//! \brief Search any symbol of "str" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findAnyLast
//! \~english Search symbol "c" from symbol at index "start" and return last occur position
//! \~russian Ищет символ "c" от символа "start" и возвращает последнее вхождение
int findLast(const char c, const int start = 0) const;
//! \~english Search substring "str" from symbol at index "start" and return last occur position
//! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение
int findLast(const PIString & str, const int start = 0) const;
//! \~english Search substring "str" from symbol at index "start" and return last occur position
//! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение
//! \~\details
//! \~\code
//! PIString s("012345012345");
//! piCout << s.findLast("-"); // -1
//! piCout << s.findLast("34"); // 9
//! piCout << s.findLast("3", 4); // 9
//! piCout << s.findLast("3", 10); // -1
//! \endcode
//! \~\sa \a find(), \a findAny(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
int findLast(const char * str, const int start = 0) const {return findLast(PIString(str), start);}
//! \~english Search any symbol of "str" from symbol at index "start" and return last occur position
//! \~russian Ищет любой символ строки "str" от символа "start" и возвращает последнее вхождение
int findAnyLast(const PIString & str, const int start = 0) const;
//! \brief Search any symbol of "str" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findAnyLast
//! \~english Search any symbol of "str" from symbol at index "start" and return last occur position
//! \~russian Ищет любой символ строки "str" от символа "start" и возвращает последнее вхождение
//! \~\details
//! \~\code
//! piCout << PIString(".str.0").findAnyLast(".,:"); // 4
//! piCout << PIString(".str,0").findAnyLast(".,:"); // 4
//! piCout << PIString(".str:0").findAnyLast(".,:"); // 4
//! \endcode
//! \~\sa \a find(), \a findAny(), \a findLast(), \a findWord(), \a findCWord(), \a findRange()
int findAnyLast(const char * str, const int start = 0) const {return findAnyLast(PIString(str), start);}
//! \brief Returns number of occurrences of symbol "c"
//! \~english Search word "word" from symbol at index "start" and return first occur position
//! \~russian Ищет слово "word" от симола "start" и возвращает первое вхождение
int findWord(const PIString & word, const int start = 0) const;
//! \~english Search C-word "word" from symbol at index "start" and return first occur position
//! \~russian Ищет C-слово "word" от симола "start" и возвращает первое вхождение
int findCWord(const PIString & word, const int start = 0) const;
//! \~english Search range start between "start" and "end" symbols at index "start_index" and return first occur position
//! \~russian Ищет начало диапазона между символами "start" и "end" от симола "start" и возвращает первое вхождение
int findRange(const PIChar start, const PIChar end, const PIChar shield = '\\', const int start_index = 0, int * len = 0) const;
//! \~english Returns number of occurrences of symbol "c"
//! \~russian Возвращает число вхождений символа "c"
//! \~\details
//! \~\code
//! piCout << PIString(".str.0").entries("."); // 2
//! piCout << PIString(".str.0").entries("0"); // 1
//! \endcode
int entries(const PIChar c) const;
//! \brief Returns number of occurrences of symbol "c"
//! \~english Returns number of occurrences of symbol "c"
//! \~russian Возвращает число вхождений символа "c"
//! \~\details
//! \~\code
//! piCout << PIString(".str.0").entries('.'); // 2
//! piCout << PIString(".str.0").entries('0'); // 1
//! \endcode
int entries(char c) const {return entries(PIChar(c));}
//! \brief Return if string starts with "str"
//! \~english Returns if string starts with "str"
//! \~russian Возвращает начинается ли строка со "str"
bool startsWith(const PIString & str) const;
//! \brief Return if string ends with "str"
//! \~english Returns if string ends with "str"
//! \~russian Возвращает оканчивается ли строка на "str"
bool endsWith(const PIString & str) const;
//! \brief Return symbols length of string
//! \~english Returns symbols length of string
//! \~russian Возвращает длину строки в символах
int length() const {return size();}
//! \brief Return \c true if string is empty, i.e. length = 0
//! \~english Returns \c true if string is empty, i.e. length = 0
//! \~russian Возвращает \c true если строка пустая, т.е. длина = 0
bool isEmpty() const {return (size() == 0 || *this == "");}
//! \~english Returns \c true if string is not empty, i.e. length > 0
//! \~russian Возвращает \c true если строка непустая, т.е. длина > 0
bool isNotEmpty() const {return !isEmpty();}
//! \brief Return \c true if string equal "true", "yes", "on" or positive not null numeric value
//! \~english Returns \c true if string equal "true", "yes", "on" or positive not null numeric value
//! \~russian Возвращает \c true если строка равна "true", "yes", "on" или числу > 0
bool toBool() const;
//! \brief Return \c char numeric value of string
//! \~english Returns \c char numeric value of string
//! \~russian Возвращает \c char числовое значение строки
char toChar() const;
//! \brief Return \c short numeric value of string in base "base"
//! \details Example: \snippet pistring.cpp PIString::toNumber
//! \~english Returns \c short numeric value of string in base "base"
//! \~russian Возвращает \c short числовое значение строки по основанию "base"
//! \~\details
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
//! \~\code
//! piCout << PIString("123").toShort(); // 123
//! piCout << PIString("123").toShort(16); // 291
//! piCout << PIString("0x123").toShort(); // 291
//! piCout << PIString("1001").toShort(2); // 9
//! \endcode
short toShort(int base = -1, bool * ok = 0) const {return short(toNumberBase(*this, base, ok));}
//! \brief Return \c ushort numeric value of string in base "base"
//! \details Example: \snippet pistring.cpp PIString::toNumber
//! \~english Returns \c ushort numeric value of string in base "base"
//! \~russian Возвращает \c ushort числовое значение строки по основанию "base"
//! \~\details
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
//! \~\code
//! piCout << PIString("123").toUShort(); // 123
//! piCout << PIString("123").toUShort(16); // 291
//! piCout << PIString("0x123").toUShort(); // 291
//! piCout << PIString("1001").toUShort(2); // 9
//! \endcode
ushort toUShort(int base = -1, bool * ok = 0) const {return ushort(toNumberBase(*this, base, ok));}
//! \brief Return \c int numeric value of string in base "base"
//! \details Example: \snippet pistring.cpp PIString::toNumber
//! \~english Returns \c int numeric value of string in base "base"
//! \~russian Возвращает \c int числовое значение строки по основанию "base"
//! \~\details
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
//! \~\code
//! piCout << PIString("123").toInt(); // 123
//! piCout << PIString("123").toInt(16); // 291
//! piCout << PIString("0x123").toInt(); // 291
//! piCout << PIString("1001").toInt(2); // 9
//! \endcode
int toInt(int base = -1, bool * ok = 0) const {return int(toNumberBase(*this, base, ok));}
//! \brief Return \c uint numeric value of string in base "base"
//! \details Example: \snippet pistring.cpp PIString::toNumber
//! \~english Returns \c uint numeric value of string in base "base"
//! \~russian Возвращает \c uint числовое значение строки по основанию "base"
//! \~\details
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
//! \~\code
//! piCout << PIString("123").toUInt(); // 123
//! piCout << PIString("123").toUInt(16); // 291
//! piCout << PIString("0x123").toUInt(); // 291
//! piCout << PIString("1001").toUInt(2); // 9
//! \endcode
uint toUInt(int base = -1, bool * ok = 0) const {return uint(toNumberBase(*this, base, ok));}
//! \brief Return \c long numeric value of string in base "base"
//! \details Example: \snippet pistring.cpp PIString::toNumber
//! \~english Returns \c long numeric value of string in base "base"
//! \~russian Возвращает \c long числовое значение строки по основанию "base"
//! \~\details
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
//! \~\code
//! piCout << PIString("123").toLong(); // 123
//! piCout << PIString("123").toLong(16); // 291
//! piCout << PIString("0x123").toLong(); // 291
//! piCout << PIString("1001").toLong(2); // 9
//! \endcode
long toLong(int base = -1, bool * ok = 0) const {return long(toNumberBase(*this, base, ok));}
//! \brief Return \c ulong numeric value of string in base "base"
//! \details Example: \snippet pistring.cpp PIString::toNumber
//! \~english Returns \c ulong numeric value of string in base "base"
//! \~russian Возвращает \c ulong числовое значение строки по основанию "base"
//! \~\details
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
//! \~\code
//! piCout << PIString("123").toULong(); // 123
//! piCout << PIString("123").toULong(16); // 291
//! piCout << PIString("0x123").toULong(); // 291
//! piCout << PIString("1001").toULong(2); // 9
//! \endcode
ulong toULong(int base = -1, bool * ok = 0) const {return ulong(toNumberBase(*this, base, ok));}
//! \brief Return \c llong numeric value of string in base "base"
//! \details Example: \snippet pistring.cpp PIString::toNumber
//! \~english Returns \c llong numeric value of string in base "base"
//! \~russian Возвращает \c llong числовое значение строки по основанию "base"
//! \~\details
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
//! \~\code
//! piCout << PIString("123").toLLong(); // 123
//! piCout << PIString("123").toLLong(16); // 291
//! piCout << PIString("0x123").toLLong(); // 291
//! piCout << PIString("1001").toLLong(2); // 9
//! \endcode
llong toLLong(int base = -1, bool * ok = 0) const {return toNumberBase(*this, base, ok);}
//! \brief Return \c ullong numeric value of string in base "base"
//! \details Example: \snippet pistring.cpp PIString::toNumber
//! \~english Returns \c ullong numeric value of string in base "base"
//! \~russian Возвращает \c ullong числовое значение строки по основанию "base"
//! \~\details
//! \~english If "base" < 0 then base automatically select 16 if string start with "0x", therwise 10
//! \~russian Если "base" < 0 тогда основание автоматически принимается 16 если строка начинается с "0x", иначе 10
//! \~\code
//! piCout << PIString("123").toULLong(); // 123
//! piCout << PIString("123").toULLong(16); // 291
//! piCout << PIString("0x123").toULLong(); // 291
//! piCout << PIString("1001").toULLong(2); // 9
//! \endcode
ullong toULLong(int base = -1, bool * ok = 0) const {return ullong(toNumberBase(*this, base, ok));}
//! \brief Return \c float numeric value of string
//! \details Example: \snippet pistring.cpp PIString::toFloat
//! \~english Returns \c float numeric value of string
//! \~russian Возвращает \c float числовое значение строки
//! \~\details
//! \~\code
//! piCout << PIString("123").toFloat(); // 123
//! piCout << PIString("1.2E+2").toFloat(); // 120
//! piCout << PIString("0.01").toFloat(); // 0.01
//! \endcode
float toFloat() const;
//! \brief Return \c double numeric value of string
//! \details Example: \snippet pistring.cpp PIString::toFloat
//! \~english Returns \c double numeric value of string
//! \~russian Возвращает \c double числовое значение строки
//! \~\details
//! \~\code
//! piCout << PIString("123").toDouble(); // 123
//! piCout << PIString("1.2E+2").toDouble(); // 120
//! piCout << PIString("0.01").toDouble(); // 0.01
//! \endcode
double toDouble() const;
//! \brief Return \c ldouble numeric value of string
//! \details Example: \snippet pistring.cpp PIString::toFloat
//! \~english Returns \c ldouble numeric value of string
//! \~russian Возвращает \c ldouble числовое значение строки
//! \~\details
//! \~\code
//! piCout << PIString("123").toLDouble(); // 123
//! piCout << PIString("1.2E+2").toLDouble(); // 120
//! piCout << PIString("0.01").toLDouble(); // 0.01
//! \endcode
ldouble toLDouble() const;
//! \brief Set string content to numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::setNumber
//! \~english Set string content to text representation of "value" in base "base" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! s.setNumber(123);
//! piCout << s; // 123
//! s.setNumber(123, 16);
//! piCout << s; // 7B
//! \endcode
PIString & setNumber(const short value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
//! \brief Set string content to numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::setNumber
//! \~english Set string content to text representation of "value" in base "base" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! s.setNumber(123);
//! piCout << s; // 123
//! s.setNumber(123, 16);
//! piCout << s; // 7B
//! \endcode
PIString & setNumber(const ushort value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
//! \brief Set string content to numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::setNumber
//! \~english Set string content to text representation of "value" in base "base" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! s.setNumber(123);
//! piCout << s; // 123
//! s.setNumber(123, 16);
//! piCout << s; // 7B
//! \endcode
PIString & setNumber(const int value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
//! \brief Set string content to numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::setNumber
//! \~english Set string content to text representation of "value" in base "base" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! s.setNumber(123);
//! piCout << s; // 123
//! s.setNumber(123, 16);
//! piCout << s; // 7B
//! \endcode
PIString & setNumber(const uint value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
//! \brief Set string content to numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::setNumber
//! \~english Set string content to text representation of "value" in base "base" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! s.setNumber(123);
//! piCout << s; // 123
//! s.setNumber(123, 16);
//! piCout << s; // 7B
//! \endcode
PIString & setNumber(const long value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
//! \brief Set string content to numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::setNumber
//! \~english Set string content to text representation of "value" in base "base" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! s.setNumber(123);
//! piCout << s; // 123
//! s.setNumber(123, 16);
//! piCout << s; // 7B
//! \endcode
PIString & setNumber(const ulong value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
//! \brief Set string content to numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::setNumber
//! \~english Set string content to text representation of "value" in base "base" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! s.setNumber(123);
//! piCout << s; // 123
//! s.setNumber(123, 16);
//! piCout << s; // 7B
//! \endcode
PIString & setNumber(const llong & value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
//! \brief Set string content to numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::setNumber
//! \~english Set string content to text representation of "value" in base "base" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! s.setNumber(123);
//! piCout << s; // 123
//! s.setNumber(123, 16);
//! piCout << s; // 7B
//! \endcode
PIString & setNumber(const ullong & value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
//! \brief Set string content to numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::setFloat
//! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! 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
//! \endcode
PIString & setNumber(const float value, char format = 'f', int precision = 8) {clear(); *this += PIString::fromNumber(value, format, precision); return *this;}
//! \brief Set string content to numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::setFloat
//! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! 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
//! \endcode
PIString & setNumber(const double & value, char format = 'f', int precision = 8) {clear(); *this += PIString::fromNumber(value, format, precision); return *this;}
//! \brief Set string content to numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::setFloat
//! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string
//! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку
//! \~\details
//! \~\code
//! PIString s;
//! 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
//! \endcode
PIString & setNumber(const ldouble & value, char format = 'f', int precision = 8) {clear(); *this += PIString::fromNumber(value, format, precision); return *this;}
//! \brief Set string content to human readable size in B/kB/MB/GB/TB
//! \details Example: \snippet pistring.cpp PIString::setReadableSize
//! \~english Set string content to human readable size in B/kB/MB/GB/TB/PB
//! \~russian Устанавливает содержимое в строку с читаемым размером B/kB/MB/GB/TB/PB
//! \~\sa PIString::readableSize()
PIString & setReadableSize(llong bytes);
//! \brief Return string contains numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::fromNumber
//! \~english Returns string contains numeric representation of "value" in base "base"
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
//! \~\details
//! \~\code
//! piCout << PIString::fromNumber(123); // 123
//! piCout << PIString::fromNumber(123, 16); // 7B
//! \endcode
static PIString fromNumber(const short value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
//! \brief Return string contains numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::fromNumber
//! \~english Returns string contains numeric representation of "value" in base "base"
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
//! \~\details
//! \~\code
//! piCout << PIString::fromNumber(123); // 123
//! piCout << PIString::fromNumber(123, 16); // 7B
//! \endcode
static PIString fromNumber(const ushort value, int base = 10, bool * ok = 0) {return fromNumberBaseU(ullong(value), base, ok);}
//! \brief Return string contains numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::fromNumber
//! \~english Returns string contains numeric representation of "value" in base "base"
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
//! \~\details
//! \~\code
//! piCout << PIString::fromNumber(123); // 123
//! piCout << PIString::fromNumber(123, 16); // 7B
//! \endcode
static PIString fromNumber(const int value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
//! \brief Return string contains numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::fromNumber
//! \~english Returns string contains numeric representation of "value" in base "base"
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
//! \~\details
//! \~\code
//! piCout << PIString::fromNumber(123); // 123
//! piCout << PIString::fromNumber(123, 16); // 7B
//! \endcode
static PIString fromNumber(const uint value, int base = 10, bool * ok = 0) {return fromNumberBaseU(ullong(value), base, ok);}
//! \brief Return string contains numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::fromNumber
//! \~english Returns string contains numeric representation of "value" in base "base"
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
//! \~\details
//! \~\code
//! piCout << PIString::fromNumber(123); // 123
//! piCout << PIString::fromNumber(123, 16); // 7B
//! \endcode
static PIString fromNumber(const long value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
//! \brief Return string contains numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::fromNumber
//! \~english Returns string contains numeric representation of "value" in base "base"
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
//! \~\details
//! \~\code
//! piCout << PIString::fromNumber(123); // 123
//! piCout << PIString::fromNumber(123, 16); // 7B
//! \endcode
static PIString fromNumber(const ulong value, int base = 10, bool * ok = 0) {return fromNumberBaseU(ullong(value), base, ok);}
//! \brief Return string contains numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::fromNumber
//! \~english Returns string contains numeric representation of "value" in base "base"
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
//! \~\details
//! \~\code
//! piCout << PIString::fromNumber(123); // 123
//! piCout << PIString::fromNumber(123, 16); // 7B
//! \endcode
static PIString fromNumber(const llong & value, int base = 10, bool * ok = 0) {return fromNumberBaseS(value, base, ok);}
//! \brief Return string contains numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::fromNumber
//! \~english Returns string contains numeric representation of "value" in base "base"
//! \~russian Возвращает строковое представление числа "value" по основанию "base"
//! \~\details
//! \~\code
//! piCout << PIString::fromNumber(123); // 123
//! piCout << PIString::fromNumber(123, 16); // 7B
//! \endcode
static PIString fromNumber(const ullong & value, int base = 10, bool * ok = 0) {return fromNumberBaseU(value, base, ok);}
//! \brief Return string contains numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::fromFloat
//! \~english Returns string contains numeric representation of "value" with format "format" and precision "precision"
//! \~russian Возвращает строковое представление числа "value" в формате "format" и точностью "precision"
//! \~\details
//! \~\code
//! 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
//! \endcode
static PIString fromNumber(const float value, char format = 'f', int precision = 8) {return ftos(value, format, precision);}
//! \brief Return string contains numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::fromFloat
//! \~english Returns string contains numeric representation of "value" with format "format" and precision "precision"
//! \~russian Возвращает строковое представление числа "value" в формате "format" и точностью "precision"
//! \~\details
//! \~\code
//! 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
//! \endcode
static PIString fromNumber(const double & value, char format = 'f', int precision = 8) {return dtos(value, format, precision);}
//! \brief Return string contains numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::fromFloat
//! \~english Returns string contains numeric representation of "value" with format "format" and precision "precision"
//! \~russian Возвращает строковое представление числа "value" в формате "format" и точностью "precision"
//! \~\details
//! \~\code
//! 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
//! \endcode
static PIString fromNumber(const ldouble & value, char format = 'f', int precision = 8) {return dtos(value, format, precision);}
//! \brief Return "true" or "false"
//! \~english Returns "true" or "false"
//! \~russian Возвращает "true" или "false"
static PIString fromBool(const bool value) {return PIString(value ? "true" : "false");}
//! \brief Return string constructed from terminal codepage
//! \~english Returns string constructed from terminal codepage
//! \~russian Возвращает строку созданную из кодировки консоли
static PIString fromConsole(const char * s);
//! \brief Return string constructed from system codepage
//! \~english Returns string constructed from system codepage
//! \~russian Возвращает строку созданную из кодировки системы
static PIString fromSystem(const char * s);
//! \brief Return string constructed from UTF-8
//! \~english Returns string constructed from UTF-8
//! \~russian Возвращает строку созданную из UTF-8
static PIString fromUTF8(const char * s);
//! \brief Return string constructed from UTF-8
static PIString fromUTF8(const PIByteArray &ba);
//! \~english Returns string constructed from UTF-8
//! \~russian Возвращает строку созданную из UTF-8
static PIString fromUTF8(const PIByteArray & utf);
//! \brief Return string constructed from ASCII
//! \~english Returns string constructed from ASCII
//! \~russian Возвращает строку созданную из ASCII
static PIString fromAscii(const char * s);
//! \brief Return string constructed from "len" chars ASCII
//! \~english Returns string constructed from "len" chars ASCII
//! \~russian Возвращает строку созданную из "len" символов ASCII
static PIString fromAscii(const char * s, int len);
//! \brief Return string constructed from "c" codepage
static PIString fromCodepage(const char * s, const char * c);
//! \~english Returns string constructed from "cp" codepage
//! \~russian Возвращает строку созданную из кодировки "cp"
static PIString fromCodepage(const char * s, const char * cp);
//! \brief Return string contains human readable size in B/kB/MB/GB/TB
//! \details Example: \snippet pistring.cpp PIString::readableSize
//! \~english Returns string contains human readable size in B/kB/MB/GB/TB/PB
//! \~russian Возвращает строку с читаемым размером B/kB/MB/GB/TB/PB
//! \~\sa PIString::setReadableSize()
static PIString readableSize(llong bytes);
private:
@@ -752,40 +1350,59 @@ private:
};
//! \relatesalso PICout \brief Output operator to PICout
//! \relatesalso PICout
//! \~english Output operator to \a PICout
//! \~russian Оператор вывода в \a PICout
PIP_EXPORT PICout operator <<(PICout s, const PIString & v);
//! \relatesalso PIByteArray \brief Output operator to PIByteArray
//! \relatesalso PIByteArray
//! \~english Store operator
//! \~russian Оператор сохранения
inline PIByteArray & operator <<(PIByteArray & s, const PIString & v) {s << *(PIDeque<PIChar>*)&v; return s;}
//! \relatesalso PIByteArray \brief Input operator from PIByteArray
//! \relatesalso PIByteArray
//! \~english Restore operator
//! \~russian Оператор извлечения
inline PIByteArray & operator >>(PIByteArray & s, PIString & v) {v.clear(); s >> *(PIDeque<PIChar>*)&v; return s;}
//! \brief Return concatenated string
//! \~english Returns concatenated string
//! \~russian Возвращает соединение строк
inline PIString operator +(const PIString & str, const PIString & f) {PIString s(str); s += f; return s;}
//! \brief Return concatenated string
//! \~english Returns concatenated string
//! \~russian Возвращает соединение строк
inline PIString operator +(const PIString & f, const char * str) {PIString s(f); s += str; return s;}
//! \brief Return concatenated string
//! \~english Returns concatenated string
//! \~russian Возвращает соединение строк
inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;}
//! \relatesalso PIString \brief Return concatenated string
//! \~english Returns concatenated string
//! \~russian Возвращает соединение строк
inline PIString operator +(const char c, const PIString & f) {return PIChar(c) + f;}
//! \brief Return concatenated string
//! \~english Returns concatenated string
//! \~russian Возвращает соединение строк
inline PIString operator +(const PIString & f, const char c) {return f + PIChar(c);}
//! \relatesalso PIString
//! \~english Compare two version strings in free notation and returns 0, -1 or 1
//! \~russian Сравнивает две строки с версиями в произвольной форме и возвращает 0, -1 или 1
int PIP_EXPORT versionCompare(const PIString & v0, const PIString & v1, int components = 6);
//! \relatesalso PIString
//! \~english Converts version string in free notation to classic view
//! \~russian Преобразует строку с версией в произвольной форме к классическому виду
PIString PIP_EXPORT versionNormalize(const PIString & v);
//! \~english Returns hash of string
//! \~russian Возвращает хэш строки
template<> inline uint piHash(const PIString & s) {return s.hash();}
template<> inline void piSwap(PIString & f, PIString & s) {f.swap(s);}
#endif // PISTRING_H

View File

@@ -35,7 +35,11 @@
//! \details
//! \~english Example:
//! \~russian Пример:
//! \~\snippet pistring.cpp PIStringList::join
//! \~\code
//! PIStringList sl("1", "2");
//! sl << "3";
//! piCout << sl.join(" < "); // 1 < 2 < 3
//! \endcode
PIString PIStringList::join(const PIString & delim) const {
PIString s;
for (uint i = 0; i < size(); ++i) {
@@ -50,7 +54,12 @@ PIString PIStringList::join(const PIString & delim) const {
//! \details
//! \~english Example:
//! \~russian Пример:
//! \~\snippet pistring.cpp PIStringList::removeStrings
//! \~\code
//! PIStringList sl("1", "2");
//! sl << "1" << "2" << "3";
//! piCout << sl; // {"1", "2", "1", "2", "3"}
//! piCout << sl.removeStrings("1"); // {"2", "2", "3"}
//! \endcode
PIStringList & PIStringList::removeStrings(const PIString & value) {
for (uint i = 0; i < size(); ++i) {
if (at(i) == value) {
@@ -65,7 +74,12 @@ PIStringList & PIStringList::removeStrings(const PIString & value) {
//! \details
//! \~english Example:
//! \~russian Пример:
//! \~\snippet pistring.cpp PIStringList::removeDuplicates
//! \~\code
//! PIStringList sl("1", "2");
//! sl << "1" << "2" << "3";
//! piCout << sl; // {"1", "2", "1", "2", "3"}
//! piCout << sl.removeDuplicates(); // {"1", "2", "3"}
//! \endcode
PIStringList& PIStringList::removeDuplicates() {
PIStringList l;
PIString s;
@@ -91,7 +105,11 @@ PIStringList& PIStringList::removeDuplicates() {
//! \details
//! \~english Example:
//! \~russian Пример:
//! \~\snippet pistring.cpp PIStringList::trim
//! \~\code
//! PIStringList sl(" 1 ", "\t2", " 3\n");
//! piCout << sl; // {" 1 ", " 2", " 3\n"}
//! piCout << sl.trim(); // {"1", "2", "3"}
//! \endcode
PIStringList & PIStringList::trim() {
for (uint i = 0; i < size(); ++i)
(*this)[i].trim();