62 _is(&is), _atEOL(
kFALSE), _atEOF(kFALSE), _prefix(""), _punct("()[]<>|/\\:?.,=+-&^%$
#@!`~") 72 _is(&is), _atEOL(kFALSE), _atEOF(kFALSE), _prefix(errorPrefix), _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[10240], c(0), cnext=
'\0', cprev=
' ' ;
140 if (
_is->eof() ||
_is->fail()) {
146 if (
_is->peek()==
'\n') {
150 while (
_is->peek()==
'#') {
159 oocoutW((
TObject*)0,
InputArguments) <<
"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)))) {
247 if (c==
'"' && !
first) {
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[10240] ;
315 if (
_is->peek()==
'\n')
_is->get(c) ;
318 _is->getline(buffer,nfree,
'\n') ;
321 char *pcontseq = strstr(buffer,
"\\\\") ;
322 if (pcontseq) nfree -= (pcontseq-buffer) ;
324 _is->getline(pcontseq,nfree,
'\n') ;
326 char* nextpcontseq = strstr(pcontseq,
"\\\\") ;
327 if (nextpcontseq) nfree -= (nextpcontseq-pcontseq) ;
328 pcontseq = nextpcontseq ;
332 char *pcomment = strstr(buffer,
"//") ;
333 if (pcomment) *pcomment=0 ;
336 char *pstart=buffer ;
337 while (isspace(*pstart)) {
340 char *pend=buffer+strlen(buffer)-1 ;
342 while (isspace(*pend)) { *pend--=0 ; }
344 if (
_is->eof() ||
_is->fail()) {
349 return TString(pstart) ;
362 if (
_is->peek()!=
'\n') {
368 _is->getline(buffer,nfree,
'\n') ;
372 char *pcontseq = strstr(buffer,
"\\\\") ;
373 if (pcontseq) nfree -= (pcontseq-buffer) ;
375 _is->getline(pcontseq,nfree,
'\n') ;
377 char* nextpcontseq = strstr(pcontseq,
"\\\\") ;
378 if (nextpcontseq) nfree -= (nextpcontseq-pcontseq) ;
379 pcontseq = nextpcontseq ;
397 Bool_t error=token.CompareTo(expected) ;
398 if (error && !_prefix.IsNull()) {
400 << expected <<
"'" <<
", got '" << token <<
"'" << endl ;
415 if (token.IsNull())
return kTRUE ;
428 const char*
data=token.Data() ;
431 if (!strcasecmp(data,
"inf") || !strcasecmp(data+1,
"inf")) {
436 value = strtod(data,&endptr) ;
437 Bool_t error = (endptr-data!=token.Length()) ;
439 if (error && !_prefix.IsNull()) {
441 << token <<
"'" <<
" to double precision" << endl ;
455 if (token.IsNull())
return kTRUE ;
468 const char*
data=token.Data() ;
469 value = strtol(data,&endptr,10) ;
470 Bool_t error = (endptr-data!=token.Length()) ;
472 if (error && !_prefix.IsNull()) {
474 << token <<
"'" <<
" to integer" << endl ;
489 if (token.IsNull())
return kTRUE ;
501 char buffer[10240],*ptr ;
502 strncpy(buffer,token.Data(),10239) ;
503 if (token.Length()>=10239) {
507 int len = strlen(buffer) ;
510 if ((len) && (buffer[len-1]==
'"'))
514 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.