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#ifndef __CINT__
225 Rep_t fRep; //! String data
226#endif
227
228 // Special concatenation constructor
229 TString(const char *a1, Ssiz_t n1, const char *a2, Ssiz_t n2);
230 void AssertElement(Ssiz_t nc) const; // Index in range
231 Ssiz_t Clobber(Ssiz_t nc); // Remove old contents
232 void InitChar(char c); // Initialize from char
233
234 enum { kAlignment = 16 };
235 static Ssiz_t Align(Ssiz_t s) { return (s + (kAlignment-1)) & ~(kAlignment-1); }
236 static Ssiz_t Recommend(Ssiz_t s) { return (s < kMinCap ? kMinCap : Align(s+1)) - 1; }
237 static Ssiz_t AdjustCapacity(Ssiz_t oldCap, Ssiz_t newCap);
238
239private:
241#ifdef R__BYTESWAP
242 void SetShortSize(Ssiz_t s) { fRep.fShort.fSize = (unsigned char)(s << 1); }
243 Ssiz_t GetShortSize() const { return fRep.fShort.fSize >> 1; }
244#else
245 void SetShortSize(Ssiz_t s) { fRep.fShort.fSize = (unsigned char)s; }
246 Ssiz_t GetShortSize() const { return fRep.fShort.fSize; }
247#endif
249 Ssiz_t GetLongSize() const { return fRep.fLong.fSize; }
252 Ssiz_t GetLongCap() const { return fRep.fLong.fCap & ~kLongMask; }
253 void SetLongPointer(char *p) { fRep.fLong.fData = p; }
254 char *GetLongPointer() { return fRep.fLong.fData; }
255 const char *GetLongPointer() const { return fRep.fLong.fData; }
256 char *GetShortPointer() { return fRep.fShort.fData; }
257 const char *GetShortPointer() const { return fRep.fShort.fData; }
258 char *GetPointer() { return IsLong() ? GetLongPointer() : GetShortPointer(); }
259 const char *GetPointer() const { return IsLong() ? GetLongPointer() : GetShortPointer(); }
260#ifdef R__BYTESWAP
261 static Ssiz_t MaxSize() { return kMaxInt - 1; }
262#else
263 static Ssiz_t MaxSize() { return (kMaxInt >> 1) - 1; }
264#endif
265 void UnLink() const { if (IsLong()) delete [] fRep.fLong.fData; }
266 void Zero() {
268 for (UInt_t i = 0; i < kNwords; ++i)
269 a[i] = 0;
270 }
271 char *Init(Ssiz_t capacity, Ssiz_t nchar);
272 void Clone(Ssiz_t nc); // Make self a distinct copy w. capacity nc
273 void FormImp(const char *fmt, va_list ap);
274 UInt_t HashCase() const;
275 UInt_t HashFoldCase() const;
276
277public:
278 enum EStripType { kLeading = 0x1, kTrailing = 0x2, kBoth = 0x3 };
280 static constexpr Ssiz_t kNPOS = ::kNPOS;
282
283 TString(); // Null string
284 explicit TString(Ssiz_t ic); // Suggested capacity
285 TString(const TString &s); // Copy constructor
286 TString(TString &&s) noexcept; // Move constructor
287 TString(const char *s); // Copy to embedded null
288 TString(const char *s, Ssiz_t n); // Copy past any embedded nulls
289 TString(const std::string &s);
290 TString(char c);
291 TString(char c, Ssiz_t s);
292 explicit TString(const std::string_view &sub);
293 TString(const TSubString &sub);
294
295 virtual ~TString();
296
297 // ROOT I/O interface
298 virtual void FillBuffer(char *&buffer) const;
299 virtual void ReadBuffer(char *&buffer);
300 virtual Int_t Sizeof() const;
301
302 static TString *ReadString(TBuffer &b, const TClass *clReq);
303 static void WriteString(TBuffer &b, const TString *a);
304
305 friend TBuffer &operator<<(TBuffer &b, const TString *obj);
306
307 // C I/O interface
308 Bool_t Gets(FILE *fp, Bool_t chop=kTRUE);
309 void Puts(FILE *fp);
310
311 // Type conversion
312 operator const char*() const { return GetPointer(); }
313#if !defined(_MSC_VER) && (!defined(__clang_major__) || __clang_major__ > 5)
314 // Clang 5.0 support for explicit conversion is still inadequate even in c++17 mode.
315 // (It leads to extraneous ambiguous overload errors)
316 inline explicit operator std::string() const { return std::string(GetPointer(),Length()); }
317#endif
318 inline operator std::string_view() const { return std::string_view(GetPointer(),Length()); }
319
320 // Assignment
321 TString &operator=(char s); // Replace string
322 TString &operator=(const char *s);
323 TString &operator=(const TString &s);
324 TString &operator=(TString &&s) noexcept;
325 TString &operator=(const std::string &s);
326 TString &operator=(const std::string_view &s);
327 TString &operator=(const TSubString &s);
328 TString &operator+=(const char *s); // Append string
329 TString &operator+=(const TString &s);
330 TString &operator+=(char c);
331
332 template<class T>
333 typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
334 &operator+=(T i);
335 template<class T>
336 typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
338 template<class T>
339 typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
341
342 // Indexing operators
343 char &operator[](Ssiz_t i); // Indexing with bounds checking
344 char &operator()(Ssiz_t i); // Indexing with optional bounds checking
345 char operator[](Ssiz_t i) const;
346 char operator()(Ssiz_t i) const;
347 TSubString operator()(Ssiz_t start, Ssiz_t len) const; // Sub-string operator
348 TSubString operator()(const TRegexp &re) const; // Match the RE
349 TSubString operator()(const TRegexp &re, Ssiz_t start) const;
350 TSubString operator()(TPRegexp &re) const; // Match the Perl compatible Regular Expression
351 TSubString operator()(TPRegexp &re, Ssiz_t start) const;
352 TSubString SubString(const char *pat, Ssiz_t start = 0,
353 ECaseCompare cmp = kExact) const;
354
355 // Non-static member functions
356 TString &Append(const char *cs);
357 TString &Append(const char *cs, Ssiz_t n);
358 TString &Append(const TString &s);
359 TString &Append(const TString &s, Ssiz_t n);
360 TString &Append(char c, Ssiz_t rep = 1); // Append c rep times
361 Int_t Atoi() const;
362 Long64_t Atoll() const;
363 Double_t Atof() const;
364 Bool_t BeginsWith(const char *s, ECaseCompare cmp = kExact) const;
365 Bool_t BeginsWith(const TString &pat, ECaseCompare cmp = kExact) const;
366 Ssiz_t Capacity() const { return (IsLong() ? GetLongCap() : kMinCap) - 1; }
368 TString &Chop();
369 void Clear();
370 int CompareTo(const char *cs, ECaseCompare cmp = kExact) const;
371 int CompareTo(const TString &st, ECaseCompare cmp = kExact) const;
372 Bool_t Contains(const char *pat, ECaseCompare cmp = kExact) const;
373 Bool_t Contains(const TString &pat, ECaseCompare cmp = kExact) const;
374 Bool_t Contains(const TRegexp &pat) const;
375 Bool_t Contains(TPRegexp &pat) const;
376 Int_t CountChar(Int_t c) const;
377 TString Copy() const;
378 const char *Data() const { return GetPointer(); }
379 Bool_t EndsWith(const char *pat, ECaseCompare cmp = kExact) const;
380 Bool_t EqualTo(const char *cs, ECaseCompare cmp = kExact) const;
381 Bool_t EqualTo(const TString &st, ECaseCompare cmp = kExact) const;
382 Ssiz_t First(char c) const;
383 Ssiz_t First(const char *cs) const;
384 void Form(const char *fmt, ...)
385#if defined(__GNUC__) && !defined(__CINT__)
386 __attribute__((format(printf, 2, 3))) /* 1 is the this pointer */
387#endif
388 ;
389 UInt_t Hash(ECaseCompare cmp = kExact) const;
390 Ssiz_t Index(const char *pat, Ssiz_t i = 0,
391 ECaseCompare cmp = kExact) const;
392 Ssiz_t Index(const TString &s, Ssiz_t i = 0,
393 ECaseCompare cmp = kExact) const;
394 Ssiz_t Index(const char *pat, Ssiz_t patlen, Ssiz_t i,
395 ECaseCompare cmp) const;
396 Ssiz_t Index(const TString &s, Ssiz_t patlen, Ssiz_t i,
397 ECaseCompare cmp) const;
398 Ssiz_t Index(const TRegexp &pat, Ssiz_t i = 0) const;
399 Ssiz_t Index(const TRegexp &pat, Ssiz_t *ext, Ssiz_t i = 0) const;
400 Ssiz_t Index(TPRegexp &pat, Ssiz_t i = 0) const;
401 Ssiz_t Index(TPRegexp &pat, Ssiz_t *ext, Ssiz_t i = 0) const;
402 TString &Insert(Ssiz_t pos, const char *s);
403 TString &Insert(Ssiz_t pos, const char *s, Ssiz_t extent);
404 TString &Insert(Ssiz_t pos, const TString &s);
405 TString &Insert(Ssiz_t pos, const TString &s, Ssiz_t extent);
406 Bool_t IsAscii() const;
407 Bool_t IsAlpha() const;
408 Bool_t IsAlnum() const;
409 Bool_t IsDigit() const;
410 Bool_t IsFloat() const;
411 Bool_t IsHex() const;
412 Bool_t IsBin() const;
413 Bool_t IsOct() const;
414 Bool_t IsDec() const;
415 Bool_t IsInBaseN(Int_t base) const;
416 Bool_t IsNull() const { return Length() == 0; }
417 Bool_t IsWhitespace() const { return (Length() == CountChar(' ')); }
418 Ssiz_t Last(char c) const;
419 Ssiz_t Length() const { return IsLong() ? GetLongSize() : GetShortSize(); }
420 Bool_t MaybeRegexp() const;
421 Bool_t MaybeWildcard() const;
422 TString MD5() const;
423 TString &Prepend(const char *cs); // Prepend a character string
424 TString &Prepend(const char *cs, Ssiz_t n);
425 TString &Prepend(const TString &s);
426 TString &Prepend(const TString &s, Ssiz_t n);
427 TString &Prepend(char c, Ssiz_t rep = 1); // Prepend c rep times
428 std::istream &ReadFile(std::istream &str); // Read to EOF or null character
429 std::istream &ReadLine(std::istream &str,
430 Bool_t skipWhite = kTRUE); // Read to EOF or newline
431 std::istream &ReadString(std::istream &str); // Read to EOF or null character
432 std::istream &ReadToDelim(std::istream &str, char delim = '\n'); // Read to EOF or delimitor
433 std::istream &ReadToken(std::istream &str); // Read separated by white space
434 TString &Remove(Ssiz_t pos); // Remove pos to end of string
435 TString &Remove(Ssiz_t pos, Ssiz_t n); // Remove n chars starting at pos
436 TString &Remove(EStripType s, char c); // Like Strip() but changing string directly
437 TString &Replace(Ssiz_t pos, Ssiz_t n, const char *s);
438 TString &Replace(Ssiz_t pos, Ssiz_t n, const char *s, Ssiz_t ns);
439 TString &Replace(Ssiz_t pos, Ssiz_t n, const TString &s);
440 TString &Replace(Ssiz_t pos, Ssiz_t n1, const TString &s, Ssiz_t n2);
441 TString &ReplaceAll(const TString &s1, const TString &s2); // Find&Replace all s1 with s2 if any
442 TString &ReplaceAll(const TString &s1, const char *s2); // Find&Replace all s1 with s2 if any
443 TString &ReplaceAll(const char *s1, const TString &s2); // Find&Replace all s1 with s2 if any
444 TString &ReplaceAll(const char *s1, const char *s2); // Find&Replace all s1 with s2 if any
445 TString &ReplaceAll(const char *s1, Ssiz_t ls1, const char *s2, Ssiz_t ls2); // Find&Replace all s1 with s2 if any
447 void Resize(Ssiz_t n); // Truncate or add blanks as necessary
448 TSubString Strip(EStripType s = kTrailing, char c = ' ') const;
449 TString &Swap(TString &other); // Swap the contents of this and other without reallocation
450 void ToLower(); // Change self to lower-case
451 void ToUpper(); // Change self to upper-case
452 TObjArray *Tokenize(const TString &delim) const;
453 Bool_t Tokenize(TString &tok, Ssiz_t &from, const char *delim = " ") const;
454 std::string_view View() const { return std::string_view(GetPointer(),Length()); }
455
456 // Static member functions
457 static UInt_t Hash(const void *txt, Int_t ntxt); // Calculates hash index from any char string.
458 static Ssiz_t InitialCapacity(Ssiz_t ic = 15); // Initial allocation capacity
459 static Ssiz_t MaxWaste(Ssiz_t mw = 15); // Max empty space before reclaim
460 static Ssiz_t ResizeIncrement(Ssiz_t ri = 16); // Resizing increment
461 static Ssiz_t GetInitialCapacity();
462 static Ssiz_t GetResizeIncrement();
463 static Ssiz_t GetMaxWaste();
464 static TString Itoa ( Int_t value, Int_t base); // Converts int to string with respect to the base specified (2-36)
465 static TString UItoa ( UInt_t value, Int_t base);
466 static TString LLtoa ( Long64_t value, Int_t base);
467 static TString ULLtoa (ULong64_t value, Int_t base);
468 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)
469 static TString Format(const char *fmt, ...)
470#if defined(__GNUC__) && !defined(__CINT__)
471 __attribute__((format(printf, 1, 2)))
472#endif
473 ;
474
475 ClassDef(TString,2) //Basic string class
476};
477
478// Related global functions
479std::istream &operator>>(std::istream &str, TString &s);
480std::ostream &operator<<(std::ostream &str, const TString &s);
481#if defined(R__TEMPLATE_OVERLOAD_BUG)
482template <>
483#endif
484TBuffer &operator>>(TBuffer &buf, TString *&sp);
485TBuffer &operator<<(TBuffer &buf, const TString * sp);
486
487// Conversion operator (per se).
488inline std::string& operator+=(std::string &left, const TString &right)
489{
490 return left.append(right.Data());
491}
492
493TString ToLower(const TString &s); // Return lower-case version of argument
494TString ToUpper(const TString &s); // Return upper-case version of argument
495
496inline UInt_t Hash(const TString &s) { return s.Hash(); }
497inline UInt_t Hash(const TString *s) { return s->Hash(); }
498 UInt_t Hash(const char *s);
499
500extern char *Form(const char *fmt, ...) // format in circular buffer
501#if defined(__GNUC__) && !defined(__CINT__)
502__attribute__((format(printf, 1, 2)))
503#endif
504;
505extern void Printf(const char *fmt, ...) // format and print
506#if defined(__GNUC__) && !defined(__CINT__)
507__attribute__((format(printf, 1, 2)))
508#endif
509;
510extern char *Strip(const char *str, char c = ' '); // strip c off str, free with delete []
511extern char *StrDup(const char *str); // duplicate str, free with delete []
512extern char *Compress(const char *str); // remove blanks from string, free with delele []
513extern int EscChar(const char *src, char *dst, int dstlen, char *specchars,
514 char escchar); // copy from src to dst escaping specchars by escchar
515extern int UnEscChar(const char *src, char *dst, int dstlen, char *specchars,
516 char escchar); // copy from src to dst removing escchar from specchars
517
518#ifdef NEED_STRCASECMP
519extern int strcasecmp(const char *str1, const char *str2);
520extern int strncasecmp(const char *str1, const char *str2, Ssiz_t n);
521#endif
522
523//////////////////////////////////////////////////////////////////////////
524// //
525// Inlines //
526// //
527//////////////////////////////////////////////////////////////////////////
528
529template<class T>
530inline typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
532{ return s += i; }
533
534template<class T>
535inline typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
537{ return s += u; }
538
539template<class T>
540inline typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
542{ return s += f; }
543
544template<class T>
545inline typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
546operator+(T i, const TString &s)
547{
548 char buffer[32];
549 // coverity[secure_coding] Buffer is large enough (2^64 = 20 digits).
550 snprintf(buffer, sizeof(buffer), "%lld", static_cast<Long64_t>(i));
551 return TString(buffer, strlen(buffer), s.Data(), s.Length());
552}
553
554template<class T>
555inline typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
556operator+(T u, const TString &s)
557{
558 char buffer[32];
559 // coverity[secure_coding] Buffer is large enough (2^64 = 20 digits).
560 snprintf(buffer, sizeof(buffer), "%llu", static_cast<ULong64_t>(u));
561 return TString(buffer, strlen(buffer), s.Data(), s.Length());
562}
563
564template<class T>
565inline typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
566operator+(T f, const TString &s)
567{
568 char buffer[32];
569 // coverity[secure_coding] Buffer is large enough: width specified in format
570 snprintf(buffer, sizeof(buffer), "%.17Lg", static_cast<LongDouble_t>(f));
571 return TString(buffer, strlen(buffer), s.Data(), s.Length());
572}
573
574inline TString &TString::Append(const char *cs)
575{ return Replace(Length(), 0, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
576
577inline TString &TString::Append(const char *cs, Ssiz_t n)
578{ return Replace(Length(), 0, cs, n); }
579
581{ return Replace(Length(), 0, s.Data(), s.Length()); }
582
584{ return Replace(Length(), 0, s.Data(), TMath::Min(n, s.Length())); }
585
586inline TString &TString::operator+=(const char *cs)
587{ return Append(cs, cs ? (Ssiz_t)strlen(cs) : 0); }
588
590{ return Append(s.Data(), s.Length()); }
591
593{ return Append(c); }
594
595template<class T>
596inline typename std::enable_if<ROOT::TypeTraits::IsSignedNumeral<T>::value,TString>::type
598{
599 char buffer[32];
600 // coverity[secure_coding] Buffer is large enough (2^64 = 20 digits).
601 snprintf(buffer, sizeof(buffer), "%lld", static_cast<Long64_t>(i));
602 return operator+=(buffer);
603}
604
605template<class T>
606inline typename std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral<T>::value,TString>::type
608{
609 char buffer[32];
610 // coverity[secure_coding] Buffer is large enough (2^64 = 20 digits).
611 snprintf(buffer, sizeof(buffer), "%llu", static_cast<ULong64_t>(u));
612 return operator+=(buffer);
613}
614
615template<class T>
616inline typename std::enable_if<ROOT::TypeTraits::IsFloatNumeral<T>::value,TString>::type
618{
619 char buffer[32];
620 // coverity[secure_coding] Buffer is large enough: width specified in format
621 snprintf(buffer, sizeof(buffer), "%.17Lg", static_cast<LongDouble_t>(f));
622 return operator+=(buffer);
623}
624
625inline Bool_t TString::BeginsWith(const char *s, ECaseCompare cmp) const
626{ return Index(s, s ? (Ssiz_t)strlen(s) : (Ssiz_t)0, (Ssiz_t)0, cmp) == 0; }
627
628inline Bool_t TString::BeginsWith(const TString &pat, ECaseCompare cmp) const
629{ return Index(pat.Data(), pat.Length(), (Ssiz_t)0, cmp) == 0; }
630
631inline Bool_t TString::Contains(const TString &pat, ECaseCompare cmp) const
632{ return Index(pat.Data(), pat.Length(), (Ssiz_t)0, cmp) != kNPOS; }
633
634inline Bool_t TString::Contains(const char *s, ECaseCompare cmp) const
635{ return Index(s, s ? (Ssiz_t)strlen(s) : 0, (Ssiz_t)0, cmp) != kNPOS; }
636
637////////////////////////////////////////////////////////////////////////////////
638/// \brief Returns whether the string matches the input TRegexp.
639/// \warning Matching regular expressions of type ".?" is not supported. Use
640/// std::regex instead.
641inline Bool_t TString::Contains(const TRegexp &pat) const
642{ return Index(pat, (Ssiz_t)0) != kNPOS; }
643
645{ return Index(pat, (Ssiz_t)0) != kNPOS; }
646
647inline Bool_t TString::EqualTo(const char *cs, ECaseCompare cmp) const
648{ return (CompareTo(cs, cmp) == 0) ? kTRUE : kFALSE; }
649
650inline Bool_t TString::EqualTo(const TString &st, ECaseCompare cmp) const
651{ return (CompareTo(st, cmp) == 0) ? kTRUE : kFALSE; }
652
653inline Ssiz_t TString::Index(const char *s, Ssiz_t i, ECaseCompare cmp) const
654{ return Index(s, s ? (Ssiz_t)strlen(s) : 0, i, cmp); }
655
656inline Ssiz_t TString::Index(const TString &s, Ssiz_t i, ECaseCompare cmp) const
657{ return Index(s.Data(), s.Length(), i, cmp); }
658
659inline Ssiz_t TString::Index(const TString &pat, Ssiz_t patlen, Ssiz_t i,
660 ECaseCompare cmp) const
661{ return Index(pat.Data(), patlen, i, cmp); }
662
663inline TString &TString::Insert(Ssiz_t pos, const char *cs)
664{ return Replace(pos, 0, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
665
666inline TString &TString::Insert(Ssiz_t pos, const char *cs, Ssiz_t n)
667{ return Replace(pos, 0, cs, n); }
668
669inline TString &TString::Insert(Ssiz_t pos, const TString &s)
670{ return Replace(pos, 0, s.Data(), s.Length()); }
671
673{ return Replace(pos, 0, s.Data(), TMath::Min(n, s.Length())); }
674
675inline TString &TString::Prepend(const char *cs)
676{ return Replace(0, 0, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
677
678inline TString &TString::Prepend(const char *cs, Ssiz_t n)
679{ return Replace(0, 0, cs, n); }
680
682{ return Replace(0, 0, s.Data(), s.Length()); }
683
685{ return Replace(0, 0, s.Data(), TMath::Min(n, s.Length())); }
686
688{ return Replace(pos, TMath::Max(0, Length()-pos), nullptr, 0); }
689
691{ return Replace(pos, n, nullptr, 0); }
692
694{ return Remove(TMath::Max(0, Length()-1)); }
695
696inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n, const char *cs)
697{ return Replace(pos, n, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
698
700{ return Replace(pos, n, s.Data(), s.Length()); }
701
702inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n1, const TString &s,
703 Ssiz_t n2)
704{ return Replace(pos, n1, s.Data(), TMath::Min(s.Length(), n2)); }
705
706inline TString &TString::ReplaceAll(const TString &s1, const TString &s2)
707{ return ReplaceAll(s1.Data(), s1.Length(), s2.Data(), s2.Length()) ; }
708
709inline TString &TString::ReplaceAll(const TString &s1, const char *s2)
710{ return ReplaceAll(s1.Data(), s1.Length(), s2, s2 ? (Ssiz_t)strlen(s2) : 0); }
711
712inline TString &TString::ReplaceAll(const char *s1, const TString &s2)
713{ return ReplaceAll(s1, s1 ? (Ssiz_t)strlen(s1) : 0, s2.Data(), s2.Length()); }
714
715inline TString &TString::ReplaceAll(const char *s1,const char *s2)
716{ return ReplaceAll(s1, s1 ? (Ssiz_t)strlen(s1) : 0, s2, s2 ? (Ssiz_t)strlen(s2) : 0); }
717
719 // Swap the contents of other and this without reallocation.
720#ifndef __CINT__
721 Rep_t tmp = other.fRep;
722 other.fRep = fRep;
723 fRep = tmp;
724#endif
725 return *this;
726}
727
729{ return GetPointer()[i]; }
730
731inline char TString::operator()(Ssiz_t i) const
732{ return GetPointer()[i]; }
733
735{ AssertElement(i); return GetPointer()[i]; }
736
737inline char TString::operator[](Ssiz_t i) const
738{ AssertElement(i); return GetPointer()[i]; }
739
740inline const char *TSubString::Data() const
741{
742 // Return a pointer to the beginning of the substring. Note that the
743 // terminating null is in the same place as for the original
744 // TString, so this method is not appropriate for converting the
745 // TSubString to a string. To do that, construct a TString from the
746 // TSubString. For example:
747 //
748 // root [0] TString s("hello world")
749 // root [1] TSubString sub=s(0, 5)
750 // root [2] sub.Data()
751 // (const char* 0x857c8b8)"hello world"
752 // root [3] TString substr(sub)
753 // root [4] substr
754 // (class TString)"hello"
755
756 return fStr.Data() + fBegin;
757}
758
759// Access to elements of sub-string with bounds checking
760inline char TSubString::operator[](Ssiz_t i) const
761{ AssertElement(i); return fStr.GetPointer()[fBegin+i]; }
762
763inline char TSubString::operator()(Ssiz_t i) const
764{ return fStr.GetPointer()[fBegin+i]; }
765
767{ fStr = s.fStr; fBegin = s.fBegin; fExtent = s.fExtent; return *this; }
768
769
770// String Logical operators
771inline Bool_t operator==(const TString &s1, const TString &s2)
772{
773 return ((s1.Length() == s2.Length()) &&
774 !memcmp(s1.Data(), s2.Data(), s1.Length()));
775}
776
777inline Bool_t operator!=(const TString &s1, const TString &s2)
778{ return !(s1 == s2); }
779
780inline Bool_t operator<(const TString &s1, const TString &s2)
781{ return s1.CompareTo(s2) < 0; }
782
783inline Bool_t operator>(const TString &s1, const TString &s2)
784{ return s1.CompareTo(s2) > 0; }
785
786inline Bool_t operator<=(const TString &s1, const TString &s2)
787{ return s1.CompareTo(s2) <= 0; }
788
789inline Bool_t operator>=(const TString &s1, const TString &s2)
790{ return s1.CompareTo(s2) >= 0; }
791
792// Bool_t operator==(const TString &s1, const char *s2);
793inline Bool_t operator!=(const TString &s1, const char *s2)
794{ return !(s1 == s2); }
795
796inline Bool_t operator<(const TString &s1, const char *s2)
797{ return s1.CompareTo(s2) < 0; }
798
799inline Bool_t operator>(const TString &s1, const char *s2)
800{ return s1.CompareTo(s2) > 0; }
801
802inline Bool_t operator<=(const TString &s1, const char *s2)
803{ return s1.CompareTo(s2) <= 0; }
804
805inline Bool_t operator>=(const TString &s1, const char *s2)
806{ return s1.CompareTo(s2) >= 0; }
807
808inline Bool_t operator==(const char *s1, const TString &s2)
809{ return (s2 == s1); }
810
811inline Bool_t operator!=(const char *s1, const TString &s2)
812{ return !(s2 == s1); }
813
814inline Bool_t operator<(const char *s1, const TString &s2)
815{ return s2.CompareTo(s1) > 0; }
816
817inline Bool_t operator>(const char *s1, const TString &s2)
818{ return s2.CompareTo(s1) < 0; }
819
820inline Bool_t operator<=(const char *s1, const TString &s2)
821{ return s2.CompareTo(s1) >= 0; }
822
823inline Bool_t operator>=(const char *s1, const TString &s2)
824{ return s2.CompareTo(s1) <= 0; }
825
826// SubString Logical operators
827// Bool_t operator==(const TSubString &s1, const TSubString &s2);
828// Bool_t operator==(const TSubString &s1, const char *s2);
829// Bool_t operator==(const TSubString &s1, const TString &s2);
830inline Bool_t operator==(const TString &s1, const TSubString &s2)
831{ return (s2 == s1); }
832
833inline Bool_t operator==(const char *s1, const TSubString &s2)
834{ return (s2 == s1); }
835
836inline Bool_t operator!=(const TSubString &s1, const char *s2)
837{ return !(s1 == s2); }
838
839inline Bool_t operator!=(const TSubString &s1, const TString &s2)
840{ return !(s1 == s2); }
841
842inline Bool_t operator!=(const TSubString &s1, const TSubString &s2)
843{ return !(s1 == s2); }
844
845inline Bool_t operator!=(const TString &s1, const TSubString &s2)
846{ return !(s2 == s1); }
847
848inline Bool_t operator!=(const char *s1, const TSubString &s2)
849{ return !(s2 == s1); }
850
851namespace llvm {
852 class raw_ostream;
853}
854
855namespace cling {
856 std::string printValue(const TString* val);
857 std::string printValue(const TSubString* val);
858 std::string printValue(const std::string_view* val);
859}
860
861#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:399
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:777
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:783
Bool_t operator>=(const TString &s1, const TString &s2)
Definition TString.h:789
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:496
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:780
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:786
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:771
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:488
#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:419
const char * GetPointer() const
Definition TString.h:259
char & operator[](Ssiz_t i)
Definition TString.h:734
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:225
std::enable_if< ROOT::TypeTraits::IsFloatNumeral< T >::value, TString >::type & operator+=(T f)
void SetShortSize(Ssiz_t s)
Definition TString.h:245
char & operator()(Ssiz_t i)
Definition TString.h:728
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:240
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:663
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:235
@ kNwords
Definition TString.h:206
void SetLongSize(Ssiz_t s)
Definition TString.h:248
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:280
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:696
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:538
const char * Data() const
Definition TString.h:378
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:647
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:693
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:366
static Ssiz_t GetMaxWaste()
Definition TString.cxx:1584
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:706
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:278
@ kTrailing
Definition TString.h:278
@ kBoth
Definition TString.h:278
ECaseCompare
Definition TString.h:279
@ kIgnoreCase
Definition TString.h:279
@ kExact
Definition TString.h:279
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:625
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:251
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:454
@ kAlignment
Definition TString.h:234
TString & Prepend(const char *cs)
Definition TString.h:675
TString & Swap(TString &other)
Definition TString.h:718
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:265
Bool_t IsNull() const
Definition TString.h:416
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:771
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:687
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:256
TString & Append(const char *cs)
Definition TString.h:574
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:263
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:254
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:586
Ssiz_t GetShortSize() const
Definition TString.h:246
Bool_t IsWhitespace() const
Definition TString.h:417
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:250
const char * GetLongPointer() const
Definition TString.h:255
std::enable_if< ROOT::TypeTraits::IsUnsignedNumeral< T >::value, TString >::type & operator+=(T u)
const char * GetShortPointer() const
Definition TString.h:257
void Zero()
Definition TString.h:266
Ssiz_t GetLongCap() const
Definition TString.h:252
void SetLongPointer(char *p)
Definition TString.h:253
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:249
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:634
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:258
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:653
static Ssiz_t Recommend(Ssiz_t s)
Definition TString.h:236
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:740
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