28 std::istream& TString::ReadFile(std::istream& strm)
31 Ssiz_t end, cur = strm.tellg();
32 strm.seekg(0, std::ios::end);
37 const Ssiz_t incr = 256;
42 Ssiz_t len = Length();
43 Ssiz_t cap = Capacity();
44 strm.read(GetPointer()+len, cap-len);
45 SetSize(len + strm.gcount());
53 cap = AdjustCapacity(cap, cap+incr);
57 GetPointer()[Length()] =
'\0';
65 std::istream& TString::ReadLine(std::istream& strm, Bool_t skipWhite)
70 return ReadToDelim(strm,
'\n');
76 std::istream& TString::ReadString(std::istream& strm)
78 return ReadToDelim(strm,
'\0');
89 std::istream& TString::ReadToDelim(std::istream& strm,
char delim)
92 const Ssiz_t incr = 32;
101 Ssiz_t len = Length();
102 Ssiz_t cap = Capacity();
103 strm.get(GetPointer()+len,
106 SetSize(len + strm.gcount());
107 if (!strm.good())
break;
114 cap = AdjustCapacity(cap, cap+incr);
119 GetPointer()[Length()] =
'\0';
127 std::istream& TString::ReadToken(std::istream& strm)
130 const Ssiz_t incr = 16;
136 UInt_t wid = strm.width(0);
139 while ((wid == 0 || Length() < (Int_t)wid) &&
140 strm.get(c).good() && (hitSpace = isspace((Int_t)c)) == 0) {
142 Ssiz_t len = Length();
143 Ssiz_t cap = Capacity();
145 cap = AdjustCapacity(cap, cap+incr);
148 GetPointer()[len] = c;
155 GetPointer()[Length()] =
'\0';
163 std::istream& operator>>(std::istream& strm, TString& s)
165 return s.ReadToken(strm);
171 std::ostream& operator<<(std::ostream& os,
const TString& s)
174 if (os.tie()) os.tie()->flush();
175 UInt_t len = s.Length();
176 UInt_t wid = os.width();
177 wid = (len < wid) ? wid - len : 0;
179 long flags = os.flags();
180 if (wid && !(flags & std::ios::left))
182 os.write((
char*)s.Data(), s.Length());
183 if (wid && (flags & std::ios::left))
187 if (os.flags() & std::ios::unitbuf)
198 Bool_t TString::Gets(FILE *fp, Bool_t chop)
206 if (fgets(buf,
sizeof(buf), fp) == 0)
break;
209 }
while (!ferror(fp) && !feof(fp) && strchr(buf,
'\n') == 0);
211 if (chop && EndsWith(
"\n")) {
223 void TString::Puts(FILE *fp)
225 fputs(GetPointer(), fp);