version 0.5.0_alpha

git-svn-id: svn://db.shs.com.ru/pip@8 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-03-10 10:13:18 +00:00
parent b1f651ab62
commit c11bc3b3b8
697 changed files with 18150 additions and 18839 deletions

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
String
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -27,7 +27,6 @@
#include "pibytearray.h"
#include "pichar.h"
#include "math.h"
class PIStringList;
@@ -41,7 +40,7 @@ public:
PIString & operator +=(const PIChar & c) {push_back(c); return *this;}
PIString & operator +=(const char * str);
PIString & operator +=(const wchar_t * str);
PIString & operator +=(const string & str) {appendFromChars(str.c_str(), str.length()); return *this;}
PIString & operator +=(const std::string & str) {appendFromChars(str.c_str(), str.length()); return *this;}
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s()); return *this;}
PIString & operator +=(const PIString & str);
#ifdef HAS_LOCALE
@@ -67,7 +66,7 @@ public:
PIString(const wchar_t * str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
//! Contructs string from std::string "str"
PIString(const string & str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
PIString(const std::string & str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
#ifdef HAS_LOCALE
PIString(const wstring & str): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += str;}
@@ -81,7 +80,7 @@ public:
/*! \brief Contructs string from "len" characters of buffer "str"
* \details Example: \snippet pistring.cpp PIString(char * , int) */
PIString(const char * str, const int len): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += string(str, len);}
PIString(const char * str, const int len): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--; *this += std::string(str, len);}
/*! \brief Contructs string as sequence of characters "c" of buffer with length "len"
* \details Example: \snippet pistring.cpp PIString(int, char) */
@@ -123,7 +122,7 @@ public:
operator const char*() {return data();}
//! Return std::string representation of string
operator const string() {if (size() == 0) return string(); string s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toAscii()); return s;}
operator const std::string() {if (size() == 0) return std::string(); std::string s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toAscii()); return s;}
//! Return symbol at index "pos"
PIChar operator [](const int pos) const {return at(pos);}
@@ -142,7 +141,7 @@ public:
bool operator ==(const char * str) const {return *this == PIString(str);}
//! Compare operator
bool operator ==(const string & str) const {return *this == PIString(str);}
bool operator ==(const std::string & str) const {return *this == PIString(str);}
//! Compare operator
@@ -156,7 +155,7 @@ public:
bool operator !=(const char * str) const {return *this != PIString(str);}
//! Compare operator
bool operator !=(const string & str) const {return *this != PIString(str);}
bool operator !=(const std::string & str) const {return *this != PIString(str);}
//! Compare operator
@@ -170,7 +169,7 @@ public:
bool operator <(const char * str) const {return *this < PIString(str);}
//! Compare operator
bool operator <(const string & str) const {return *this < PIString(str);}
bool operator <(const std::string & str) const {return *this < PIString(str);}
//! Compare operator
@@ -184,7 +183,7 @@ public:
bool operator >(const char * str) const {return *this > PIString(str);}
//! Compare operator
bool operator >(const string & str) const {return *this > PIString(str);}
bool operator >(const std::string & str) const {return *this > PIString(str);}
//! Compare operator
@@ -198,7 +197,7 @@ public:
bool operator <=(const char * str) const {return *this <= PIString(str);}
//! Compare operator
bool operator <=(const string & str) const {return *this <= PIString(str);}
bool operator <=(const std::string & str) const {return *this <= PIString(str);}
//! Compare operator
@@ -212,7 +211,7 @@ public:
bool operator >=(const char * str) const {return *this >= PIString(str);}
//! Compare operator
bool operator >=(const string & str) const {return *this >= PIString(str);}
bool operator >=(const std::string & str) const {return *this >= PIString(str);}
operator bool() const {return toBool();}
@@ -246,7 +245,7 @@ public:
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
//! Append std::string "str" at the end of string
PIString & operator <<(const string & str) {*this += str; return *this;}
PIString & operator <<(const std::string & str) {*this += str; return *this;}
/*! \brief Append string representation of "num" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(int) */
@@ -469,6 +468,7 @@ public:
//! \brief Return \c std::string representation of this string
std::string stdString() const {return convertToStd();}
#ifdef HAS_LOCALE
wstring stdWString() const {return convertToWString();}
#endif
@@ -486,11 +486,15 @@ public:
//! \brief Convert each symbol in copyed string to lower case and return it
PIString toLowerCase() const;
PIString toNativeDecimalPoints() const {
#ifdef HAS_LOCALE
PIString toNativeDecimalPoints() const {PIString s(*this); if (currentLocale == 0) return s; return s.replaceAll(".", currentLocale->decimal_point).replaceAll(",", currentLocale->decimal_point);}
PIString s(*this); if (currentLocale == 0) return s; return s.replaceAll(".", currentLocale->decimal_point).replaceAll(",", currentLocale->decimal_point);
#else
PIString toNativeDecimalPoints() const {return PIString(*this).replaceAll(",", ".");}
return PIString(*this).replaceAll(",", ".");
#endif
}
//! \brief Search substring "str" from symbol at index "start" and return first occur position
@@ -505,10 +509,6 @@ public:
//! \details Example: \snippet pistring.cpp PIString::find
int find(const char * str, const int start = 0) const {return find(PIString(str), start);}
//! \brief Search substring "str" from symbol at index "start" and return first occur position
//! \details Example: \snippet pistring.cpp PIString::find
int find(const string str, const int start = 0) const {return find(PIString(str), start);}
//! \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;
@@ -521,10 +521,6 @@ public:
//! \details Example: \snippet pistring.cpp PIString::findLast
int findLast(const char * str, const int start = 0) const {return findLast(PIString(str), start);}
//! \brief Search substring "str" from symbol at index "start" and return last occur position
//! \details Example: \snippet pistring.cpp PIString::findLast
int findLast(const string 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;
@@ -632,15 +628,15 @@ public:
//! \brief Set string content to numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::setFloat
PIString & setNumber(const float value) {clear(); *this += ftos(value); return *this;}
PIString & setNumber(const float value) {clear(); *this += PIString::fromNumber(value); return *this;}
//! \brief Set string content to numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::setFloat
PIString & setNumber(const double & value) {clear(); *this += dtos(value); return *this;}
PIString & setNumber(const double & value) {clear(); *this += PIString::fromNumber(value); return *this;}
//! \brief Set string content to numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::setFloat
PIString & setNumber(const ldouble & value) {clear(); *this += dtos(value); return *this;}
PIString & setNumber(const ldouble & value) {clear(); *this += PIString::fromNumber(value); return *this;}
//! \brief Set string content to human readable size in B/kB/MB/GB/TB
//! \details Example: \snippet pistring.cpp PIString::setReadableSize
@@ -682,15 +678,15 @@ public:
//! \brief Return string contains numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::fromFloat
static PIString fromNumber(const float value) {return PIString(ftos(value));}
static PIString fromNumber(const float value) {return ftos(value);}
//! \brief Return string contains numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::fromFloat
static PIString fromNumber(const double & value) {return PIString(dtos(value));}
static PIString fromNumber(const double & value) {return ftos(value);}
//! \brief Return string contains numeric representation of "value"
//! \details Example: \snippet pistring.cpp PIString::fromFloat
static PIString fromNumber(const ldouble & value) {return PIString(dtos(value));}
static PIString fromNumber(const ldouble & value) {return ftos(value);}
//! \brief Return "true" or "false"
static PIString fromBool(const bool value) {return PIString(value ? "true" : "false");}
@@ -706,6 +702,12 @@ private:
static const char toBaseN[];
static const int fromBaseN[];
static PIString itos(const int num);
static PIString ltos(const long num);
static PIString uitos(const uint num);
static PIString ultos(const ulong num);
static PIString ftos(const float num);
static PIString dtos(const double num);
static PIString fromNumberBaseS(const llong value, int base = 10, bool * ok = 0) {
if (value == 0) return PIString("0");
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return PIString();}
@@ -777,7 +779,7 @@ private:
return ret;
}
void appendFromChars(const char * c, int s);
string convertToStd() const;
std::string convertToStd() const;
#ifdef HAS_LOCALE
wstring convertToWString() const {wstring s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toWChar()); return s;}
#endif
@@ -793,7 +795,7 @@ private:
inline std::ostream & operator <<(std::ostream & s, const PIString & v) {for (int i = 0; i < v.length(); ++i) s << v[i]; return s;}
//! \relatesalso PIString \brief Input operator from std::istream (cin)
inline std::istream & operator >>(std::istream & s, PIString & v) {string ss; s >> ss; v << PIString(ss); return s;}
inline std::istream & operator >>(std::istream & s, PIString & v) {std::string ss; s >> ss; v << PIString(ss); return s;}
//! \relatesalso PIString \relatesalso PICout \brief Output operator to PICout
inline PICout operator <<(PICout s, const PIString & v) {s.space(); s.quote(); s.setControl(0, true); for (int i = 0; i < v.length(); ++i) s << v[i]; s.restoreControl(); s.quote(); return s;}
@@ -815,7 +817,7 @@ inline PIString operator +(const PIString & str, const PIString & f) {PIString s
inline PIString operator +(const PIString & f, const char * str) {PIString s(f); s += str; return s;}
//! \relatesalso PIString \brief Return concatenated string
inline PIString operator +(const PIString & f, const string & str) {PIString s(f); s += str; return s;}
inline PIString operator +(const PIString & f, const std::string & str) {PIString s(f); s += str; return s;}
//inline PIString operator +(const char c, const PIString & f) {return PIString(c) + f;}
@@ -823,7 +825,7 @@ inline PIString operator +(const PIString & f, const string & str) {PIString s(f
inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;}
//! \relatesalso PIString \brief Return concatenated string
inline PIString operator +(const string & str, const PIString & f) {return PIString(str) + f;}
inline PIString operator +(const std::string & str, const PIString & f) {return PIString(str) + f;}
inline char chrUpr(char c);
inline char chrLwr(char c);
@@ -890,7 +892,7 @@ public:
PIStringList & operator <<(const PIStringList & sl) {piForeachC (PIString & i, sl) push_back(i); return *this;}
//inline PIStringList & operator <<(const char c) {push_back(PIString(c)); return *this;}
PIStringList & operator <<(const char * str) {push_back(PIString(str)); return *this;}
PIStringList & operator <<(const string & str) {push_back(str); return *this;}
PIStringList & operator <<(const std::string & str) {push_back(str); return *this;}
PIStringList & operator <<(const int & num) {push_back(PIString::fromNumber(num)); return *this;}
PIStringList & operator <<(const short & num) {push_back(PIString::fromNumber(num)); return *this;}
PIStringList & operator <<(const long & num) {push_back(PIString::fromNumber(num)); return *this;}