62 _is(&is), _atEOL(
kFALSE), _atEOF(
kFALSE), _prefix(
""), _punct(
"()[]<>|/\\:?.,=+-&^%$#@!`~")
93 return (nc==
'\n'||nc==-1) ;
113 const char* punct =
_punct.Data() ;
114 for (
int i=0 ; i<
_punct.Length() ; i++)
135 char buffer[64000], c(0), cnext =
'\0', cprev =
' ';
140 if (
_is->eof() ||
_is->fail()) {
146 if (
_is->peek()==
'\n') {
150 while (
_is->peek()==
'#') {
158 if (bufptr >= 63999) {
160 <<
"RooStreamParser::readToken: token length exceeds buffer capacity, terminating token early" << endl;
170 if (
_is->eof() ||
_is->fail() || c==
'\n')
break ;
183 if (c ==
'.' || c==
'-' || c==
'+' || c==
'/' || c==
'\\') {
187 if (cnext==
'I' || cnext==
'i') {
193 haveINF = ((cnext==
'I' && tmp1 ==
'N' && tmp2 ==
'F') || (cnext==
'i' && tmp1 ==
'n' && tmp2 ==
'f')) ;
198 _is->putback(cnext) ;
203 if (c==
'\\' && cnext==
'\\') {
212 if (c==
'/' && cnext==
'/') {
221 }
else if (!quotedString) {
230 if (
isPunctChar(c) && !(c==
'.' && (isdigit(cnext)||isdigit(cprev)))
231 && !((c==
'-'||c==
'+') && isdigit(cnext) && cprev==
'e')
232 && (!
first || !((c==
'-'||c==
'+') && (isdigit(cnext)||cnext==
'.'||haveINF)))) {
248 if (c==
'"' && !
first) {
261 if (
_is->eof() ||
_is->bad()) {
278 while ((isspace(c) || c==
'/') && c !=
'\n') {
281 if (
_is->peek()==
'/') {
295 if (bufptr==0 && lineCont) {
301 return TString(buffer) ;
313 char c, buffer[64000];
316 if (
_is->peek() ==
'\n')
320 _is->getline(buffer, nfree,
'\n');
323 char *pcontseq = strstr(buffer,
"\\\\");
325 nfree -= (pcontseq - buffer);
327 _is->getline(pcontseq, nfree,
'\n');
329 char *nextpcontseq = strstr(pcontseq,
"\\\\");
331 nfree -= (nextpcontseq - pcontseq);
332 pcontseq = nextpcontseq;
336 char *pcomment = strstr(buffer,
"//") ;
337 if (pcomment) *pcomment=0 ;
340 char *pstart=buffer ;
341 while (isspace(*pstart)) {
344 char *pend=buffer+strlen(buffer)-1 ;
346 while (isspace(*pend)) { *pend--=0 ; }
348 if (
_is->eof() ||
_is->fail()) {
353 return TString(pstart) ;
366 if (
_is->peek()!=
'\n') {
372 _is->getline(buffer, nfree,
'\n');
376 char *pcontseq = strstr(buffer,
"\\\\");
378 nfree -= (pcontseq - buffer);
380 _is->getline(pcontseq, nfree,
'\n');
382 char *nextpcontseq = strstr(pcontseq,
"\\\\");
384 nfree -= (nextpcontseq - pcontseq);
385 pcontseq = nextpcontseq;
403 Bool_t error=token.CompareTo(expected) ;
404 if (error && !
_prefix.IsNull()) {
406 << expected <<
"'" <<
", got '" << token <<
"'" << endl ;
421 if (token.IsNull())
return kTRUE ;
434 const char*
data=token.Data() ;
437 if (!strcasecmp(data,
"inf") || !strcasecmp(data+1,
"inf")) {
442 value = strtod(data,&endptr) ;
443 Bool_t error = (endptr-data!=token.Length()) ;
445 if (error && !
_prefix.IsNull()) {
447 << token <<
"'" <<
" to double precision" << endl ;
461 if (token.IsNull())
return kTRUE ;
474 const char*
data=token.Data() ;
475 value = strtol(data,&endptr,10) ;
476 Bool_t error = (endptr-data!=token.Length()) ;
478 if (error && !
_prefix.IsNull()) {
480 << token <<
"'" <<
" to integer" << endl ;
495 if (token.IsNull())
return kTRUE ;
507 char buffer[64000], *ptr;
508 strncpy(buffer, token.Data(), 63999);
509 if (token.Length() >= 63999) {
514 int len = strlen(buffer) ;
517 if ((len) && (buffer[len-1]==
'"'))
521 ptr=(buffer[0]==
'"') ? buffer+1 : buffer ;
Bool_t isPunctChar(char c) const
Check if given char is considered punctuation.
Bool_t convertToDouble(const TString &token, Double_t &value)
Convert given string to a double. Return true if the conversion fails.
TString readToken()
Read one token separated by any of the know punctuation characters This function recognizes and handl...
Bool_t convertToInteger(const TString &token, Int_t &value)
Convert given string to an Int_t.
static Double_t infinity()
Return internal infinity representation.
void zapToEnd(Bool_t inclContLines=kFALSE)
Eat all characters up to and including then end of the current line.
RooStreamParser(std::istream &is)
Construct parser on given input stream.
Bool_t readDouble(Double_t &value, Bool_t zapOnError=kFALSE)
Read the next token and convert it to a Double_t.
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of '\' in th...
Bool_t expectToken(const TString &expected, Bool_t zapOnError=kFALSE)
Read the next token and return kTRUE if it is identical to the given 'expected' token.
Bool_t readString(TString &value, Bool_t zapOnError=kFALSE)
Read a string token.
Bool_t convertToString(const TString &token, TString &string)
Convert given token to a string (i.e. remove eventual quotation marks)
void setPunctuation(const TString &punct)
Change list of characters interpreted as punctuation.
Mother of all ROOT objects.
virtual ~RooStreamParser()
Destructor.
Bool_t readInteger(Int_t &value, Bool_t zapOnError=kFALSE)
Read a token and convert it to an Int_t.
Bool_t atEOL()
If true, parser is at end of line in stream.