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 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;
869 while (!copy.
End()) {
887 std::vector<KVString>
v;
890 v.push_back(
Next(strip_whitespace));
895 #ifdef __WITH_KVSTRING_ITOA
908 const char* cp =
Data();
910 if (len == 0)
return kFALSE;
911 for (
Ssiz_t i = 0; i < len; ++i)
912 if (cp[i] !=
'0' && cp[i] !=
'1')
930 const char* cp =
Data();
932 if (len == 0)
return kFALSE;
933 for (
Ssiz_t i = 0; i < len; ++i)
934 if (!isdigit(cp[i]) || cp[i] ==
'8' || cp[i] ==
'9')
952 const char* cp =
Data();
954 if (len == 0)
return kFALSE;
955 for (
Ssiz_t i = 0; i < len; ++i)
976 if (base < 2 || base > 36) {
977 Error(
"KVString::IsInBaseN",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base);
981 Error(
"KVString::IsInBaseN",
"input string is empty.") ;
986 KVString str_ref0 =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
990 for (
Int_t k = 0; k <
str.Length(); k++) {
1022 #ifdef __WITH_KVSTRING_ITOA
1025 if (base < 2 || base > 36) {
1026 Error(
"KVString::Itoa",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base) ;
1030 Int_t quotient = value;
1033 buf +=
"0123456789abcdefghijklmnopqrstuvwxyz"[
TMath::Abs(quotient % base) ];
1038 if (value < 0) buf +=
'-';
1039 std::reverse(buf.begin(), buf.end());
1061 #ifdef __WITH_KVSTRING_ITOA
1064 if (base < 2 || base > 36) {
1065 Error(
"KVString::UItoa",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base);
1072 buf +=
"0123456789abcdefghijklmnopqrstuvwxyz"[ quotient % base ];
1076 std::reverse(buf.begin(), buf.end());
1098 #ifdef __WITH_KVSTRING_ITOA
1101 if (base < 2 || base > 36) {
1102 Error(
"KVString::LLtoa",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base);
1109 buf +=
"0123456789abcdefghijklmnopqrstuvwxyz"[
TMath::Abs(quotient % base) ];
1114 if (value < 0) buf +=
'-';
1115 std::reverse(buf.begin(), buf.end());
1137 #ifdef __WITH_KVSTRING_ITOA
1140 if (base < 2 || base > 36) {
1141 Error(
"KVString::ULLtoa",
"base %d is not supported. Suppported bases are {2,3,...,36}.", base);
1148 buf +=
"0123456789abcdefghijklmnopqrstuvwxyz"[ quotient % base ];
1152 std::reverse(buf.begin(), buf.end());
1170 #ifdef __WITH_KVSTRING_ITOA
1173 if (base_in < 2 || base_in > 36 || base_out < 2 || base_out > 36) {
1174 Error(
"KVString::BaseConvert",
"only bases 2-36 are supported (base_in=%d, base_out=%d).", base_in, base_out);
1180 if (s_in_[0] ==
'-') {
1184 if (!isSigned && s_in_[0] ==
'+') s_in_.
Remove(0, 1);
1189 Error(
"KVString::BaseConvert",
"s_in=\"%s\" is not in base %d", s_in.
Data(), base_in);
1196 Error(
"KVString::BaseConvert",
"s_in=\"%s\" > %s = 2^64-1 in base %d.", s_in.
Data(), s_max.
Data(), base_in);
1202 if (s_in_ > s_max) {
1204 Error(
"KVString::BaseConvert",
"s_in=\"%s\" > %s = 2^64-1 in base %d.", s_in.
Data(), s_max.
Data(), base_in);
1212 if (isSigned) s_out.
Prepend(
"-");
1235 if (tmp.
Length()) tmp +=
" ";
1257 while (!tmp.
End()) {
1258 if (tmp2.
Length()) tmp2 +=
" ";
1299 while ((o = next())) {
1304 int tmplen = tmp.
Length();
1306 int tmp2len = tmp2.
Length();
1308 for (
int i = 0; i < len; i++) {
1309 if (tmp[i] != tmp2[i]) tmp[i] = bug;
1311 if (tmp2len > tmplen) {
1312 tmp.
Append(bug, tmp2len - tmplen);
1316 int tmplen = tmp.
Length();
1318 bool do_bug =
false;
1319 for (
int i = 0; i < tmplen; i++) {
1321 if (tmp[i] == bug)
continue;
1322 else do_bug =
false;
1324 else if (tmp[i] == bug) {
1369 while ((o = next())) {
1374 int tmplen = tmp.
Length();
1376 int tmp2len = tmp2.
Length();
1378 for (
int i = 0; i < len; i++) {
1379 if (tmp[i] != tmp2[i]) tmp[i] = bug;
1381 if (tmp2len > tmplen) {
1382 tmp.
Append(bug, tmp2len - tmplen);
1386 int tmplen = tmp.
Length();
1388 bool do_bug =
false;
1389 for (
int i = 0; i < tmplen; i++) {
1391 if (tmp[i] == bug)
continue;
1392 else do_bug =
false;
1394 else if (tmp[i] == bug) {
1415 for (
Int_t i = 0; i < length; ++i) {
1417 if (p < 26)
Append((
char)p +
'A');
1418 else Append((
char)(p - 26) +
'a');
1431 if ((*
this)[0] >=
'a' && (*
this)[0] <=
'z')(*this)[0] -= (
'a' -
'A');
1447 TString sy_dec, sy_exp, sey_dec, sey_exp;
1449 Int_t y_exp, ey_exp;
1452 unique_ptr<TObjArray> loa_y(sy.
Tokenize(
"e"));
1454 TIter next_y(loa_y.get());
1461 y_dec = sy_dec.
Atof();
1462 y_exp = sy_exp.
Atoi();
1465 unique_ptr<TObjArray> loa_ey(sey.
Tokenize(
"e"));
1467 TIter next_ey(loa_ey.get());
1476 ey_dec = sey_dec.
Atof();
1477 ey_exp = sey_exp.
Atoi();
1485 if (y_exp == ey_exp)
s =
Format(
"%1.2g.0(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
1486 else s =
Format(
"%1.3g.0(%g.0).10$^{%d}$", y_dec, err, y_exp);
1489 if (y_exp == ey_exp)
s =
Format(
"%1.2g.0(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
1490 else s =
Format(
"%1.3g.0(%g0).10$^{%d}$", y_dec, err, y_exp);
1493 if (y_exp == ey_exp)
s =
Format(
"%1.2g.0(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
1494 else s =
Format(
"%1.3g.0(%g).10$^{%d}$", y_dec, err, y_exp);
1500 if (y_exp == ey_exp)
s =
Format(
"%1.2g0(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
1501 else s =
Format(
"%1.3g0(%g.0).10$^{%d}$", y_dec, err, y_exp);
1504 if (y_exp == ey_exp)
s =
Format(
"%1.2g0(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
1505 else s =
Format(
"%1.3g0(%g0).10$^{%d}$", y_dec, err, y_exp);
1508 if (y_exp == ey_exp)
s =
Format(
"%1.2g0(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
1509 else s =
Format(
"%1.3g0(%g).10$^{%d}$", y_dec, err, y_exp);
1513 if (y_exp == ey_exp)
s =
Format(
"%1.2g(%g.0).10$^{%d}$", y_dec, ey_dec, y_exp);
1514 else s =
Format(
"%1.3g(%g.0).10$^{%d}$", y_dec, err, y_exp);
1517 if (y_exp == ey_exp)
s =
Format(
"%1.2g(%g0).10$^{%d}$", y_dec, ey_dec, y_exp);
1518 else s =
Format(
"%1.3g(%g0).10$^{%d}$", y_dec, err, y_exp);
1521 if (y_exp == ey_exp)
s =
Format(
"%1.2g(%g).10$^{%d}$", y_dec, ey_dec, y_exp);
1522 else s =
Format(
"%1.3g(%g).10$^{%d}$", y_dec, err, y_exp);;
1525 s.ReplaceAll(
".10$^{0}$",
"");
1526 s.ReplaceAll(
"0)",
")");
1528 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
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)