2 #ifndef _Q_STRING_HANDLER_HH_
3 #define _Q_STRING_HANDLER_HH_
29 {
return s.erase(0, s.find_first_not_of(
"\t ")); }
33 {
return s.erase(s.find_last_not_of(
"\t ") + 1, std::string::npos); }
43 std::string
ToLower(
const std::string &text);
45 std::string
ToUpper(
const std::string &text);
51 void Escape(std::string& text,
char toBeEscaped);
57 void UnEscape(std::string& text,
char escaped);
63 void Replace(std::string& text,
char oldChar,
char newChar);
76 size_t Split(std::string source,
77 std::list<std::string>& splitted,
95 bool StringToInt(std::string in,
int &out,
bool strictCheck);
103 bool StringToLong(std::string in, Long64_t &out,
bool strictCheck);
127 bool StringToDouble(std::string in,
double &out,
bool strictCheck);
147 std::string
IntToString(
int val,
int width = 0,
char pad=
'0');
152 std::string
LongToString(Long64_t val,
int width = 0,
char pad=
'0');
172 std::string
DoubleToString(
double val,
int nDigits = 4,
bool scientific =
true);
182 std::string
Resize(
const std::string& s,
size_t len);
185 std::string
TimeFormat(
const char *fmt=
"%b %d %Y %H:%M:%S");
200 template<
class T> std::string
SqlString(
const Diana::QBaseType<T>& baseVal,
203 std::stringstream retSStream;
204 if(baseVal.IsValid())
205 retSStream << (modeSelect?
"=":
"")
208 retSStream << (modeSelect?
"IS NULL":
"NULL");
209 return retSStream.str();
223 std::string
SqlString(
const Diana::QBool& boolVal,
bool modeSelect);
237 std::string
SqlString(
const std::vector<int>& vecVal,
bool modeSelect,
249 std::string
SqlString(
const Diana::QString& strVal,
250 const std::string& selectName=
"");
271 std::string
RandomString(UInt_t length,Bool_t caseSensitive=
true,Bool_t startLetter=
false);
281 template <
class ForwardIterator> std::string
Join(
const std::string &joiner,ForwardIterator begin,ForwardIterator end) {
282 std::stringstream ret;
283 ForwardIterator it = begin;
284 if(it==end)
return ret.str();
286 for(;it!=end;it++) ret << joiner << *it;
bool wrapped into a QObject
string wrapped into a QObject
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...
general purpose string manipulation functions
std::string RandomString(UInt_t length, Bool_t caseSensitive=true, Bool_t startLetter=false)
Return a random string of lenght.
bool StringToChar(const std::string &in, char &out)
convert string to signed char (i.e. 8-bit int)
std::string IntToHexString(int value)
convert int value to string using hex representation
std::string SqlString(const Diana::QBaseType< T > &baseVal, bool modeSelect)
build string valid for sql select or insert query starting from a QBaseType variable
std::string DoubleToString(double val, int nDigits=4, bool scientific=true)
convert double value to string
std::string & RSwallowSpaces(std::string &s)
remove spaces and tabs from the end of s
void Escape(std::string &text, char toBeEscaped)
escape text by adding backslash before each instance of toBeEscaped character
std::string LongToString(Long64_t val, int width=0, char pad='0')
convert long64 value to string
std::string BoolToString(bool val)
convert bool value to string ("true" or "false")
std::string IntToString(int val, int width=0, char pad='0')
convert int value to string
bool StringToBool(std::string in, bool &out)
convert string to bool
std::string TimeFormat(const char *fmt="%b %d %Y %H:%M:%S")
Get the current time formated as a string.
std::string ToUpper(const std::string &text)
Convert to upper case.
size_t Split(std::string source, std::list< std::string > &splitted, char separtator)
split source into a list of substrings separated by separator
std::string & DoubleSwallowSpaces(std::string &s)
remove spaces and tabs from both the beginning and the end of s
std::string & SwallowSpaces(std::string &s)
remove spaces and tabs from the beginning of s
bool StringToDouble(std::string in, double &out, bool strictCheck)
convert string to double
bool StringToLong(std::string in, Long64_t &out, bool strictCheck)
convert string to Long64_t
bool StringToInt(std::string in, int &out, bool strictCheck)
convert string to integer
std::string Join(const std::string &joiner, ForwardIterator begin, ForwardIterator end)
Join a list of things into a string.
std::string ToLower(const std::string &text)
Convert to lower case.
std::string Resize(const std::string &s, size_t len)
resize a string to len, adding spaces if necessary
std::string RemoveFromString(const std::string &text, const char *chars)
Remove some characters from the string.
void UnEscape(std::string &text, char escaped)
unescape text by removing backslash preceding each instance of escaped character
void Replace(std::string &text, char oldChar, char newChar)
replace oldChar with newChar in text. Escaped characters are not replaced.