30 #ifdef __WITHOUT_TSTRING_TOKENIZE
47 std::list < Int_t > splitIndex;
49 Int_t i, start, nrDiff = 0;
50 for (i = 0; i < delim.
Length(); i++) {
56 splitIndex.push_back(pos);
62 splitIndex.push_back(
Length());
71 std::list < Int_t >::const_iterator it;
73 for (it = splitIndex.begin(); it != splitIndex.end(); it++) {
75 for (it = splitIndex.begin();
76 it != (std::list < Int_t >::const_iterator) splitIndex.end();
80 if (stop - 1 >= start + 1) {
81 TString tok = (*this)(start + 1, stop - start - 1);
93 #ifdef __WITH_KVSTRING_ISDIGIT
108 const char* cp =
Data();
110 if (len == 0)
return kFALSE;
112 for (
Ssiz_t i = 0; i < len; ++i) {
113 if (cp[i] !=
' ' && !isdigit(cp[i]))
return kFALSE;
114 if (cp[i] ==
' ')
b++;
115 if (isdigit(cp[i]))
d++;
124 #ifdef __WITH_KVSTRING_REMOVE
134 *
this =
Strip(st, c);
140 #ifdef __WITH_KVSTRING_ATOI
161 tmp += (*this)(start, end - start);
163 end =
Index(
" ", start);
166 tmp += (*this)(start, end - start);
167 return atoi(tmp.
Data());
172 #ifdef __WITH_KVSTRING_ATOF
190 if (comma == -1 && end == -1)
199 return atof(tmp.
Data());
204 tmp2 += tmp(start, end - start);
206 end = tmp.
Index(
" ", start);
209 tmp2 += tmp(start, end - start);
210 return atof(tmp2.
Data());
215 #ifdef __WITH_KVSTRING_ISFLOAT
245 Int_t i_dot, i_e, i_plus, i_minus, i_comma;
246 i_dot = i_e = i_plus = i_minus = i_comma = -1;
248 i_dot = tmp.
First(
'.');
249 if (i_dot > -1) tmp.
Replace(i_dot, 1,
" ", 1);
250 i_comma = tmp.
First(
',');
251 if (i_comma > -1) tmp.
Replace(i_comma, 1,
" ", 1);
252 i_e = tmp.
First(
'e');
257 i_e = tmp.
First(
'E');
258 if (i_e > -1) tmp.
Replace(i_e, 1,
" ", 1);
260 i_plus = tmp.
First(
'+');
261 if (i_plus > -1) tmp.
Replace(i_plus, 1,
" ", 1);
262 i_minus = tmp.
First(
'-');
263 if (i_minus > -1) tmp.
Replace(i_minus, 1,
" ", 1);
283 #ifdef __WITH_KVSTRING_ISWHITESPACE
348 Int_t read_items = 0;
350 const char* cp =
Data();
351 Int_t int_format_length_descriptor = 0;
354 while (fmt[fmt_index] !=
'\0') {
356 if (fmt[fmt_index] ==
'%') {
359 if (fmt[fmt_index] >=
'0' && fmt[fmt_index] <=
'9') {
361 zero_padding = (fmt[fmt_index] ==
'0');
362 if (zero_padding) fmt_index++;
365 while (fmt[fmt_index] >=
'0' && fmt[fmt_index] <=
'9') {
366 length_of_number += fmt[fmt_index++];
368 int_format_length_descriptor = length_of_number.
Atoi();
370 if (fmt[fmt_index] ==
'd') {
373 if (int_format_length_descriptor) {
378 Int_t figures_read = 0;
379 while (cp[str_index] >=
'0' && cp[str_index] <=
'9') {
380 dummy += cp[str_index++];
383 if (figures_read != int_format_length_descriptor) {
390 *(va_arg(args,
int*)) = dummy.
Atoi();
403 while (int_format_length_descriptor) {
404 if (cp[str_index] ==
'\0') {
409 if ((cp[str_index] !=
' ') && (cp[str_index] <
'0' || cp[str_index] >
'9')) {
414 if ((cp[str_index] ==
' ') && no_more_whitespace) {
419 if (cp[str_index] !=
' ') {
420 no_more_whitespace =
kTRUE;
421 dummy += cp[str_index];
424 int_format_length_descriptor--;
427 if (!no_more_whitespace) {
432 if (cp[str_index + 1] !=
'\0' && (cp[str_index + 1] <
'0' || cp[str_index + 1] >
'9')) {
437 *(va_arg(args,
int*)) = dummy.
Atoi();
445 while (cp[str_index] >=
'0' && cp[str_index] <=
'9')
446 dummy += cp[str_index++];
447 *(va_arg(args,
int*)) = dummy.
Atoi();
452 else if (fmt[fmt_index] ==
'*') {
460 if (fmt[fmt_index] != cp[str_index]) {
474 if (cp[str_index] !=
'\0')
506 else if (pattern ==
"*")
return kTRUE;
508 std::unique_ptr<TObjArray> tok(pattern.
Tokenize(
"*"));
509 Int_t n_tok = tok->GetEntries();
519 Int_t idx = 0, num = 0;
520 for (
Int_t ii = 0; ii < n_tok; ii += 1) {
528 if (num == n_tok)
return kTRUE;
896 while (!copy.
End()) {
914 std::vector<KVString>
v;
917 v.push_back(
Next(strip_whitespace));
922 #ifdef __WITH_KVSTRING_ITOA
935 const char* cp =
Data();
937 if (len == 0)
return kFALSE;
938 for (
Ssiz_t i = 0; i < len; ++i)
939 if (cp[i] !=
'0' && cp[i] !=
'1')
957 const char* cp =
Data();
959 if (len == 0)
return kFALSE;
960 for (
Ssiz_t i = 0; i < len; ++i)
961 if (!isdigit(cp[i]) || cp[i] ==
'8' || cp[i] ==
'9')
979 const char* cp =
Data();
981 if (len == 0)
return kFALSE;
982 for (
Ssiz_t i = 0; i < len; ++i)
1003 if (base < 2 || base > 36) {
1004 Error(
"KVString::IsInBaseN",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base);
1008 Error(
"KVString::IsInBaseN",
"input string is empty.") ;
1013 KVString str_ref0 =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
1017 for (
Int_t k = 0; k <
str.Length(); k++) {
1049 #ifdef __WITH_KVSTRING_ITOA
1052 if (base < 2 || base > 36) {
1053 Error(
"KVString::Itoa",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base) ;
1057 Int_t quotient = value;
1060 buf +=
"0123456789abcdefghijklmnopqrstuvwxyz"[
TMath::Abs(quotient % base) ];
1065 if (value < 0) buf +=
'-';
1066 std::reverse(buf.begin(), buf.end());
1088 #ifdef __WITH_KVSTRING_ITOA
1091 if (base < 2 || base > 36) {
1092 Error(
"KVString::UItoa",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base);
1099 buf +=
"0123456789abcdefghijklmnopqrstuvwxyz"[ quotient % base ];
1103 std::reverse(buf.begin(), buf.end());
1125 #ifdef __WITH_KVSTRING_ITOA
1128 if (base < 2 || base > 36) {
1129 Error(
"KVString::LLtoa",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base);
1136 buf +=
"0123456789abcdefghijklmnopqrstuvwxyz"[
TMath::Abs(quotient % base) ];
1141 if (value < 0) buf +=
'-';
1142 std::reverse(buf.begin(), buf.end());
1164 #ifdef __WITH_KVSTRING_ITOA
1167 if (base < 2 || base > 36) {
1168 Error(
"KVString::ULLtoa",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base);
1175 buf +=
"0123456789abcdefghijklmnopqrstuvwxyz"[ quotient % base ];
1179 std::reverse(buf.begin(), buf.end());
1197 #ifdef __WITH_KVSTRING_ITOA
1200 if (base_in < 2 || base_in > 36 || base_out < 2 || base_out > 36) {
1201 Error(
"KVString::BaseConvert",
"only bases 2-36 are supported (base_in=%d, base_out=%d).", base_in, base_out);
1207 if (s_in_[0] ==
'-') {
1211 if (!isSigned && s_in_[0] ==
'+') s_in_.
Remove(0, 1);
1216 Error(
"KVString::BaseConvert",
"s_in=\"%s\" is not in base %d", s_in.
Data(), base_in);
1223 Error(
"KVString::BaseConvert",
"s_in=\"%s\" > %s = 2^64-1 in base %d.", s_in.
Data(), s_max.
Data(), base_in);
1229 if (s_in_ > s_max) {
1231 Error(
"KVString::BaseConvert",
"s_in=\"%s\" > %s = 2^64-1 in base %d.", s_in.
Data(), s_max.
Data(), base_in);
1239 if (isSigned) s_out.
Prepend(
"-");
1262 if (tmp.
Length()) tmp +=
" ";
1284 while (!tmp.
End()) {
1285 if (tmp2.
Length()) tmp2 +=
" ";
1326 while ((o = next())) {
1331 int tmplen = tmp.
Length();
1333 int tmp2len = tmp2.
Length();
1335 for (
int i = 0; i < len; i++) {
1336 if (tmp[i] != tmp2[i]) tmp[i] = bug;
1338 if (tmp2len > tmplen) {
1339 tmp.
Append(bug, tmp2len - tmplen);
1343 int tmplen = tmp.
Length();
1345 bool do_bug =
false;
1346 for (
int i = 0; i < tmplen; i++) {
1348 if (tmp[i] == bug)
continue;
1349 else do_bug =
false;
1351 else if (tmp[i] == bug) {
1396 while ((o = next())) {
1401 int tmplen = tmp.
Length();
1403 int tmp2len = tmp2.
Length();
1405 for (
int i = 0; i < len; i++) {
1406 if (tmp[i] != tmp2[i]) tmp[i] = bug;
1408 if (tmp2len > tmplen) {
1409 tmp.
Append(bug, tmp2len - tmplen);
1413 int tmplen = tmp.
Length();
1415 bool do_bug =
false;
1416 for (
int i = 0; i < tmplen; i++) {
1418 if (tmp[i] == bug)
continue;
1419 else do_bug =
false;
1421 else if (tmp[i] == bug) {
1442 for (
Int_t i = 0; i < length; ++i) {
1444 if (p < 26)
Append((
char)p +
'A');
1445 else Append((
char)(p - 26) +
'a');
1458 if ((*
this)[0] >=
'a' && (*
this)[0] <=
'z')(*this)[0] -= (
'a' -
'A');
1474 TString sy_dec, sy_exp, sey_dec, sey_exp;
1476 Int_t y_exp, ey_exp;
1479 std::unique_ptr<TObjArray> loa_y(sy.
Tokenize(
"e"));
1481 TIter next_y(loa_y.get());
1488 y_dec = sy_dec.
Atof();
1489 y_exp = sy_exp.
Atoi();
1492 std::unique_ptr<TObjArray> loa_ey(sey.
Tokenize(
"e"));
1494 TIter next_ey(loa_ey.get());
1503 ey_dec = sey_dec.
Atof();
1504 ey_exp = sey_exp.
Atoi();
1512 if (y_exp == ey_exp)
s =
Format(
"%1.2g.0(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
1513 else s =
Format(
"%1.3g.0(%g.0).10$^{%d}$", y_dec, err, y_exp);
1516 if (y_exp == ey_exp)
s =
Format(
"%1.2g.0(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
1517 else s =
Format(
"%1.3g.0(%g0).10$^{%d}$", y_dec, err, y_exp);
1520 if (y_exp == ey_exp)
s =
Format(
"%1.2g.0(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
1521 else s =
Format(
"%1.3g.0(%g).10$^{%d}$", y_dec, err, y_exp);
1527 if (y_exp == ey_exp)
s =
Format(
"%1.2g0(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
1528 else s =
Format(
"%1.3g0(%g.0).10$^{%d}$", y_dec, err, y_exp);
1531 if (y_exp == ey_exp)
s =
Format(
"%1.2g0(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
1532 else s =
Format(
"%1.3g0(%g0).10$^{%d}$", y_dec, err, y_exp);
1535 if (y_exp == ey_exp)
s =
Format(
"%1.2g0(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
1536 else s =
Format(
"%1.3g0(%g).10$^{%d}$", y_dec, err, y_exp);
1540 if (y_exp == ey_exp)
s =
Format(
"%1.2g(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
1541 else s =
Format(
"%1.3g(%g.0).10$^{%d}$", y_dec, err, y_exp);
1544 if (y_exp == ey_exp)
s =
Format(
"%1.2g(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
1545 else s =
Format(
"%1.3g(%g0).10$^{%d}$", y_dec, err, y_exp);
1548 if (y_exp == ey_exp)
s =
Format(
"%1.2g(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
1549 else s =
Format(
"%1.3g(%g).10$^{%d}$", y_dec, err, y_exp);;
1552 s.ReplaceAll(
".10$^{0}$",
"");
1553 s.ReplaceAll(
"0)",
")");
1555 Form(
"%s",
s.Data());
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
R__EXTERN TRandom * gRandom
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
std::unique_ptr< TObjArray > kObjArr
used by Next() to iterate over list
void RBegin(TString delim) const
void RemoveAllExtraWhiteSpace()
KVString Next(Bool_t strip_whitespace=kFALSE) const
virtual Int_t Sscanf(const Char_t *fmt,...)
static KVString ULLtoa(ULong64_t value, Int_t base)
static KVString LLtoa(Long64_t value, Int_t base)
Bool_t fEndList
used by Next() & End() to iterate over list
void RandomLetterSequence(Int_t length)
std::vector< KVString > Vectorize(TString delim, Bool_t strip_whitespace=kFALSE)
virtual KVString & Substitute(const Char_t c1, const Char_t c2)
Replace every occurence of 'c1' with 'c2'.
KVString & FindCommonCharacters(const TCollection *, const char bug=' *')
static KVString BaseConvert(const KVString &s_in, Int_t base_in, Int_t base_out)
static KVString UItoa(UInt_t value, Int_t base)
virtual Bool_t Match(TString pattern)
Int_t GetNValues(TString delim) const
static KVString Itoa(Int_t value, Int_t base)
KVString RNext(Bool_t strip_whitespace=kFALSE) const
Int_t fIterIndex
used by Next() to iterate over list
KVString & FindCommonTitleCharacters(const TCollection *, const char bug=' *')
KVString StripAllExtraWhiteSpace() const
void Capitalize()
Change first character of string from lower to upper case.
virtual void SetOwner(Bool_t enable=kTRUE)
const TString & GetString() const
virtual const char * GetName() const
virtual const char * GetTitle() const
virtual UInt_t Integer(UInt_t imax)
static TString UItoa(UInt_t value, Int_t base)
static TString LLtoa(Long64_t value, Int_t base)
static const Ssiz_t kNPOS
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
TSubString Strip(EStripType s=kTrailing, char c=' ') const
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Ssiz_t First(char c) const
TObjArray * Tokenize(const TString &delim) const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Append(char c, Ssiz_t rep=1)
const char * Data() const
static TString BaseConvert(const TString &s_in, Int_t base_in, Int_t base_out)
static TString ULLtoa(ULong64_t value, Int_t base)
Int_t CountChar(Int_t c) const
TString & Prepend(char c, Ssiz_t rep=1)
Bool_t IsInBaseN(Int_t base) const
static TString Format(const char *fmt,...)
static TString Itoa(Int_t value, Int_t base)
Bool_t IsWhitespace() const
void Form(const char *fmt,...)
TString & Remove(EStripType s, char c)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
unsigned long long ULong64_t
Double_t Min(Double_t a, Double_t b)
Double_t Power(Double_t x, Double_t y)