Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TString.h
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Fons Rademakers 04/08/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TString
13#define ROOT_TString
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TString //
19// //
20// Basic string class. //
21// //
22// Cannot be stored in a TCollection... use TObjString instead. //
23// //
24//////////////////////////////////////////////////////////////////////////
25
26#include "Rtypes.h"
27
28#include "TMathBase.h"
29#include <string_view>
30#include "ROOT/TypeTraits.hxx"
31#include "snprintf.h"
32
33#include <iosfwd>
34#include <cstdarg>
35#include <cstdio>
36#include <cstring>
37#include <string>
38#if (__cplusplus >= 202002L)
39# include <compare>
40#endif
41
42class TRegexp;
43class TPRegexp;
44class TString;
45class TSubString;
46class TObjArray;
47class TVirtualMutex;
48class TBuffer;
49class TClass;
50class TBufferFile;
51
52TString operator+(const TString &s1, const TString &s2);
53TString operator+(const TString &s, const char *cs);
54TString operator+(const char *cs, const TString &s);
55TString operator+(const TString &s, char c);
56TString operator+(char c, const TString &s);
57Bool_t operator==(const TString &s1, const TString &s2);
58Bool_t operator==(const TString &s1, const char *s2);
59Bool_t operator==(const TSubString &s1, const TSubString &s2);
60Bool_t operator==(const TSubString &s1, const TString &s2);
61Bool_t operator==(const TSubString &s1, const char *s2);
62/*
63template<class T>
64struct is_signed_numeral : std::integral_constant<bool,
65 std::is_integral<T>::value && std::is_signed<T>::value
66> {};
67
68template<class T>
69struct is_unsigned_numeral : std::integral_constant<bool,
70 std::is_integral<T>::value && !std::is_signed<T>::value
71> {};
72
73template<class T>
74using is_float_numeral = std::is_floating_point<T>;
75*/
76
77//////////////////////////////////////////////////////////////////////////
78// //
79// TSubString //
80// //
81// The TSubString class allows selected elements to be addressed. //
82// There are no public constructors. //
83// //
84//////////////////////////////////////////////////////////////////////////
86
87friend class TStringLong;
88friend class TString;
89
90friend Bool_t operator==(const TSubString &s1, const TSubString &s2);
91friend Bool_t operator==(const TSubString &s1, const TString &s2);
92friend Bool_t operator==(const TSubString &s1, const char *s2);
93
94private:
95 TString &fStr; // Referenced string
96 Ssiz_t fBegin; // Index of starting character
97 Ssiz_t fExtent; // Length of TSubString
98
99 // NB: the only constructor is private
100 TSubString(const TString &s, Ssiz_t start, Ssiz_t len);
101
102protected:
103 void SubStringError(Ssiz_t, Ssiz_t, Ssiz_t) const;
104 void AssertElement(Ssiz_t i) const; // Verifies i is valid index
105
106public:
108 : fStr(s.fStr), fBegin(s.fBegin), fExtent(s.fExtent) { }
109
110 TSubString &operator=(const char *s); // Assignment from a char*
111 TSubString &operator=(const TString &s); // Assignment from a TString
112 TSubString &operator=(const TSubString &s); // Assignment from a TSubString
113 char &operator()(Ssiz_t i); // Index with optional bounds checking
114 char &operator[](Ssiz_t i); // Index with bounds checking
115 char operator()(Ssiz_t i) const; // Index with optional bounds checking
116 char operator[](Ssiz_t i) const; // Index with bounds checking
117
118 operator std::string_view() const { return std::string_view(Data(),fExtent); }
119 operator std::string() const { return std::string(Data(),fExtent); }
120
121 const char *Data() const;
122 Ssiz_t Length() const { return fExtent; }
123 Ssiz_t Start() const { return fBegin; }
124 TString& String() { return fStr; }
125 void ToLower(); // Convert self to lower-case
126 void ToUpper(); // Convert self to upper-case
127
128 // For detecting null substrings
129 Bool_t IsNull() const { return fBegin == kNPOS; }
130 int operator!() const { return fBegin == kNPOS; }
131};
132
133
134//////////////////////////////////////////////////////////////////////////
135// //
136// TString //
137// //
138//////////////////////////////////////////////////////////////////////////
139class TString {
140
141friend class TStringLong;
142friend class TSubString;
143friend class TBufferFile;
144
145friend TString operator+(const TString &s1, const TString &s2);
146friend TString operator+(const TString &s, const char *cs);
147friend TString operator+(const char *cs, const TString &s);
148friend TString operator+(const TString &s, char c);
149friend TString operator+(char c, const TString &s);
150
151template<class T>
152friend typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
153operator+(TString s, T i);
154template<class T>
155friend typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
156operator+(TString s, T u);
157template<class T>
158friend typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
159operator+(TString s, T f);
160template<class T>
161friend typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
162operator+(T i, const TString &s);
163template<class T>
164friend typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
165operator+(T u, const TString &s);
166template<class T>
167friend typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
168operator+(T f, const TString &s);
169
170friend Bool_t operator==(const TString &s1, const TString &s2);
171friend Bool_t operator==(const TString &s1, const char *s2);
172#if __cplusplus >= 202002L
173friend std::strong_ordering operator<=>(const TString &s1, const TString &s2) {
174 const int cmp = s1.CompareTo(s2);
175 if (cmp == 0) return std::strong_ordering::equal;
176 if (cmp < 0) return std::strong_ordering::less;
177 return std::strong_ordering::greater;
178}
179#endif
180
181private:
182#ifdef R__BYTESWAP
183 enum { kShortMask = 0x01, kLongMask = 0x1 };
184#else
185 enum { kShortMask = 0x80, kLongMask = 0x80000000 };
186#endif
187
189 {
190 Ssiz_t fCap; // Max string length (including null)
191 Ssiz_t fSize; // String length (excluding null)
192 char *fData; // Long string data
193 };
194
195 enum { kMinCap = (sizeof(LongStr_t) - 1)/sizeof(char) > 2 ?
196 (sizeof(LongStr_t) - 1)/sizeof(char) : 2 };
197
199 {
200 unsigned char fSize; // String length (excluding null)
201 char fData[kMinCap]; // Short string data
202 };
203
205
206 enum { kNwords = sizeof(UStr_t) / sizeof(Ssiz_t)};
207
208 struct RawStr_t
209 {
211 };
212
213 struct Rep_t
214 {
215 union
216 {
220 };
221 };
222
223protected:
224 Rep_t fRep; //! String data
225
226 // Special concatenation constructor
227 TString(const char *a1, Ssiz_t n1, const char *a2, Ssiz_t n2);
228 void AssertElement(Ssiz_t nc) const; // Index in range
229 Ssiz_t Clobber(Ssiz_t nc); // Remove old contents
230 void InitChar(char c); // Initialize from char
231
232 enum { kAlignment = 16 };
233 static Ssiz_t Align(Ssiz_t s) { return (s + (kAlignment-1)) & ~(kAlignment-1); }
234 static Ssiz_t Recommend(Ssiz_t s) { return (s < kMinCap ? kMinCap : Align(s+1)) - 1; }
235 static Ssiz_t AdjustCapacity(Ssiz_t oldCap, Ssiz_t newCap);
236
237private:
239#ifdef R__BYTESWAP
240 void SetShortSize(Ssiz_t s) { fRep.fShort.fSize = (unsigned char)(s << 1); }
241 Ssiz_t GetShortSize() const { return fRep.fShort.fSize >> 1; }
242#else
243 void SetShortSize(Ssiz_t s) { fRep.fShort.fSize = (unsigned char)s; }
244 Ssiz_t GetShortSize() const { return fRep.fShort.fSize; }
245#endif
247 Ssiz_t GetLongSize() const { return fRep.fLong.fSize; }
250 Ssiz_t GetLongCap() const { return fRep.fLong.fCap & ~kLongMask; }
251 void SetLongPointer(char *p) { fRep.fLong.fData = p; }
252 char *GetLongPointer() { return fRep.fLong.fData; }
253 const char *GetLongPointer() const { return fRep.fLong.fData; }
254 char *GetShortPointer() { return fRep.fShort.fData; }
255 const char *GetShortPointer() const { return fRep.fShort.fData; }
256 char *GetPointer() { return IsLong() ? GetLongPointer() : GetShortPointer(); }
257 const char *GetPointer() const { return IsLong() ? GetLongPointer() : GetShortPointer(); }
258#ifdef R__BYTESWAP
259 static Ssiz_t MaxSize() { return kMaxInt - 1; }
260#else
261 static Ssiz_t MaxSize() { return (kMaxInt >> 1) - 1; }
262#endif
263 void UnLink() const { if (IsLong()) delete [] fRep.fLong.fData; }
264 void Zero() {
266 for (UInt_t i = 0; i < kNwords; ++i)
267 a[i] = 0;
268 }
269 char *Init(Ssiz_t capacity, Ssiz_t nchar);
270 void Clone(Ssiz_t nc); // Make self a distinct copy w. capacity nc
271 void FormImp(const char *fmt, va_list ap);
272 UInt_t HashCase() const;
273 UInt_t HashFoldCase() const;
274
275public:
276 enum EStripType { kLeading = 0x1, kTrailing = 0x2, kBoth = 0x3 };
278 static constexpr Ssiz_t kNPOS = ::kNPOS;
280
281 TString(); // Null string
282 explicit TString(Ssiz_t ic); // Suggested capacity
283 TString(const TString &s); // Copy constructor
284 TString(TString &&s) noexcept; // Move constructor
285 TString(const char *s); // Copy to embedded null
286 TString(const char *s, Ssiz_t n); // Copy past any embedded nulls
287 TString(const std::string &s);
288 TString(char c);
289 TString(char c, Ssiz_t s);
290 explicit TString(const std::string_view &sub);
291 TString(const TSubString &sub);
292
293 virtual ~TString();
294
295 // ROOT I/O interface
296 virtual void FillBuffer(char *&buffer) const;
297 virtual void ReadBuffer(char *&buffer);
298 virtual Int_t Sizeof() const;
299
300 static TString *ReadString(TBuffer &b, const TClass *clReq);
301 static void WriteString(TBuffer &b, const TString *a);
302
303 friend TBuffer &operator<<(TBuffer &b, const TString *obj);
304
305 // C I/O interface
306 Bool_t Gets(FILE *fp, Bool_t chop=kTRUE);
307 void Puts(FILE *fp);
308
309 // Type conversion
310 operator const char*() const { return GetPointer(); }
311#if !defined(_MSC_VER) && (!defined(__clang_major__) || __clang_major__ > 5)
312 // Clang 5.0 support for explicit conversion is still inadequate even in c++17 mode.
313 // (It leads to extraneous ambiguous overload errors)
314 inline explicit operator std::string() const { return std::string(GetPointer(),Length()); }
315#endif
316 inline operator std::string_view() const { return std::string_view(GetPointer(),Length()); }
317
318 // Assignment
319 TString &operator=(char s); // Replace string
320 TString &operator=(const char *s);
321 TString &operator=(const TString &s);
322 TString &operator=(TString &&s) noexcept;
323 TString &operator=(const std::string &s);
324 TString &operator=(const std::string_view &s);
325 TString &operator=(const TSubString &s);
326 TString &operator+=(const char *s); // Append string
327 TString &operator+=(const TString &s);
328 TString &operator+=(char c);
329
330 template<class T>
331 typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
332 &operator+=(T i);
333 template<class T>
334 typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
336 template<class T>
337 typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
339
340 // Indexing operators
341 char &operator[](Ssiz_t i); // Indexing with bounds checking
342 char &operator()(Ssiz_t i); // Indexing with optional bounds checking
343 char operator[](Ssiz_t i) const;
344 char operator()(Ssiz_t i) const;
345 TSubString operator()(Ssiz_t start, Ssiz_t len) const; // Sub-string operator
346 TSubString operator()(const TRegexp &re) const; // Match the RE
347 TSubString operator()(const TRegexp &re, Ssiz_t start) const;
348 TSubString operator()(TPRegexp &re) const; // Match the Perl compatible Regular Expression
349 TSubString operator()(TPRegexp &re, Ssiz_t start) const;
350 TSubString SubString(const char *pat, Ssiz_t start = 0,
351 ECaseCompare cmp = kExact) const;
352
353 // Non-static member functions
354 TString &Append(const char *cs);
355 TString &Append(const char *cs, Ssiz_t n);
356 TString &Append(const TString &s);
357 TString &Append(const TString &s, Ssiz_t n);
358 TString &Append(char c, Ssiz_t rep = 1); // Append c rep times
359 Int_t Atoi() const;
360 Long64_t Atoll() const;
361 Double_t Atof() const;
362 Bool_t BeginsWith(const char *s, ECaseCompare cmp = kExact) const;
363 Bool_t BeginsWith(const TString &pat, ECaseCompare cmp = kExact) const;
364 Ssiz_t Capacity() const { return (IsLong() ? GetLongCap() : kMinCap) - 1; }
366 TString &Chop();
367 void Clear();
368 int CompareTo(const char *cs, ECaseCompare cmp = kExact) const;
369 int CompareTo(const TString &st, ECaseCompare cmp = kExact) const;
370 Bool_t Contains(const char *pat, ECaseCompare cmp = kExact) const;
371 Bool_t Contains(const TString &pat, ECaseCompare cmp = kExact) const;
372 Bool_t Contains(const TRegexp &pat) const;
373 Bool_t Contains(TPRegexp &pat) const;
374 Int_t CountChar(Int_t c) const;
375 TString Copy() const;
376 const char *Data() const { return GetPointer(); }
377 Bool_t EndsWith(const char *pat, ECaseCompare cmp = kExact) const;
378 Bool_t EqualTo(const char *cs, ECaseCompare cmp = kExact) const;
379 Bool_t EqualTo(const TString &st, ECaseCompare cmp = kExact) const;
380 Ssiz_t First(char c) const;
381 Ssiz_t First(const char *cs) const;
382 void Form(const char *fmt, ...)
383#if defined(__GNUC__)
384 __attribute__((format(printf, 2, 3))) /* 1 is the this pointer */
385#endif
386 ;
387 UInt_t Hash(ECaseCompare cmp = kExact) const;
388 Ssiz_t Index(const char *pat, Ssiz_t i = 0,
389 ECaseCompare cmp = kExact) const;
390 Ssiz_t Index(const TString &s, Ssiz_t i = 0,
391 ECaseCompare cmp = kExact) const;
392 Ssiz_t Index(const char *pat, Ssiz_t patlen, Ssiz_t i,
393 ECaseCompare cmp) const;
394 Ssiz_t Index(const TString &s, Ssiz_t patlen, Ssiz_t i,
395 ECaseCompare cmp) const;
396 Ssiz_t Index(const TRegexp &pat, Ssiz_t i = 0) const;
397 Ssiz_t Index(const TRegexp &pat, Ssiz_t *ext, Ssiz_t i = 0) const;
398 Ssiz_t Index(TPRegexp &pat, Ssiz_t i = 0) const;
399 Ssiz_t Index(TPRegexp &pat, Ssiz_t *ext, Ssiz_t i = 0) const;
400 TString &Insert(Ssiz_t pos, const char *s);
401 TString &Insert(Ssiz_t pos, const char *s, Ssiz_t extent);
402 TString &Insert(Ssiz_t pos, const TString &s);
403 TString &Insert(Ssiz_t pos, const TString &s, Ssiz_t extent);
404 Bool_t IsAscii() const;
405 Bool_t IsAlpha() const;
406 Bool_t IsAlnum() const;
407 Bool_t IsDigit() const;
408 Bool_t IsFloat() const;
409 Bool_t IsHex() const;
410 Bool_t IsBin() const;
411 Bool_t IsOct() const;
412 Bool_t IsDec() const;
413 Bool_t IsInBaseN(Int_t base) const;
414 Bool_t IsNull() const { return Length() == 0; }
415 Bool_t IsWhitespace() const { return (Length() == CountChar(' ')); }
416 Ssiz_t Last(char c) const;
417 Ssiz_t Length() const { return IsLong() ? GetLongSize() : GetShortSize(); }
418 Bool_t MaybeRegexp() const;
419 Bool_t MaybeWildcard() const;
420 TString MD5() const;
421 TString &Prepend(const char *cs); // Prepend a character string
422 TString &Prepend(const char *cs, Ssiz_t n);
423 TString &Prepend(const TString &s);
424 TString &Prepend(const TString &s, Ssiz_t n);
425 TString &Prepend(char c, Ssiz_t rep = 1); // Prepend c rep times
426 std::istream &ReadFile(std::istream &str); // Read to EOF or null character
427 std::istream &ReadLine(std::istream &str,
428 Bool_t skipWhite = kTRUE); // Read to EOF or newline
429 std::istream &ReadString(std::istream &str); // Read to EOF or null character
430 std::istream &ReadToDelim(std::istream &str, char delim = '\n'); // Read to EOF or delimitor
431 std::istream &ReadToken(std::istream &str); // Read separated by white space
432 TString &Remove(Ssiz_t pos); // Remove pos to end of string
433 TString &Remove(Ssiz_t pos, Ssiz_t n); // Remove n chars starting at pos
434 TString &Remove(EStripType s, char c); // Like Strip() but changing string directly
435 TString &Replace(Ssiz_t pos, Ssiz_t n, const char *s);
436 TString &Replace(Ssiz_t pos, Ssiz_t n, const char *s, Ssiz_t ns);
437 TString &Replace(Ssiz_t pos, Ssiz_t n, const TString &s);
438 TString &Replace(Ssiz_t pos, Ssiz_t n1, const TString &s, Ssiz_t n2);
439 TString &ReplaceAll(const TString &s1, const TString &s2); // Find&Replace all s1 with s2 if any
440 TString &ReplaceAll(const TString &s1, const char *s2); // Find&Replace all s1 with s2 if any
441 TString &ReplaceAll(const char *s1, const TString &s2); // Find&Replace all s1 with s2 if any
442 TString &ReplaceAll(const char *s1, const char *s2); // Find&Replace all s1 with s2 if any
443 TString &ReplaceAll(const char *s1, Ssiz_t ls1, const char *s2, Ssiz_t ls2); // Find&Replace all s1 with s2 if any
445 void Resize(Ssiz_t n); // Truncate or add blanks as necessary
446 TSubString Strip(EStripType s = kTrailing, char c = ' ') const;
447 TString &Swap(TString &other); // Swap the contents of this and other without reallocation
448 void ToLower(); // Change self to lower-case
449 void ToUpper(); // Change self to upper-case
450 TObjArray *Tokenize(const TString &delim) const;
451 Bool_t Tokenize(TString &tok, Ssiz_t &from, const char *delim = " ") const;
452 std::string_view View() const { return std::string_view(GetPointer(),Length()); }
453
454 // Static member functions
455 static UInt_t Hash(const void *txt, Int_t ntxt); // Calculates hash index from any char string.
456 static Ssiz_t InitialCapacity(Ssiz_t ic = 15); // Initial allocation capacity
457 static Ssiz_t MaxWaste(Ssiz_t mw = 15); // Max empty space before reclaim
458 static Ssiz_t ResizeIncrement(Ssiz_t ri = 16); // Resizing increment
459 static Ssiz_t GetInitialCapacity();
460 static Ssiz_t GetResizeIncrement();
461 static Ssiz_t GetMaxWaste();
462 static TString Itoa ( Int_t value, Int_t base); // Converts int to string with respect to the base specified (2-36)
463 static TString UItoa ( UInt_t value, Int_t base);
464 static TString LLtoa ( Long64_t value, Int_t base);
465 static TString ULLtoa (ULong64_t value, Int_t base);
466 static TString BaseConvert(const TString& s_in, Int_t base_in, Int_t base_out); // Converts string from base base_in to base base_out (supported bases 2-36)
467 static TString Format(const char *fmt, ...)
468#if defined(__GNUC__)
469 __attribute__((format(printf, 1, 2)))
470#endif
471 ;
472
473 ClassDef(TString,2) //Basic string class
474};
475
476// Related global functions
477std::istream &operator>>(std::istream &str, TString &s);
478std::ostream &operator<<(std::ostream &str, const TString &s);
479#if defined(R__TEMPLATE_OVERLOAD_BUG)
480template <>
481#endif
482TBuffer &operator>>(TBuffer &buf, TString *&sp);
483TBuffer &operator<<(TBuffer &buf, const TString * sp);
484
485// Conversion operator (per se).
486inline std::string& operator+=(std::string &left, const TString &right)
487{
488 return left.append(right.Data());
489}
490
491TString ToLower(const TString &s); // Return lower-case version of argument
492TString ToUpper(const TString &s); // Return upper-case version of argument
493
494inline UInt_t Hash(const TString &s) { return s.Hash(); }
495inline UInt_t Hash(const TString *s) { return s->Hash(); }
496 UInt_t Hash(const char *s);
497
498extern char *Form(const char *fmt, ...) // format in circular buffer
499#if defined(__GNUC__)
500__attribute__((format(printf, 1, 2)))
501#endif
502;
503extern void Printf(const char *fmt, ...) // format and print
504#if defined(__GNUC__)
505__attribute__((format(printf, 1, 2)))
506#endif
507;
508extern char *Strip(const char *str, char c = ' '); // strip c off str, free with delete []
509extern char *StrDup(const char *str); // duplicate str, free with delete []
510extern char *Compress(const char *str); // remove blanks from string, free with delele []
511extern int EscChar(const char *src, char *dst, int dstlen, char *specchars,
512 char escchar); // copy from src to dst escaping specchars by escchar
513extern int UnEscChar(const char *src, char *dst, int dstlen, char *specchars,
514 char escchar); // copy from src to dst removing escchar from specchars
515
516#ifdef NEED_STRCASECMP
517extern int strcasecmp(const char *str1, const char *str2);
518extern int strncasecmp(const char *str1, const char *str2, Ssiz_t n);
519#endif
520
521//////////////////////////////////////////////////////////////////////////
522// //
523// Inlines //
524// //
525//////////////////////////////////////////////////////////////////////////
526
527template<class T>
528inline typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
530{ return s += i; }
531
532template<class T>
533inline typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
535{ return s += u; }
536
537template<class T>
538inline typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
540{ return s += f; }
541
542template<class T>
543inline typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
544operator+(T i, const TString &s)
545{
546 char buffer[32];
547 // coverity[secure_coding] Buffer is large enough (2^64 = 20 digits).
548 snprintf(buffer, sizeof(buffer), "%lld", static_cast<Long64_t>(i));
549 return TString(buffer, strlen(buffer), s.Data(), s.Length());
550}
551
552template<class T>
553inline typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
554operator+(T u, const TString &s)
555{
556 char buffer[32];
557 // coverity[secure_coding] Buffer is large enough (2^64 = 20 digits).
558 snprintf(buffer, sizeof(buffer), "%llu", static_cast<ULong64_t>(u));
559 return TString(buffer, strlen(buffer), s.Data(), s.Length());
560}
561
562template<class T>
563inline typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
564operator+(T f, const TString &s)
565{
566 char buffer[32];
567 // coverity[secure_coding] Buffer is large enough: width specified in format
568 snprintf(buffer, sizeof(buffer), "%.17Lg", static_cast<LongDouble_t>(f));
569 return TString(buffer, strlen(buffer), s.Data(), s.Length());
570}
571
572inline TString &TString::Append(const char *cs)
573{ return Replace(Length(), 0, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
574
575inline TString &TString::Append(const char *cs, Ssiz_t n)
576{ return Replace(Length(), 0, cs, n); }
577
579{ return Replace(Length(), 0, s.Data(), s.Length()); }
580
582{ return Replace(Length(), 0, s.Data(), TMath::Min(n, s.Length())); }
583
584inline TString &TString::operator+=(const char *cs)
585{ return Append(cs, cs ? (Ssiz_t)strlen(cs) : 0); }
586
588{ return Append(s.Data(), s.Length()); }
589
591{ return Append(c); }
592
593template<class T>
594inline typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
596{
597 char buffer[32];
598 // coverity[secure_coding] Buffer is large enough (2^64 = 20 digits).
599 snprintf(buffer, sizeof(buffer), "%lld", static_cast<Long64_t>(i));
600 return operator+=(buffer);
601}
602
603template<class T>
604inline typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
606{
607 char buffer[32];
608 // coverity[secure_coding] Buffer is large enough (2^64 = 20 digits).
609 snprintf(buffer, sizeof(buffer), "%llu", static_cast<ULong64_t>(u));
610 return operator+=(buffer);
611}
612
613template<class T>
614inline typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
616{
617 char buffer[32];
618 // coverity[secure_coding] Buffer is large enough: width specified in format
619 snprintf(buffer, sizeof(buffer), "%.17Lg", static_cast<LongDouble_t>(f));
620 return operator+=(buffer);
621}
622
623inline Bool_t TString::BeginsWith(const char *s, ECaseCompare cmp) const
624{ return Index(s, s ? (Ssiz_t)strlen(s) : (Ssiz_t)0, (Ssiz_t)0, cmp) == 0; }
625
626inline Bool_t TString::BeginsWith(const TString &pat, ECaseCompare cmp) const
627{ return Index(pat.Data(), pat.Length(), (Ssiz_t)0, cmp) == 0; }
628
629inline Bool_t TString::Contains(const TString &pat, ECaseCompare cmp) const
630{ return Index(pat.Data(), pat.Length(), (Ssiz_t)0, cmp) != kNPOS; }
631
632inline Bool_t TString::Contains(const char *s, ECaseCompare cmp) const
633{ return Index(s, s ? (Ssiz_t)strlen(s) : 0, (Ssiz_t)0, cmp) != kNPOS; }
634
635////////////////////////////////////////////////////////////////////////////////
636/// \brief Returns whether the string matches the input TRegexp.
637/// \warning Matching regular expressions of type ".?" is not supported. Use
638/// std::regex instead.
639inline Bool_t TString::Contains(const TRegexp &pat) const
640{ return Index(pat, (Ssiz_t)0) != kNPOS; }
641
643{ return Index(pat, (Ssiz_t)0) != kNPOS; }
644
645inline Bool_t TString::EqualTo(const char *cs, ECaseCompare cmp) const
646{ return (CompareTo(cs, cmp) == 0) ? kTRUE : kFALSE; }
647
648inline Bool_t TString::EqualTo(const TString &st, ECaseCompare cmp) const
649{ return (CompareTo(st, cmp) == 0) ? kTRUE : kFALSE; }
650
651inline Ssiz_t TString::Index(const char *s, Ssiz_t i, ECaseCompare cmp) const
652{ return Index(s, s ? (Ssiz_t)strlen(s) : 0, i, cmp); }
653
654inline Ssiz_t TString::Index(const TString &s, Ssiz_t i, ECaseCompare cmp) const
655{ return Index(s.Data(), s.Length(), i, cmp); }
656
657inline Ssiz_t TString::Index(const TString &pat, Ssiz_t patlen, Ssiz_t i,
658 ECaseCompare cmp) const
659{ return Index(pat.Data(), patlen, i, cmp); }
660
661inline TString &TString::Insert(Ssiz_t pos, const char *cs)
662{ return Replace(pos, 0, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
663
664inline TString &TString::Insert(Ssiz_t pos, const char *cs, Ssiz_t n)
665{ return Replace(pos, 0, cs, n); }
666
667inline TString &TString::Insert(Ssiz_t pos, const TString &s)
668{ return Replace(pos, 0, s.Data(), s.Length()); }
669
671{ return Replace(pos, 0, s.Data(), TMath::Min(n, s.Length())); }
672
673inline TString &TString::Prepend(const char *cs)
674{ return Replace(0, 0, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
675
676inline TString &TString::Prepend(const char *cs, Ssiz_t n)
677{ return Replace(0, 0, cs, n); }
678
680{ return Replace(0, 0, s.Data(), s.Length()); }
681
683{ return Replace(0, 0, s.Data(), TMath::Min(n, s.Length())); }
684
686{ return Replace(pos, TMath::Max(0, Length()-pos), nullptr, 0); }
687
689{ return Replace(pos, n, nullptr, 0); }
690
692{ return Remove(TMath::Max(0, Length()-1)); }
693
694inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n, const char *cs)
695{ return Replace(pos, n, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
696
698{ return Replace(pos, n, s.Data(), s.Length()); }
699
700inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n1, const TString &s,
701 Ssiz_t n2)
702{ return Replace(pos, n1, s.Data(), TMath::Min(s.Length(), n2)); }
703
704inline TString &TString::ReplaceAll(const TString &s1, const TString &s2)
705{ return ReplaceAll(s1.Data(), s1.Length(), s2.Data(), s2.Length()) ; }
706
707inline TString &TString::ReplaceAll(const TString &s1, const char *s2)
708{ return ReplaceAll(s1.Data(), s1.Length(), s2, s2 ? (Ssiz_t)strlen(s2) : 0); }
709
710inline TString &TString::ReplaceAll(const char *s1, const TString &s2)
711{ return ReplaceAll(s1, s1 ? (Ssiz_t)strlen(s1) : 0, s2.Data(), s2.Length()); }
712
713inline TString &TString::ReplaceAll(const char *s1,const char *s2)
714{ return ReplaceAll(s1, s1 ? (Ssiz_t)strlen(s1) : 0, s2, s2 ? (Ssiz_t)strlen(s2) : 0); }
715
717 // Swap the contents of other and this without reallocation.
718 Rep_t tmp = other.fRep;
719 other.fRep = fRep;
720 fRep = tmp;
721 return *this;
722}
723
725{ return GetPointer()[i]; }
726
727inline char TString::operator()(Ssiz_t i) const
728{ return GetPointer()[i]; }
729
731{ AssertElement(i); return GetPointer()[i]; }
732
733inline char TString::operator[](Ssiz_t i) const
734{ AssertElement(i); return GetPointer()[i]; }
735
736inline const char *TSubString::Data() const
737{
738 // Return a pointer to the beginning of the substring. Note that the
739 // terminating null is in the same place as for the original
740 // TString, so this method is not appropriate for converting the
741 // TSubString to a string. To do that, construct a TString from the
742 // TSubString. For example:
743 //
744 // root [0] TString s("hello world")
745 // root [1] TSubString sub=s(0, 5)
746 // root [2] sub.Data()
747 // (const char* 0x857c8b8)"hello world"
748 // root [3] TString substr(sub)
749 // root [4] substr
750 // (class TString)"hello"
751
752 return fStr.Data() + fBegin;
753}
754
755// Access to elements of sub-string with bounds checking
756inline char TSubString::operator[](Ssiz_t i) const
757{ AssertElement(i); return fStr.GetPointer()[fBegin+i]; }
758
759inline char TSubString::operator()(Ssiz_t i) const
760{ return fStr.GetPointer()[fBegin+i]; }
761
763{ fStr = s.fStr; fBegin = s.fBegin; fExtent = s.fExtent; return *this; }
764
765
766// String Logical operators
767inline Bool_t operator==(const TString &s1, const TString &s2)
768{
769 return ((s1.Length() == s2.Length()) &&
770 !memcmp(s1.Data(), s2.Data(), s1.Length()));
771}
772
773inline Bool_t operator!=(const TString &s1, const TString &s2)
774{ return !(s1 == s2); }
775
776inline Bool_t operator<(const TString &s1, const TString &s2)
777{ return s1.CompareTo(s2) < 0; }
778
779inline Bool_t operator>(const TString &s1, const TString &s2)
780{ return s1.CompareTo(s2) > 0; }
781
782inline Bool_t operator<=(const TString &s1, const TString &s2)
783{ return s1.CompareTo(s2) <= 0; }
784
785inline Bool_t operator>=(const TString &s1, const TString &s2)
786{ return s1.CompareTo(s2) >= 0; }
787
788// Bool_t operator==(const TString &s1, const char *s2);
789inline Bool_t operator!=(const TString &s1, const char *s2)
790{ return !(s1 == s2); }
791
792inline Bool_t operator<(const TString &s1, const char *s2)
793{ return s1.CompareTo(s2) < 0; }
794
795inline Bool_t operator>(const TString &s1, const char *s2)
796{ return s1.CompareTo(s2) > 0; }
797
798inline Bool_t operator<=(const TString &s1, const char *s2)
799{ return s1.CompareTo(s2) <= 0; }
800
801inline Bool_t operator>=(const TString &s1, const char *s2)
802{ return s1.CompareTo(s2) >= 0; }
803
804inline Bool_t operator==(const char *s1, const TString &s2)
805{ return (s2 == s1); }
806
807inline Bool_t operator!=(const char *s1, const TString &s2)
808{ return !(s2 == s1); }
809
810inline Bool_t operator<(const char *s1, const TString &s2)
811{ return s2.CompareTo(s1) > 0; }
812
813inline Bool_t operator>(const char *s1, const TString &s2)
814{ return s2.CompareTo(s1) < 0; }
815
816inline Bool_t operator<=(const char *s1, const TString &s2)
817{ return s2.CompareTo(s1) >= 0; }
818
819inline Bool_t operator>=(const char *s1, const TString &s2)
820{ return s2.CompareTo(s1) <= 0; }
821
822// SubString Logical operators
823// Bool_t operator==(const TSubString &s1, const TSubString &s2);
824// Bool_t operator==(const TSubString &s1, const char *s2);
825// Bool_t operator==(const TSubString &s1, const TString &s2);
826inline Bool_t operator==(const TString &s1, const TSubString &s2)
827{ return (s2 == s1); }
828
829inline Bool_t operator==(const char *s1, const TSubString &s2)
830{ return (s2 == s1); }
831
832inline Bool_t operator!=(const TSubString &s1, const char *s2)
833{ return !(s1 == s2); }
834
835inline Bool_t operator!=(const TSubString &s1, const TString &s2)
836{ return !(s1 == s2); }
837
838inline Bool_t operator!=(const TSubString &s1, const TSubString &s2)
839{ return !(s1 == s2); }
840
841inline Bool_t operator!=(const TString &s1, const TSubString &s2)
842{ return !(s2 == s1); }
843
844inline Bool_t operator!=(const char *s1, const TSubString &s2)
845{ return !(s2 == s1); }
846
847namespace llvm {
848 class raw_ostream;
849}
850
851namespace cling {
852 std::string printValue(const TString* val);
853 std::string printValue(const TSubString* val);
854 std::string printValue(const std::string_view* val);
855}
856
857#endif
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define s1(x)
Definition RSha256.hxx:91
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Int_t kMaxInt
Definition RtypesCore.h:112
int Ssiz_t
Definition RtypesCore.h:67
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
long double LongDouble_t
Definition RtypesCore.h:61
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:124
long long Long64_t
Definition RtypesCore.h:80
unsigned long long ULong64_t
Definition RtypesCore.h:81
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDef(name, id)
Definition Rtypes.h:337
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition TBuffer.h:397
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t nchar
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
TString ToUpper(const TString &s)
Return an upper-case version of str.
Definition TString.cxx:1511
Bool_t operator!=(const TString &s1, const TString &s2)
Definition TString.h:773
TString ToLower(const TString &s)
Return a lower-case version of str.
Definition TString.cxx:1497
Bool_t operator>(const TString &s1, const TString &s2)
Definition TString.h:779
Bool_t operator>=(const TString &s1, const TString &s2)
Definition TString.h:785
char * Compress(const char *str)
Remove all blanks from the string str.
Definition TString.cxx:2572
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
UInt_t Hash(const TString &s)
Definition TString.h:494
int UnEscChar(const char *src, char *dst, int dstlen, char *specchars, char escchar)
Un-escape specchars in src from escchar and copy to dst.
Definition TString.cxx:2617
Bool_t operator<(const TString &s1, const TString &s2)
Definition TString.h:776
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
Definition TString.cxx:1541
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
Definition TString.cxx:2521
Bool_t operator<=(const TString &s1, const TString &s2)
Definition TString.h:782
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
Bool_t operator==(const TString &s1, const TString &s2)
Definition TString.h:767
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2557
int EscChar(const char *src, char *dst, int dstlen, char *specchars, char escchar)
Escape specchars in src with escchar and copy to dst.
Definition TString.cxx:2593
std::istream & operator>>(std::istream &str, TString &s)
Read string from stream.
Definition Stringio.cxx:169
std::string & operator+=(std::string &left, const TString &right)
Definition TString.h:486
#define snprintf
Definition civetweb.c:1540
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition TBufferFile.h:47
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
An array of TObjects.
Definition TObjArray.h:31
Regular expression class.
Definition TRegexp.h:31
ATTENTION: this class is obsolete.
Definition TStringLong.h:30
Basic string class.
Definition TString.h:139
TString Copy() const
Copy a string.
Definition TString.cxx:529
static TString UItoa(UInt_t value, Int_t base)
Converts a UInt_t (twice the range of an Int_t) to a TString with respect to the base specified (2-36...
Definition TString.cxx:2119
@ kLongMask
Definition TString.h:185
@ kShortMask
Definition TString.h:185
Ssiz_t Length() const
Definition TString.h:417
const char * GetPointer() const
Definition TString.h:257
char & operator[](Ssiz_t i)
Definition TString.h:730
static TString LLtoa(Long64_t value, Int_t base)
Converts a Long64_t to a TString with respect to the base specified (2-36).
Definition TString.cxx:2144
Rep_t fRep
Definition TString.h:224
std::enable_if< ROOT::TypeTraits::IsFloatNumeral< T >::value, TString >::type & operator+=(T f)
void SetShortSize(Ssiz_t s)
Definition TString.h:243
char & operator()(Ssiz_t i)
Definition TString.h:724
Bool_t IsDec() const
Returns true if all characters in string are decimal digits (0-9).
Definition TString.cxx:1940
Bool_t IsLong() const
Definition TString.h:238
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:457
TString & Insert(Ssiz_t pos, const char *s)
Definition TString.h:661
static Ssiz_t MaxWaste(Ssiz_t mw=15)
Set maximum space that may be wasted in a string before doing a resize.
Definition TString.cxx:1612
Int_t Atoi() const
Return integer value of string.
Definition TString.cxx:1988
static Ssiz_t Align(Ssiz_t s)
Definition TString.h:233
@ kNwords
Definition TString.h:206
void SetLongSize(Ssiz_t s)
Definition TString.h:246
Bool_t Gets(FILE *fp, Bool_t chop=kTRUE)
Read one line from the stream, including the \n, or until EOF.
Definition Stringio.cxx:204
std::istream & ReadToDelim(std::istream &str, char delim='\n')
Read up to an EOF, or a delimiting character, whichever comes first.
Definition Stringio.cxx:95
static constexpr Ssiz_t kNPOS
Definition TString.h:278
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2244
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1163
TString()
TString default ctor.
Definition TString.cxx:87
Bool_t IsHex() const
Returns true if all characters in string are hexadecimal digits (0-9,a-f,A-F).
Definition TString.cxx:1892
Double_t Atof() const
Return floating-point value contained in string.
Definition TString.cxx:2054
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1114
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
Definition TString.cxx:1858
void Clear()
Clear string without changing its capacity.
Definition TString.cxx:1235
TSubString SubString(const char *pat, Ssiz_t start=0, ECaseCompare cmp=kExact) const
Returns a substring matching "pattern", or the null substring if there is no such match.
Definition TString.cxx:1657
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:694
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:538
const char * Data() const
Definition TString.h:376
static TString * ReadString(TBuffer &b, const TClass *clReq)
Read TString object from buffer.
Definition TString.cxx:1362
Bool_t EqualTo(const char *cs, ECaseCompare cmp=kExact) const
Definition TString.h:645
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition TString.cxx:1830
TString & Chop()
Definition TString.h:691
Bool_t MaybeRegexp() const
Returns true if string contains one of the regexp characters "^$.[]*+?".
Definition TString.cxx:952
static Ssiz_t ResizeIncrement(Ssiz_t ri=16)
Set default resize increment for all TStrings. Default is 16.
Definition TString.cxx:1602
UInt_t HashCase() const
Return a case-sensitive hash value (endian independent).
Definition TString.cxx:633
Bool_t IsOct() const
Returns true if all characters in string are octal digits (0-7).
Definition TString.cxx:1924
virtual ~TString()
Delete a TString.
Definition TString.cxx:251
Ssiz_t Capacity() const
Definition TString.h:364
static Ssiz_t GetMaxWaste()
Definition TString.cxx:1584
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
static Ssiz_t AdjustCapacity(Ssiz_t oldCap, Ssiz_t newCap)
Calculate a nice capacity greater than or equal to newCap.
Definition TString.cxx:1220
TString MD5() const
Return the MD5 digest for this string, in a string representation.
Definition TString.cxx:940
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition TString.cxx:1152
@ kLeading
Definition TString.h:276
@ kTrailing
Definition TString.h:276
@ kBoth
Definition TString.h:276
ECaseCompare
Definition TString.h:277
@ kIgnoreCase
Definition TString.h:277
@ kExact
Definition TString.h:277
Bool_t IsAlpha() const
Returns true if all characters in string are alphabetic.
Definition TString.cxx:1798
UInt_t HashFoldCase() const
Return a case-insensitive hash value (endian independent).
Definition TString.cxx:662
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:931
void ToUpper()
Change string to upper case.
Definition TString.cxx:1195
Bool_t IsAscii() const
Returns true if all characters in string are ascii.
Definition TString.cxx:1785
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2264
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:623
static Ssiz_t GetResizeIncrement()
Definition TString.cxx:1576
void Puts(FILE *fp)
Write string to the stream.
Definition Stringio.cxx:229
void SetLongCap(Ssiz_t s)
Definition TString.h:249
friend TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
Definition TString.cxx:1541
std::string_view View() const
Definition TString.h:452
@ kAlignment
Definition TString.h:232
TString & Prepend(const char *cs)
Definition TString.h:673
TString & Swap(TString &other)
Definition TString.h:716
Bool_t IsBin() const
Returns true if all characters in string are binary digits (0,1).
Definition TString.cxx:1908
void UnLink() const
Definition TString.h:263
Bool_t IsNull() const
Definition TString.h:414
static TString BaseConvert(const TString &s_in, Int_t base_in, Int_t base_out)
Converts string from base base_in to base base_out.
Definition TString.cxx:2194
static TString ULLtoa(ULong64_t value, Int_t base)
Converts a ULong64_t (twice the range of an Long64_t) to a TString with respect to the base specified...
Definition TString.cxx:2171
Int_t CountChar(Int_t c) const
Return number of times character c occurs in the string.
Definition TString.cxx:515
friend Bool_t operator==(const TString &s1, const TString &s2)
Definition TString.h:767
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition TString.cxx:677
static void WriteString(TBuffer &b, const TString *a)
Write TString object to buffer.
Definition TString.cxx:1428
virtual void FillBuffer(char *&buffer) const
Copy string into I/O buffer.
Definition TString.cxx:1310
TString & operator=(char s)
Assign character c to TString.
Definition TString.cxx:301
std::istream & ReadFile(std::istream &str)
Replace string with the contents of strm, stopping at an EOF.
Definition Stringio.cxx:29
TString & Remove(Ssiz_t pos)
Definition TString.h:685
static Ssiz_t InitialCapacity(Ssiz_t ic=15)
Set default initial capacity for all TStrings. Default is 15.
Definition TString.cxx:1593
char * GetShortPointer()
Definition TString.h:254
TString & Append(const char *cs)
Definition TString.h:572
Bool_t IsInBaseN(Int_t base) const
Returns true if all characters in string are expressed in the base specified (range=2-36),...
Definition TString.cxx:1957
char * Init(Ssiz_t capacity, Ssiz_t nchar)
Private member function returning an empty string representation of size capacity and containing ncha...
Definition TString.cxx:261
Bool_t MaybeWildcard() const
Returns true if string contains one of the wildcard characters "[]*?".
Definition TString.cxx:964
void InitChar(char c)
Initialize a string with a single character.
Definition TString.cxx:148
static Ssiz_t MaxSize()
Definition TString.h:261
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
char * GetLongPointer()
Definition TString.h:252
static TString Itoa(Int_t value, Int_t base)
Converts an Int_t to a TString with respect to the base specified (2-36).
Definition TString.cxx:2092
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
Definition TString.cxx:1401
Ssiz_t Clobber(Ssiz_t nc)
Clear string and make sure it has a capacity of nc.
Definition TString.cxx:1246
TString & operator+=(const char *s)
Definition TString.h:584
Ssiz_t GetShortSize() const
Definition TString.h:244
Bool_t IsWhitespace() const
Definition TString.h:415
void Clone(Ssiz_t nc)
Make self a distinct copy with capacity of at least tot, where tot cannot be smaller than the current...
Definition TString.cxx:1279
void SetSize(Ssiz_t s)
Definition TString.h:248
const char * GetLongPointer() const
Definition TString.h:253
std::enable_if< ROOT::TypeTraits::IsUnsignedNumeral< T >::value, TString >::type & operator+=(T u)
const char * GetShortPointer() const
Definition TString.h:255
void Zero()
Definition TString.h:264
Ssiz_t GetLongCap() const
Definition TString.h:250
void SetLongPointer(char *p)
Definition TString.h:251
std::istream & ReadToken(std::istream &str)
Read a token, delimited by whitespace, from the input stream.
Definition Stringio.cxx:133
Ssiz_t GetLongSize() const
Definition TString.h:247
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
friend TBuffer & operator<<(TBuffer &b, const TString *obj)
Write TString or derived to TBuffer.
Definition TString.cxx:1470
static Ssiz_t GetInitialCapacity()
Definition TString.cxx:1568
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
void AssertElement(Ssiz_t nc) const
Check to make sure a string index is in range.
Definition TString.cxx:1208
virtual void ReadBuffer(char *&buffer)
Read string from I/O buffer.
Definition TString.cxx:1331
Bool_t IsAlnum() const
Returns true if all characters in string are alphanumeric.
Definition TString.cxx:1813
void FormImp(const char *fmt, va_list ap)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2310
char * GetPointer()
Definition TString.h:256
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
static Ssiz_t Recommend(Ssiz_t s)
Definition TString.h:234
std::istream & ReadLine(std::istream &str, Bool_t skipWhite=kTRUE)
Read a line from stream upto newline skipping any whitespace.
Definition Stringio.cxx:71
Long64_t Atoll() const
Return long long value of string.
Definition TString.cxx:2014
A zero length substring is legal.
Definition TString.h:85
TString & String()
Definition TString.h:124
TSubString & operator=(const char *s)
Assign char* to sub-string.
Definition TString.cxx:1696
Bool_t IsNull() const
Definition TString.h:129
void ToUpper()
Convert sub-string to upper-case.
Definition TString.cxx:1754
TString & fStr
Definition TString.h:95
Ssiz_t Start() const
Definition TString.h:123
int operator!() const
Definition TString.h:130
void SubStringError(Ssiz_t, Ssiz_t, Ssiz_t) const
Output error message.
Definition TString.cxx:1766
Ssiz_t fBegin
Definition TString.h:96
char & operator[](Ssiz_t i)
Return character at pos i from sub-string. Check validity of i.
Definition TString.cxx:1668
Ssiz_t fExtent
Definition TString.h:97
friend Bool_t operator==(const TSubString &s1, const TSubString &s2)
Compare two sub-strings.
Definition TString.cxx:1731
void AssertElement(Ssiz_t i) const
Check to make sure a sub-string index is in range.
Definition TString.cxx:1775
void ToLower()
Convert sub-string to lower-case.
Definition TString.cxx:1742
TSubString(const TSubString &s)
Definition TString.h:107
const char * Data() const
Definition TString.h:736
char & operator()(Ssiz_t i)
Return character at pos i from sub-string. No check on i.
Definition TString.cxx:1677
Ssiz_t Length() const
Definition TString.h:122
This class implements a mutex interface.
#define Swap(a, b)
Definition geom.c:201
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Ssiz_t fWords[kNwords]
Definition TString.h:210
RawStr_t fRaw
Definition TString.h:219
ShortStr_t fShort
Definition TString.h:218
LongStr_t fLong
Definition TString.h:217
unsigned char fSize
Definition TString.h:200
char fData[kMinCap]
Definition TString.h:201
LongStr_t fL
Definition TString.h:204
ShortStr_t fS
Definition TString.h:204