15.10.2012 - version 0.2.0 - PIIODevice - base of file, ethernet, serial and packets extractor. PIEthernet now support also TCP (client and server). PIConsole now can align labels in each column individually.
This commit is contained in:
21
pistring.h
Normal file → Executable file
21
pistring.h
Normal file → Executable file
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
String
|
||||
Copyright (C) 2011 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2012 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
|
||||
@@ -126,8 +126,12 @@ public:
|
||||
PIString & insert(const int index, const char * c) {return insert(index, PIString(c));}
|
||||
PIString & expandRightTo(const int len, const PIChar & c) {if (len > length()) resize(len, c); return *this;}
|
||||
PIString & expandLeftTo(const int len, const PIChar & c) {if (len > length()) insert(0, PIString(len - length(), c)); return *this;}
|
||||
PIString & reverse() {PIString str(*this); clear(); piForeachR (const PIChar & c, str) push_back(c); return *this;}
|
||||
PIString reversed() const {PIString str(*this); str.reverse(); return str;}
|
||||
|
||||
const char * data() {return convertToStd().c_str();}
|
||||
//const char * data() {return convertToStd().c_str();}
|
||||
int lengthAscii() const;
|
||||
const char * data() const;
|
||||
const string stdString() const {return convertToStd();}
|
||||
wstring stdWString() const {return convertToWString();}
|
||||
PIByteArray toByteArray() {string s(convertToStd()); return PIByteArray(s.c_str(), s.length());}
|
||||
@@ -140,7 +144,7 @@ public:
|
||||
#else
|
||||
PIString toNativeDecimalPoints() const {PIString s(*this); if (currentLocale == 0) return s; return s.replaceAll(".", currentLocale->decimal_point);}
|
||||
#endif
|
||||
|
||||
|
||||
int find(const char str, const int start = 0) const;
|
||||
int find(const PIString str, const int start = 0) const;
|
||||
int find(const char * str, const int start = 0) const {return find(PIString(str), start);}
|
||||
@@ -153,15 +157,15 @@ public:
|
||||
int length() const {return size();}
|
||||
bool isEmpty() const {return (size() == 0 || *this == "");}
|
||||
|
||||
bool toBool() const {PIString s(*this); if (atof(s.toNativeDecimalPoints().stdString().c_str()) > 0. || s.trimmed().toLowerCase() == "true") return true; return false;}
|
||||
bool toBool() const {PIString s(*this); if (atof(s.toNativeDecimalPoints().data()) > 0. || s.trimmed().toLowerCase() == "true") return true; return false;}
|
||||
char toChar() const;
|
||||
short toShort() const;
|
||||
int toInt() const;
|
||||
long toLong() const;
|
||||
llong toLLong() const;
|
||||
float toFloat() const {PIString s(*this); return (float)atof(s.toNativeDecimalPoints().stdString().c_str());}
|
||||
double toDouble() const {PIString s(*this); return atof(s.toNativeDecimalPoints().stdString().c_str());}
|
||||
ldouble toLDouble() const {PIString s(*this); return atof(s.toNativeDecimalPoints().stdString().c_str());}
|
||||
float toFloat() const {PIString s(*this); return (float)atof(s.toNativeDecimalPoints().data());}
|
||||
double toDouble() const {PIString s(*this); return atof(s.toNativeDecimalPoints().data());}
|
||||
ldouble toLDouble() const {PIString s(*this); return atof(s.toNativeDecimalPoints().data());}
|
||||
|
||||
//inline PIString & setNumber(const char value) {clear(); *this += itos(value); return *this;}
|
||||
PIString & setNumber(const int value) {clear(); *this += itos(value); return *this;}
|
||||
@@ -188,11 +192,14 @@ private:
|
||||
string convertToStd() const;
|
||||
wstring convertToWString() const {wstring s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toWChar()); return s;}
|
||||
|
||||
PIByteArray data_;
|
||||
//string std_string;
|
||||
//wstring std_wstring;
|
||||
|
||||
};
|
||||
|
||||
inline std::ostream & operator <<(std::ostream & s, const PIString & v) {for (int i = 0; i < v.length(); ++i) s << v[i]; return s;}
|
||||
inline std::istream & operator >>(std::istream & s, PIString & v) {string ss; s >> ss; v << PIString(ss); return s;}
|
||||
|
||||
inline PIString operator +(const PIString & str, const PIString & f) {PIString s(str); s += f; return s;}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user