7 #include "TTimeStamp.h"
20 std::string ret(text);
21 for(
size_t i=0;i<strlen(chars);i++)
22 ret.erase(std::remove(ret.begin(),ret.end(),chars[i]),ret.end());
28 std::string ret(text);
29 std::transform(ret.begin(),ret.end(),ret.begin(),(int (*)(
int))std::tolower);
35 std::string ret(text);
36 std::transform(ret.begin(),ret.end(),ret.begin(),(int (*)(
int))std::toupper);
46 if((position = text.find(toBeEscaped, position)) == std::string::npos)
48 text.insert(position, 1,
'\\');
60 if((position = text.find(escaped, position)) == std::string::npos)
63 if( (position > 0) && (text.at(position-1) ==
'\\') )
64 text.erase(position-1, 1);
77 if( (position = text.find(oldChar, position)) == std::string::npos)
81 if( (position == 0) || (text.at(position-1) !=
'\\') )
82 text.replace(position, 1, 1, newChar);
90 std::list<std::string>& splitted,
101 pos = source.find(separator, pos);
102 if(std::string::npos == pos)
104 if(pos != 0 && source.at(pos-1) ==
'\\')
110 std::string element = source.substr(0, pos);
114 if( !(element.empty()) )
115 splitted.push_back(element);
117 if(pos == std::string::npos)
120 source = source.substr(pos+1);
123 return splitted.size();
133 int base = ((
"0x" == in.substr(0, 2))? 16 : 10);
134 const char* cStr = in.c_str();
136 out = ::strtol(cStr, &check, base);
141 return ( (
'\0' == (*check)) || (!strictCheck) );
152 int base = ((
"0x" == in.substr(0, 2))? 16 : 10);
153 const char* cStr = in.c_str();
155 out = ::strtoll(cStr, &check, base);
160 return ( (
'\0' == (*check)) || (!strictCheck) );
200 const char* cStr = in.c_str();
201 out = ::strtod(cStr, &check);
206 return ( (
'\0' == (*check)) || (!strictCheck) );
218 if(iVal < 0 || iVal > 255)
229 std::ostringstream text;
231 text << std::setw(width) << std::setfill(pad);
238 std::ostringstream text;
240 text << std::setw(width) << std::setfill(pad);
247 return val ?
"true" :
"false";
255 std::ostringstream text;
257 text.unsetf(std::ios_base::floatfield);
260 text << std::scientific << std::setprecision(nDigits - 1) << val;
262 text << std::setprecision(nDigits) << val;
270 std::ostringstream hexa;
271 hexa <<
"0x" << std::hex << std::setw(4) << std::setfill(
'0') << value;
278 if (str.size() < len ) {
280 int i = len - s.size();
283 s = str.substr(0,len);
296 ::strftime(buffer,512,fmt,::localtime(&
t0));
297 return std::string(buffer);
306 std::string retString =
"";
310 if(boolVal.IsValid())
311 retString += ((boolVal ==
true)?
"true":
"false");
319 bool modeSelect,
bool writeEmptyBra)
321 std::stringstream retString;
325 if( !writeEmptyBra && vecVal.size() == 0 )
331 if( !writeEmptyBra && vecVal.size() == 0 )
336 for(uint i = 0; i < vecVal.size(); i++)
337 retString << (i!=0 ?
"," :
"") << vecVal[i];
340 return retString.str();
345 const std::string& selectName)
347 std::stringstream retString;
349 if(selectName.empty())
352 return "'" + strVal.GetValue() +
"'";
359 retString << selectName <<
"='" << (std::string)strVal <<
"'";
361 retString <<
"(" << selectName <<
" IS NULL OR "
362 << selectName <<
"='')";
364 return retString.str();
369 static TRandom *mRandom = NULL;
370 if(mRandom == NULL) {
372 mRandom =
new TRandom(A.GetNanoSec());
374 const int dict_length = (caseSensitive ? 62 : 36);
375 const char *dictionary =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
378 ret+=dictionary[(UInt_t)mRandom->Uniform(10,dict_length)];
382 ret+=dictionary[(UInt_t)mRandom->Uniform(0,dict_length)];
388 template std::string
QStringHandler::Join(
const std::string &,std::vector<std::string>::iterator,std::vector<std::string>::iterator);
389 template std::string
QStringHandler::Join(
const std::string &,std::vector<std::string>::const_iterator,std::vector<std::string>::const_iterator);
390 template std::string
QStringHandler::Join(
const std::string &,std::list<std::string>::iterator,std::list<std::string>::iterator);
391 template std::string
QStringHandler::Join(
const std::string &,std::list<std::string>::const_iterator,std::list<std::string>::const_iterator);
393 template std::string
QStringHandler::Join(
const std::string &,std::vector<int>::iterator,std::vector<int>::iterator);
394 template std::string
QStringHandler::Join(
const std::string &,std::vector<int>::const_iterator,std::vector<int>::const_iterator);
395 template std::string
QStringHandler::Join(
const std::string &,std::list<int>::iterator,std::list<int>::iterator);
396 template std::string
QStringHandler::Join(
const std::string &,std::list<int>::const_iterator,std::list<int>::const_iterator);
398 template std::string
QStringHandler::Join(
const std::string &,std::vector<unsigned int>::iterator,std::vector<unsigned int>::iterator);
399 template std::string
QStringHandler::Join(
const std::string &,std::vector<unsigned int>::const_iterator,std::vector<unsigned int>::const_iterator);
400 template std::string
QStringHandler::Join(
const std::string &,std::list<unsigned int>::iterator,std::list<unsigned int>::iterator);
401 template std::string
QStringHandler::Join(
const std::string &,std::list<unsigned int>::const_iterator,std::list<unsigned int>::const_iterator);
403 template std::string
QStringHandler::Join(
const std::string &,std::vector<long>::iterator,std::vector<long>::iterator);
404 template std::string
QStringHandler::Join(
const std::string &,std::vector<long>::const_iterator,std::vector<long>::const_iterator);
405 template std::string
QStringHandler::Join(
const std::string &,std::list<long>::iterator,std::list<long>::iterator);
406 template std::string
QStringHandler::Join(
const std::string &,std::list<long>::const_iterator,std::list<long>::const_iterator);
408 template std::string
QStringHandler::Join(
const std::string &,std::vector<unsigned long>::iterator,std::vector<unsigned long>::iterator);
409 template std::string
QStringHandler::Join(
const std::string &,std::vector<unsigned long>::const_iterator,std::vector<unsigned long>::const_iterator);
410 template std::string
QStringHandler::Join(
const std::string &,std::list<unsigned long>::iterator,std::list<unsigned long>::iterator);
411 template std::string
QStringHandler::Join(
const std::string &,std::list<unsigned long>::const_iterator,std::list<unsigned long>::const_iterator);
413 template std::string
QStringHandler::Join(
const std::string &,std::vector<float>::iterator,std::vector<float>::iterator);
414 template std::string
QStringHandler::Join(
const std::string &,std::vector<float>::const_iterator,std::vector<float>::const_iterator);
415 template std::string
QStringHandler::Join(
const std::string &,std::list<float>::iterator,std::list<float>::iterator);
416 template std::string
QStringHandler::Join(
const std::string &,std::list<float>::const_iterator,std::list<float>::const_iterator);
418 template std::string
QStringHandler::Join(
const std::string &,std::vector<double>::iterator,std::vector<double>::iterator);
419 template std::string
QStringHandler::Join(
const std::string &,std::vector<double>::const_iterator,std::vector<double>::const_iterator);
420 template std::string
QStringHandler::Join(
const std::string &,std::list<double>::iterator,std::list<double>::iterator);
421 template std::string
QStringHandler::Join(
const std::string &,std::list<double>::const_iterator,std::list<double>::const_iterator);
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
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
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.