61 _is(&is), _atEOL(
kFALSE), _atEOF(
kFALSE), _prefix(
""), _punct(
"()[]<>|/\\:?.,=+-&^%$#@!`~")
92 return (nc==
'\n'||nc==-1) ;
112 const char* punct =
_punct.Data() ;
113 for (
int i=0 ; i<
_punct.Length() ; i++)
134 char buffer[64000],
c(0), cnext =
'\0', cprev =
' ';
139 if (
_is->eof() ||
_is->fail()) {
145 if (
_is->peek()==
'\n') {
149 while (
_is->peek()==
'#') {
157 if (bufptr >= 63999) {
159 <<
"RooStreamParser::readToken: token length exceeds buffer capacity, terminating token early" << endl;
169 if (
_is->eof() ||
_is->fail() ||
c==
'\n')
break ;
182 if (
c ==
'.' ||
c==
'-' ||
c==
'+' ||
c==
'/' ||
c==
'\\') {
186 if (cnext==
'I' || cnext==
'i') {
192 haveINF = ((cnext==
'I' && tmp1 ==
'N' && tmp2 ==
'F') || (cnext==
'i' && tmp1 ==
'n' && tmp2 ==
'f')) ;
197 _is->putback(cnext) ;
202 if (
c==
'\\' && cnext==
'\\') {
211 if (
c==
'/' && cnext==
'/') {
220 }
else if (!quotedString) {
229 if (
isPunctChar(
c) && !(
c==
'.' && (isdigit(cnext)||isdigit(cprev)))
230 && !((
c==
'-'||
c==
'+') && isdigit(cnext) && cprev==
'e')
231 && (!
first || !((
c==
'-'||
c==
'+') && (isdigit(cnext)||cnext==
'.'||haveINF)))) {
260 if (
_is->eof() ||
_is->bad()) {
277 while ((isspace(
c) ||
c==
'/') &&
c !=
'\n') {
280 if (
_is->peek()==
'/') {
294 if (bufptr==0 && lineCont) {
300 return TString(buffer) ;
312 char c, buffer[64000];
315 if (
_is->peek() ==
'\n')
319 _is->getline(buffer, nfree,
'\n');
322 char *pcontseq = strstr(buffer,
"\\\\");
324 nfree -= (pcontseq - buffer);
326 _is->getline(pcontseq, nfree,
'\n');
328 char *nextpcontseq = strstr(pcontseq,
"\\\\");
330 nfree -= (nextpcontseq - pcontseq);
331 pcontseq = nextpcontseq;
335 char *pcomment = strstr(buffer,
"//") ;
336 if (pcomment) *pcomment=0 ;
339 char *pstart=buffer ;
340 while (isspace(*pstart)) {
343 char *pend=buffer+strlen(buffer)-1 ;
345 while (isspace(*pend)) { *pend--=0 ; }
347 if (
_is->eof() ||
_is->fail()) {
352 return TString(pstart) ;
365 if (
_is->peek()!=
'\n') {
371 _is->getline(buffer, nfree,
'\n');
375 char *pcontseq = strstr(buffer,
"\\\\");
377 nfree -= (pcontseq - buffer);
379 _is->getline(pcontseq, nfree,
'\n');
381 char *nextpcontseq = strstr(pcontseq,
"\\\\");
383 nfree -= (nextpcontseq - pcontseq);
384 pcontseq = nextpcontseq;
402 Bool_t error=token.CompareTo(expected) ;
403 if (error && !
_prefix.IsNull()) {
405 << expected <<
"'" <<
", got '" << token <<
"'" << endl ;
420 if (token.IsNull())
return kTRUE ;
433 const char*
data=token.Data() ;
436 if (!strcasecmp(data,
"inf") || !strcasecmp(data+1,
"inf")) {
441 value = strtod(data,&endptr) ;
442 Bool_t error = (endptr-data!=token.Length()) ;
444 if (error && !
_prefix.IsNull()) {
446 << token <<
"'" <<
" to double precision" << endl ;
460 if (token.IsNull())
return kTRUE ;
473 const char*
data=token.Data() ;
474 value = strtol(data,&endptr,10) ;
475 Bool_t error = (endptr-data!=token.Length()) ;
477 if (error && !
_prefix.IsNull()) {
479 << token <<
"'" <<
" to integer" << endl ;
494 if (token.IsNull())
return kTRUE ;
506 char buffer[64000], *ptr;
507 strncpy(buffer, token.Data(), 63999);
508 if (token.Length() >= 63999) {
513 int len = strlen(buffer) ;
516 if ((len) && (buffer[len-1]==
'"'))
520 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.