cfl_token.cpp
Go to the documentation of this file.
1 /** @file cfl_token.cpp @brief Class Token */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5 Copyright (C) 2006 Bernd Opitz
6 Exclusive copyright is granted to Klaus Schmidt
7 
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12 
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 #include "cfl_token.h"
24 
25 namespace faudes {
26 
27 
28 // Token::Token()
29 Token::Token(void) :
30  mType(None),
31  mStringValue(""),
32  mOptionValue(""),
33  mIntegerValue(0),
34  mFloatValue(0),
35  mPreceedingSpace(""),
36  mAttributeCount(0)
37 {
38 }
39 
40 // copy construct
41 Token::Token(const Token& rToken) :
42  mType(rToken.mType),
43  mStringValue(rToken.mStringValue),
44  mOptionValue(rToken.mOptionValue),
45  mIntegerValue(rToken.mIntegerValue),
46  mFloatValue(rToken.mFloatValue),
47  mPreceedingSpace(rToken.mPreceedingSpace),
48  mAttributes(rToken.mAttributes),
49  mAttributeCount(rToken.mAttributeCount)
50 {
51 }
52 
53 
54 // assignment
55 Token& Token::operator=(const Token& rToken) {
56  mType=rToken.mType;
57  mStringValue=rToken.mStringValue;
58  mOptionValue=rToken.mOptionValue;
60  mFloatValue=rToken.mFloatValue;
62  mAttributes=rToken.mAttributes;
64  return *this;
65 }
66 
67 // destructor
69 }
70 
71 // Token::SetNone()
72 void Token::SetNone(void ) {
73  mType=None;
74  mStringValue="";
75  mOptionValue="";
76  mIntegerValue=0;
77  mFloatValue=0;
78  mAttributes.clear();
81 }
82 
83 // Token::SetString(str)
84 void Token::SetString(const std::string& rName) {
85  SetNone();
86  mType=String;
87  mStringValue=rName;
88 }
89 
90 // Token::SetBegin(str)
91 void Token::SetBegin(const std::string& rName) {
92  SetNone();
93  mType=Begin;
94  mStringValue=rName;
95 }
96 
97 // Token::SetEnd(str)
98 void Token::SetEnd(const std::string& rName) {
99  SetNone();
100  mType=End;
101  mStringValue=rName;
102 }
103 
104 // Token::SetEmpty(str)
105 void Token::SetEmpty(const std::string& rName) {
106  SetNone();
107  mType=End | Begin;
108  mStringValue=rName;
109 }
110 
111 // Token::SetOption(str)
112 void Token::SetOption(const std::string& rName) {
113  SetNone();
114  mType=Option | String;
115  mStringValue="+"+rName+"+";
116  mOptionValue=rName;
117 }
118 
119 // Token::SetInteger(number)
120 void Token::SetInteger(const Int number) {
121  SetNone();
122  mType=Integer | Float;
123  mIntegerValue=number;
124  mFloatValue=number;
125 }
126 
127 // Token::SetInteger16(number)
128 void Token::SetInteger16(const Int number) {
129  SetNone();
131  mIntegerValue=number;
132  mFloatValue=number;
133 }
134 
135 // Token::SetBoolean(number)
136 void Token::SetBoolean(const Int number) {
137  SetNone();
138  mType= Boolean | Integer | Float;
139  mIntegerValue=number;
140  mFloatValue=number;
141 }
142 
143 // Token::SetFloat(number)
144 void Token::SetFloat(const faudes::Float number) {
145  SetNone();
146  mType=Float;
147  mIntegerValue=(Int) number;
148  mFloatValue=number;
149 }
150 
151 // Token::SetBinary
152 void Token::SetBinary(const char* data, std::size_t len) {
153  SetNone();
154  mType=Binary | String;
155  mStringValue.assign(data,len);
156 }
157 
158 
159 // Token::ClrEnd()
160 void Token::ClrEnd(void) {
161  mType&= ~End;
162 }
163 
164 
165 // access integer
167  return(mIntegerValue);
168 }
169 
170 
171 // access float
173  return(mFloatValue);
174 }
175 
176 // access string
177 const std::string& Token::StringValue(void) const {
178  if(mType & Option) return(mOptionValue); // compatibility
179  return(mStringValue);
180 }
181 
182 // access option
183 const std::string& Token::OptionValue(void) const {
184  return(mOptionValue);
185 }
186 
187 // access raw data
188 const std::string& Token::PreceedingSpace(void) const {
189  return mPreceedingSpace;
190 }
191 
192 // access raw data
193 void Token::PreceedingSpace(const std::string& sep) {
194  mPreceedingSpace=sep;
195 }
196 
197 // access unique type (depreciated!)
199  if(mType & Begin) return Begin;
200  if(mType & End) return End;
201  if(mType & Integer16) return Integer16;
202  if(mType & Boolean) return Boolean;
203  if(mType & Integer) return Integer;
204  if(mType & Float) return Float;
205  if(mType & Option) return Option;
206  if(mType & Binary) return Binary;
207  if(mType & String) return String;
208  return None;
209 }
210 
211 
212 // test type
213 bool Token::IsNone(void) const {
214  return mType == None;
215 }
216 
217 // test type
218 bool Token::IsInteger(void) const {
219  return mType & Integer;
220 }
221 
222 // test type
223 bool Token::IsInteger16(void) const {
224  return mType & Integer16;
225 }
226 
227 // test type
228 bool Token::IsBoolean(void) const {
229  return mType & Boolean;
230 }
231 
232 // test type
233 bool Token::IsFloat(void) const {
234  return mType & Float;
235 }
236 
237 // test type
238 bool Token::IsOption(void) const {
239  return mType & Option;
240 }
241 
242 // test type
243 bool Token::IsString(void) const {
244  return mType & String;
245 }
246 
247 // test type
248 bool Token::IsBinary(void) const {
249  return mType & Binary;
250 }
251 
252 // test type
253 bool Token::IsCdata(void) const {
254  return mType & Cdata;
255 }
256 
257 // test type
258 bool Token::IsBegin(void) const {
259  return mType & Begin;
260 }
261 
262 // test type
263 bool Token::IsBegin(const std::string& tag) const {
264  if(! (mType & Begin) ) return false;
265  return mStringValue==tag;
266 }
267 
268 // test type
269 bool Token::IsEnd(void) const {
270  return mType & End;
271 }
272 
273 // test type
274 bool Token::IsEnd(const std::string& tag) const {
275  if(! (mType & End) ) return false;
276  return mStringValue==tag;
277 }
278 
279 // test type
280 bool Token::IsEmpty(void) const {
281  return (mType & Begin) && (mType & End);
282 }
283 
284 // clear attribute
285 void Token::ClrAttribute(const std::string& name) {
286  aiterator ait=mAttributes.find(name);
287  if(ait==mAttributes.end()) return;
288  mAttributes.erase(ait);
289 }
290 
291 // clear all attributes
293  mAttributes.clear();
294  mAttributeCount=0;
295 }
296 
297 
298 // insert attribute for interpretation
299 void Token::InsAttribute(const std::string& name, const std::string& value) {
300  AttributeValue aval;
301  aval.mStringValue=value;
302  aval.mType=None;
303  aval.mSort=mAttributeCount++;
304  mAttributes[name]=aval;
305 }
306 
307 
308 // insert string attribute
309 void Token::InsAttributeString(const std::string& name, const std::string& value) {
310  AttributeValue aval;
311  aval.mStringValue=value;
312  aval.mType=String;
313  aval.mSort=mAttributeCount++;
314  mAttributes[name]=aval;
315 }
316 
317 // insert integer attribute
318 void Token::InsAttributeInteger(const std::string& name, Int value) {
319  AttributeValue aval;
320  aval.mStringValue=ToStringInteger(value);
321  aval.mType=Float | Integer;
322  aval.mSort=mAttributeCount++;
323  mAttributes[name]=aval;
324 }
325 
326 // insert integer attribute
327 void Token::InsAttributeInteger16(const std::string& name, Int value) {
328  AttributeValue aval;
329  aval.mStringValue=ToStringInteger16(value);
330  aval.mType=Float | Integer;
331  aval.mSort=mAttributeCount++;
332  mAttributes[name]=aval;
333 }
334 
335 // insert integer attribute
336 void Token::InsAttributeBoolean(const std::string& name, Int value) {
337  AttributeValue aval;
338  if(value==0) aval.mStringValue="false";
339  else aval.mStringValue="true";
340  aval.mType=Float | Integer;
341  aval.mSort=mAttributeCount++;
342  mAttributes[name]=aval;
343 }
344 
345 // insert float attribute
346 void Token::InsAttributeFloat(const std::string& name, faudes::Float value) {
347  AttributeValue aval;
348  aval.mStringValue=ToStringFloat(value);
349  aval.mType=Float;
350  aval.mSort=mAttributeCount++;
351  mAttributes[name]=aval;
352 }
353 
354 // test attribute type
355 bool Token::ExistsAttributeString(const std::string& name) {
356  aiterator ait=mAttributes.find(name);
357  if(ait==mAttributes.end()) return false;
358  InterpretAttribute(ait);
359  if(ait->second.mType & String) return true;
360  return false;
361 }
362 
363 
364 // test attribute type
365 bool Token::ExistsAttributeInteger(const std::string& name) {
366  aiterator ait=mAttributes.find(name);
367  if(ait==mAttributes.end()) return false;
368  InterpretAttribute(ait);
369  if(ait->second.mType & Integer) return true;
370  return false;
371 }
372 
373 
374 // test attribute type
375 bool Token::ExistsAttributeFloat(const std::string& name) {
376  aiterator ait=mAttributes.find(name);
377  if(ait==mAttributes.end()) return false;
378  InterpretAttribute(ait);
379  if(ait->second.mType & Float) return true;
380  return false;
381 }
382 
383 
384 // access attribute value
385 const std::string& Token::AttributeStringValue(const std::string& name) {
386  static const std::string emptystr="";
387  aiterator ait=mAttributes.find(name);
388  if(ait==mAttributes.end()) return emptystr;
389  InterpretAttribute(ait);
390  if(!(ait->second.mType & String)) return emptystr;
391  return ait->second.mStringValue;
392 }
393 
394 
395 // access attribute value
396 Int Token::AttributeIntegerValue(const std::string& name) {
397  aiterator ait=mAttributes.find(name);
398  if(ait==mAttributes.end()) return 0;
399  InterpretAttribute(ait);
400  if(!(ait->second.mType & Integer)) return 0;
401  return ait->second.mIntegerValue;
402 }
403 
404 
405 // access attribute value
406 faudes::Float Token::AttributeFloatValue(const std::string& name) {
407  aiterator ait=mAttributes.find(name);
408  if(ait==mAttributes.end()) return 0;
409  InterpretAttribute(ait);
410  if(!(ait->second.mType & Float)) return 0;
411  return ait->second.mFloatValue;
412 }
413 
414 
415 // WriteVerbatim(pStream)
416  void Token::WriteVerbatim(std::ostream* pStream, const std::string& rData, bool lfflag) {
417  // markup
418  *pStream << "<![CDATA[";
419  // optional preceeding linefeed
420  if(lfflag) *pStream << std::endl;
421  // split up cdata sections
422  std::string esc="]]>";
423  std::size_t pos=0;
424  // loop segments
425  while(pos < rData.size()) {
426  std::size_t next= rData.find(esc,pos);
427  if(next==std::string::npos) next=rData.size()+1;
428  // write segment
429  *pStream << rData.substr(pos,next-pos);
430  // write split
431  if(next<=rData.size())
432  *pStream << "]]]]><![CDATA[>";
433  // proceed
434  pos=next+3;
435  }
436  // optional post linefeed
437  if(lfflag) *pStream << std::endl;
438  // markup
439  *pStream << "]]>";
440 }
441 
442 
443 
444 // WriteBinary(pStream,data,len)
445  void Token::WriteBinary(std::ostream* pStream, const char* pData, std::size_t len) {
446 
447  // my encoding (hardcoded in read, however)
448  static char Base64EncodingTable[]=
449  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
450 
451  // start
452  *pStream << "=";
453 
454  // loop vars
455  const char* src = pData;
456  std::size_t cnt=len;
457  int step=0;
458  unsigned char c0=0,c1=0,c2=0,c3=0;
459 
460  // encode and output buffer
461  while(cnt>0) {
462  switch(step) {
463  // collect char for 1st byte
464  case 0:
465  c0= ((*src & 0xFC) >> 2);
466  c1= ((*src & 0x03) << 4);
467  c2=0;
468  c3=0;
469  step=1;
470  break;
471  // collect char for 2nd byte
472  case 1:
473  c1|= ((*src & 0xF0) >> 4);
474  c2|= ((*src & 0x0F) << 2);
475  step=2;
476  break;
477  // collect char for 3rd byte, plus output
478  case 2:
479  c2|= ((*src & 0xC0) >> 6);
480  c3|= (*src & 0x3F);
481  *pStream << Base64EncodingTable[c0] << Base64EncodingTable[c1] <<
482  Base64EncodingTable[c2] << Base64EncodingTable[c3];
483  step=0;
484  break;
485  default: break;
486  }
487  cnt--;
488  src++;
489  }
490  // flush left overs, incl padding
491  switch(step) {
492  case 0:
493  *pStream << "= ";
494  break;
495  case 1:
496  *pStream << Base64EncodingTable[c0] << Base64EncodingTable[c1] << "=== ";
497  break;
498  case 2:
499  *pStream << Base64EncodingTable[c0] << Base64EncodingTable[c1] <<
500  Base64EncodingTable[c2] << "== ";
501  break;
502  }
503 }
504 
505 // WriteBinary(pStream)
506 void Token::WriteBinary(std::ostream* pStream) const {
507  if(mType!=Binary) return;
508  WriteBinary(pStream,mStringValue.data(),mStringValue.size());
509 }
510 
511 
512 // ReadBinary ... to mStringValue
513 int Token::ReadBinary(std::istream* pStream) {
514 
515  // line count
516  int lc;
517 
518  // swallow leading '='
519  char c1=pStream->get();
520  if(c1!='=') return -1;
521 
522  // read as string, excl. marks '='
523  lc=ReadString(pStream,'=');
524 
525  // swallow one trailing '='
526  c1=pStream->get();
527  if(c1!='=') return -1;
528 
529  // take any extra trailing padding =
530  while(!pStream->eof()) {
531  if(pStream->peek()!='=') break;
532  pStream->get();
533  mStringValue.append("=");
534  }
535 
536  // loop vars
537  std::string::iterator src=mStringValue.begin();
538  std::string::iterator dst=mStringValue.begin();
539  std::size_t cnt=0;
540  int c=0, d0=0, d1=0, d2=0;
541  unsigned char cs[4];
542  unsigned int step=0;
543 
544  // loop
545  while(true) {
546 
547  // get data
548  while(true) {
549  // sense eof
550  if(src==mStringValue.end()) { c = -1; break; }
551  // get char
552  c=*(src++);
553  // decode
554  if(c>='A' && c <='Z') { c-='A'; break; }
555  if(c>='a' && c <='z') { c-='a'; c+= ('Z'-'A')+1; break; }
556  if(c>='0' && c <='9') { c-='0'; c+= 2*('Z'-'A')+2; break; }
557  if(c=='+') {c= 62; break; }
558  if(c=='/') {c= 63; break; }
559  if(c=='=') {c= 0xFF; break; };
560  }
561  // pass on eof
562  if(c== -1) break;
563  // record and continue
564  cs[step++] = c;
565  if(step<=3) continue;
566  step=0;
567  // sort bits
568  d0= ((cs[0] << 2) & 0xFC) | ((cs[1] >> 4) & 0x03);
569  d1= ((cs[1] << 4) & 0xF0) | ((cs[2] >> 2) & 0x0F);
570  d2= ((cs[2] << 6) & 0xC0) | (cs[3] & 0x3F);
571  // record result
572  if(cs[0]!= 0xFF && cs[1]!=0xFF) {*(dst++)=d0; cnt++;}
573  if(cs[1]!= 0xFF && cs[2]!=0xFF) {*(dst++)=d1; cnt++;}
574  if(cs[2]!= 0xFF && cs[3]!=0xFF) {*(dst++)=d2; cnt++;}
575  // sense end
576  if(cs[3]==0xFF) break;
577  }
578 
579  // set data length (sets the length incl termination char??)
580  mStringValue.resize(cnt);
581 
582  // return padding error or line count
583  return step==0 ? lc : -1;
584 }
585 
586 
587 
588 // ReadSpace(pStream)
589 int Token::ReadSpace(std::istream* pStream, bool fcomments){
590  char c = '\0';
591  int lc = 0;
592  FD_DV("Token::ReadSpace()");
593  // check the whole pStream
594  while(*pStream) {
595  // swallow white space
596  while(*pStream) {
597  // check eof
598  if(pStream->eof()) return lc;
599  // look one character ahead
600  c = pStream->peek();
601  // count the next lines
602  if(c == '\n') {
603  ++lc;
604  pStream->get();
605  mPreceedingSpace.append(1,c);
606  continue;
607  }
608  // swallow controls
609  if(iscntrl(c)) {
610  pStream->get();
611  mPreceedingSpace.append(1,c);
612  continue;
613  }
614  // swallow space
615  if(isspace(c)) {
616  pStream->get();
617  mPreceedingSpace.append(1,c);
618  continue;
619  }
620  // regard this non-white
621  break;
622  }
623  // if the next character starts a faudes comment
624  if(!fcomments) break;
625  if(c != '%') break;
626  while(*pStream) {
627  // check eof
628  if(pStream->eof()) {return(lc);};
629  // get the next character
630  c = pStream->get();
631  // count the next lines
632  if (c == '\n') ++lc;
633  // terminate with the next new line character
634  if (c == '\n') break;
635  if (c == '\r') break;
636  }
637  }
638  // termination if the next character is neither a space, a control, or a '%'.
639  FD_DV("Token::ReadSpace(): lc " << lc << " c " << c);
640  return lc;
641 }
642 
643 // InterpretAttribute(aval)
645  if(ait->second.mType != None) return;
647  ait->second.mStringValue, ait->second.mType,
648  ait->second.mIntegerValue, ait->second.mFloatValue);
649  ait->second.mType |= String;
650 }
651 
652 // InterpretNumber(string)
655 }
656 
657 // InterpretNumber(string, ...)
658 bool Token::InterpretNumber(const std::string& numstr, int& type, Int& ival, faudes::Float& fval) {
659  char c, vc;
660  faudes::Float fv=0;
661  Int iv=0;
662  int comma = -1;
663  bool minus = false;
664  int base=10;
665  bool ok=false;
666  int cnt=0;
667  type &= ~(Integer | Integer16 | Float);
668  // test for special cases
669  if(numstr=="inf" || numstr=="+inf") {
670  ival = std::numeric_limits<Int>::max();
671  fval = std::numeric_limits<faudes::Float>::max();
672  type|= (Integer | Float);
673  return true;
674  }
675  // test for special casess
676  if(numstr=="-inf") {
677  ival=std::numeric_limits<Int>::min()+1;
678  fval = -1* std::numeric_limits<faudes::Float>::max();
679  type|= (Integer | Float);
680  return true;
681  }
682  // test for special cases
683  if(numstr=="true" || numstr=="True") {
684  ival = 1;
685  fval = ival;
686  type|= (Integer | Boolean);
687  return true;
688  }
689  // test for special cases
690  if(numstr=="false" || numstr=="False") {
691  ival = 0;
692  fval = ival;
693  type|= (Integer | Boolean);
694  return true;
695  }
696  // iterate over string
697  std::string::const_iterator cit=numstr.begin();
698  for(;cit!=numstr.end(); cit++) {
699  // check next charakter
700  c = *cit;
701  cnt++;
702  // change base on x
703  if(c=='x' && iv==0 && cnt==2 && comma<0 && !minus)
704  {base = 16; continue;}
705  // change sign on -
706  if(c=='-' && cnt==1)
707  {minus = true; continue;}
708  // record comma
709  if(c=='.' && comma<0 && base==10)
710  {comma = 0; continue;}
711  // break if it is not a digit
712  if(!isdigit(c) && base==10) break;
713  if(!isxdigit(c) && base==16) break;
714  // compute the value of c
715  vc=0;
716  if(c>='0' && c<= '9') vc = c-'0';
717  else if(c>='a' && c<= 'f') vc = c-'a' + 10;
718  else if(c>='A' && c<= 'F') vc = c-'A' + 10;
719  // compute the corresponding number
720  iv = base * iv + vc;
721  fv = base * fv + vc;
722  if(comma>=0) comma++;
723  ok = true;
724  }
725  // detect error
726  if(cit!=numstr.end()) ok=false;
727  // fix sign
728  if(minus) {
729  iv=-iv;
730  fv=-fv;
731  }
732  // fix decimal point
733  for(;comma>0;comma--) {
734  iv/=base;
735  fv/=base;
736  }
737  // assign the numeric value and type in Token
738  if(ok) {
739  ival = iv;
740  fval = fv;
741  type |= Float;
742  if(comma<=0 && !minus) type |= Integer;
743  if(comma<=0 && !minus && base==16) type |= Integer16;
744  }
745  return ok;
746 }
747 
748 // Write(pStream)
749 void Token::Write(std::ostream* pStream) const {
750  FD_DV("Token::Write: mType=" << (int) mType
751  << "\" mStringValue=\"" << mStringValue
752  << "\" mIntegerValue=" <<mIntegerValue
753  << "\" mFloatValue=" <<mFloatValue <<"\n");
754  // numerics first
755  if(mType & Integer16) {
757  } else if(mType & Integer) {
759  } else if(mType & Float) {
760  *pStream << ExpandString(ToStringFloat(mFloatValue), FD_NAMELEN) << " ";
761  }
762  // mark up: begin
763  else if(mType & Begin) {
764  *pStream << '<' << mStringValue;
765  std::map<int,caiterator> sortnames;
766  for(caiterator ait=mAttributes.begin(); ait!=mAttributes.end(); ait++)
767  sortnames[ait->second.mSort]=ait;
768  std::map<int,caiterator>::iterator sit;
769  for(sit=sortnames.begin(); sit!=sortnames.end(); sit++) {
770  caiterator ait=sit->second;
771  *pStream << " ";
772  WriteEscapedString(pStream,ait->first);
773  *pStream << "=\"";
774  WriteEscapedString(pStream,ait->second.mStringValue);
775  *pStream << "\"";
776  }
777  if(mType & End) *pStream << "/";
778  *pStream << ">";
779  }
780  // mark up:end
781  else if(mType & End) {
782  *pStream << "</" << mStringValue << ">";
783  }
784  // cdata markup
785  else if(mType & Cdata) {
786  WriteVerbatim(pStream,mStringValue);
787  }
788  // string
789  else if(mType & Option) {
790  WriteString(pStream,""); // '+' is incl. mStringValue
791  } else if(mType & Binary) {
792  WriteBinary(pStream);
793  } else if(mType & String) {
794  // figure delimiter
795  bool quote=false;
796  if(mStringValue.size()==0) quote=true;
797  if(mStringValue.size()>0)
798  if(!isalpha(mStringValue[0])) quote=true;
799  static const std::string white=" \n\r\t\f";
800  if(mStringValue.find_first_of(white)!=std::string::npos)
801  quote=true;
802  if(quote)
803  WriteString(pStream,"\"");
804  else
805  WriteString(pStream,"");
806  }
807  // error (should we have an exception here?)
808  else { /* assert(0) */ };
809 }
810 
811 // WriteEscapedString(pStream)
812 int Token::WriteEscapedString(std::ostream* pStream, const std::string& outstr) {
813  // assemble escape character string
814  std::string escstr="<>&\"";
815  // no escape characters
816  if(outstr.find_first_of(escstr)==std::string::npos) {
817  *pStream << outstr;
818  return outstr.size();
819  }
820  // do escape substitution
821  int cc=0;
822  std::string::const_iterator cit=outstr.begin();
823  for(;cit!=outstr.end(); cit++) {
824  if(*cit=='<')
825  { *pStream << "&lt;"; cc+=4; continue;}
826  if(*cit=='>')
827  { *pStream << "&gt;"; cc+=4; continue;}
828  if(*cit=='&')
829  { *pStream << "&amp;"; cc+=5; continue;}
830  if(*cit=='"')
831  { *pStream << "&quot;"; cc+=6; continue;}
832  *pStream << *cit; cc++;
833  }
834  return cc;
835 }
836 
837 // WriteString(pStream, delim)
838 void Token::WriteString(std::ostream* pStream, const std::string& delim) const {
839  int cc=0;
840  *pStream << delim;
841  cc+=delim.size();
842  cc+=WriteEscapedString(pStream,mStringValue);
843  *pStream << delim << " ";
844  cc+=delim.size()+1;
845  while(cc< FD_NAMELEN) {
846  *pStream << " "; cc++;
847  }
848 }
849 
850 // ReadString(pStream, char)
851 int Token::ReadString(std::istream* pStream, char stop) {
852  return ReadEscapedString(pStream,stop,mStringValue);
853 }
854 
855 
856 // ReadEscapedString(pStream, rString, char)
857 int Token::ReadEscapedString(std::istream* pStream, char stop, std::string& rString) {
858  int lc=0;
859  char c;
860  std::string entref="";
861  bool ctrlblank = false;
862  rString = "";
863  // check the whole pStream
864  while (*pStream) {
865  // check eof
866  if(pStream->eof()) return -1;
867  // test one character
868  c = pStream->peek();
869  // break on mark up
870  if(c == '<') break;
871  if(c == '>') break;
872  // break on stop
873  if(c == stop) break;
874  if(isblank(c) && stop==' ') break;
875  if(iscntrl(c) && stop==' ') break;
876  // get one character
877  c = pStream->get();
878  // count the next lines
879  if(c=='\n') ++lc;
880  // replace sequence of control characters by one blank
881  if(iscntrl(c) && ctrlblank) continue;
882  ctrlblank=false;
883  if(iscntrl(c)) { c=' '; ctrlblank=true;}
884  // if in escape mode ...
885  if(entref.size()!=0) {
886  //record reference
887  entref.append(1,c);
888  // error: reference must not contain a white space
889  if(c == ' ') return -1;
890  // decode reference
891  if(c == ';') {
892  if(entref=="&amp;") rString.append(1,'&');
893  else if(entref=="&quot;") rString.append(1,'"');
894  else if(entref=="&apos;") rString.append(1,'\'');
895  else if(entref=="&lt;") rString.append(1,'<');
896  else if(entref=="&gt;") rString.append(1,'>');
897  // plain copy unknown
898  else rString.append(entref);
899  entref="";
900  }
901  continue;
902  }
903  // ... sense escape
904  if(c == '&') entref.append(1,c);
905  // ... add character
906  if(c != '&') rString.append(1,c);
907  continue;
908  }
909  // report
910  FD_DV("Token::ReadEscapedString(): lc=" << lc << " val=" << rString);
911  // space seperated string must be nontrivial
912  if(stop==' ' && rString.size()==0) return -1;
913  return lc;
914 }
915 
916 
917 // ReadCharacterData(pStream, rString)
918 int Token::ReadCharacterData(std::istream* pStream, std::string& rString, bool fcomments) {
919  rString = "";
920  // special case
921  if(pStream->eof()) return 0;
922  // check the whole pStream
923  int lc=0;
924  char c;
925  bool cm = false;
926  while (*pStream) {
927  // check other errors
928  if(!pStream->good()) { rString="I/O error"; return -1; }
929  // test one character
930  c = pStream->peek();
931  // break on eof
932  if(pStream->eof()) break;
933  // sense error: markup in faudes comment
934  if(fcomments && cm)
935  if((c=='<') || (c=='>')) { rString="'<' or '>' in faudes comment"; return -1; }
936  // break on mark up
937  if(c == '<') break;
938  // again: test state (peek may set eof, so dont use good() here)
939  if(pStream->bad()) { rString="I/O error"; return -1; }
940  // get one character
941  c = pStream->get();
942  // count the next lines
943  if(c=='\n') ++lc;
944  // track faudes comment mode
945  if(c=='%') cm=true;
946  if(c=='\n') cm=false;
947  // ... add character
948  if(!(fcomments && cm))
949  rString.append(1,c);
950  }
951  return lc;
952 }
953 
954 
955 // ReadAttributes(pStream)
956 // (and swallow all space after the last attribute)
957 int Token::ReadAttributes(std::istream* pStream) {
958  int lc=0;
959  char c=0;
960  FD_DV("Token::ReadAttributes()");
961  // scan until excl. '>'
962  while (*pStream) {
963  // skip space
964  while (*pStream) {
965  if(pStream->eof()) return -1;
966  c = pStream->peek();
967  if(!(isblank(c) || iscntrl(c))) break;
968  pStream->get();
969  if(c=='\n') ++lc;
970  }
971  // get attrname
972  std::string aname;
973  while (*pStream) {
974  if(pStream->eof()) return -1;
975  c = pStream->peek();
976  if(isblank(c) || iscntrl(c)) break;
977  if(c=='=') break;
978  if(c=='>') break;
979  if(c=='/') break;
980  pStream->get();
981  aname.append(1,c);
982  }
983  FD_DV("Token::ReadAttributes(): aname " << aname);
984  // no name so we're done
985  if(aname.size()==0) {
986  return lc;
987  }
988  // skip space
989  while(*pStream) {
990  if(pStream->eof()) return -1;
991  c = pStream->peek();
992  if(!(isblank(c) || iscntrl(c))) break;
993  pStream->get();
994  if(c=='\n') ++lc;
995  }
996  // insist in eq
997  if(c!='=') return -1;
998  pStream->get();
999  // skip space
1000  while (*pStream) {
1001  if(pStream->eof()) return -1;
1002  c = pStream->peek();
1003  if(!(isblank(c) || iscntrl(c))) break;
1004  pStream->get();
1005  if(c=='\n') ++lc;
1006  }
1007  // strict version, value by '"'
1008  if(c == '"') {
1009  pStream->get();
1010  int ll=ReadString(pStream,'"');
1011  if(ll<0) return -1;
1012  pStream->get();
1013  lc+=ll;
1014  }
1015  // strict version, value by '''
1016  else if(c == '\'') {
1017  pStream->get();
1018  int ll=ReadString(pStream,'\'');
1019  if(ll<0) return -1;
1020  pStream->get();
1021  lc+=ll;
1022  }
1023  // relaxed version, value by "space"
1024  else {
1025  int ll=ReadString(pStream,' ');
1026  if(ll<0) return -1;
1027  lc+=ll;
1028  }
1029  std::string aval=mStringValue;
1030  FD_DV("Token::ReadAttributes(): aval " << aval);
1031  // record attribute
1032  InsAttribute(aname,aval);
1033  }
1034  // done
1035  return lc;
1036 }
1037 
1038 // ReadMarkup(pStream)
1039 // (leading "<" has allready been read)
1040 int Token::ReadMarkup(std::istream* pStream) {
1041  int lc=0;
1042  int ll;
1043  char c=0;
1044  mStringValue = "";
1045  mType=None;
1046  // figure indicator character
1047  char p1=0;
1048  char p2=0;
1049  if(pStream->eof()) return -1;
1050  c = pStream->peek();
1051  if(!(isalpha(c) || c=='_' || c==':')) {
1052  p1 = pStream->get();
1053  if(pStream->eof()) return -1;
1054  p2 = pStream->peek();
1055  }
1056  FD_DV("Token::ReadMarkup: " << c << "-" << p1 << "-" << p2);
1057  // its a begin tag ...
1058  if(p1==0) {
1059  FD_DV("Token::ReadMarkup: sensed XML tag");
1060  // ... get the name
1061  std::string name;
1062  while (*pStream) {
1063  if(pStream->eof()) return -1;
1064  c = pStream->peek();
1065  if(c == '>') break;
1066  if(c == '/') break;
1067  if(isblank(c) || iscntrl(c)) break;
1068  pStream->get();
1069  name.append(1,c);
1070  }
1071  if(name.size()==0) return -1;
1072  mType = Begin;
1073  ll=ReadAttributes(pStream);
1074  if(ll<0) return -1;
1075  if(pStream->eof()) return -1;
1076  c = pStream->peek();
1077  if(c=='/') {
1078  mType |= End;
1079  pStream->get();
1080  }
1081  mStringValue=name;
1082  FD_DV("Token::ReadMarkup: sensed XML tag, type " << mType << " name " << mStringValue);
1083  }
1084  // its an end tag: get the name
1085  if(p1=='/') {
1086  std::string name;
1087  while(*pStream) {
1088  if(pStream->eof()) return -1;
1089  c = pStream->peek();
1090  if(c == '>') break;
1091  if(c == '/') break;
1092  if(isblank(c) || iscntrl(c)) break;
1093  pStream->get();
1094  name.append(1,c);
1095  }
1096  if(name.size()==0) return -1;
1097  if(c!='>') return -1;
1098  mType = End;
1099  mStringValue=name;
1100  }
1101  // its an xml comment
1102  if(p1=='!' && p2=='-') {
1103  FD_DV("Token::ReadMarkup: sensed XML comment <" << p1 << p2);
1104  c=pStream->get();
1105  if(pStream->eof()) return -1;
1106  c=pStream->get();
1107  if(c!='-') return -1;
1108  char c2=0;
1109  char c3=0;
1110  while (*pStream) {
1111  c3=c2; c2=c;
1112  if(pStream->eof()) return -1;
1113  c = pStream->peek();
1114  if(c3== '-' && c2=='-' && c == '>') break;
1115  pStream->get();
1116  if(c=='\n') ++lc;
1117  }
1118  FD_DV("Token::ReadMarkup: sensed XML comment end " << c3 << c2 << c);
1119  }
1120  // its an xml doctypedec (which we cannot handle properly)
1121  if(p1=='!' && (p2=='D' || p2=='d')) {
1122  FD_DV("Token::ReadMarkup doc.type.dec. not implemented (!)");
1123  c=pStream->get();
1124  while(*pStream) {
1125  if(pStream->eof()) return -1;
1126  c = pStream->peek();
1127  if(c == '>') break;
1128  pStream->get();
1129  if(c=='\n') ++lc;
1130  }
1131  }
1132  // its an xml cdata (interpret as string)
1133  if(p1=='!' && p2=='[' ) {
1134  FD_DV("Token::ReadMarkup: sense CDATA?");
1135  // sense "<![CDATA["
1136  c=pStream->get();
1137  if(pStream->eof()) return -1;
1138  if(pStream->get()!='C') return -1;
1139  if(pStream->eof()) return -1;
1140  if(pStream->get()!='D') return -1;
1141  if(pStream->eof()) return -1;
1142  if(pStream->get()!='A') return -1;
1143  if(pStream->eof()) return -1;
1144  if(pStream->get()!='T') return -1;
1145  if(pStream->eof()) return -1;
1146  if(pStream->get()!='A') return -1;
1147  if(pStream->eof()) return -1;
1148  if(pStream->get()!='[') return -1;
1149  // read until "]]>"
1150  FD_DV("Token::ReadMarkup: sense CDATA!");
1151  char c2=0;
1152  char c3=0;
1153  while(*pStream) {
1154  c3=c2; c2=c;
1155  if(pStream->eof()) return -1;
1156  c = pStream->peek();
1157  if(c3== ']' && c2==']' && c == '>') break;
1158  if(pStream->eof()) return -1;
1159  pStream->get();
1160  if(c=='\n') ++lc;
1161  mStringValue.append(1,c);
1162  }
1163  FD_DV("Token::ReadMarkup: sense CDATA:" << mStringValue);
1164  // drop "]]"
1165  if(mStringValue.size()>=2)
1166  mStringValue.erase(mStringValue.size()-2);
1167  mType |= String;
1168  mType |= Cdata;
1169  FD_DV("Token::ReadMarkup: sense CDATA:" << mStringValue);
1170  }
1171  // its an xml proc.intstruction (which we ignore)
1172  if(p1=='?') {
1173  if(pStream->eof()) return -1;
1174  c = pStream->get();
1175  char c2=0;
1176  while (*pStream) {
1177  c2=c;
1178  if(pStream->eof()) return -1;
1179  c = pStream->peek();
1180  if(c2=='?' && c == '>') break;
1181  pStream->get();
1182  if(c=='\n') ++lc;
1183  }
1184  }
1185  // error
1186  if(pStream->eof()) return -1;
1187  c = pStream->peek();
1188  if(c!='>') {
1189  FD_DV("Token::ReadMarkup: mismatch (?) " << mStringValue);
1190  while (*pStream) {
1191  if(pStream->eof()) return -1;
1192  c = pStream->peek();
1193  if(c == '>') break;
1194  if(c=='\n') ++lc;
1195  pStream->get();
1196  }
1197  }
1198  // done
1199  pStream->get();
1200  FD_DV("Token::ReadMarkup: return type " << mType << " string " << mStringValue << " lc" << lc);
1201  return lc;
1202 }
1203 
1204 // Read(pStream)
1205 int Token::Read(std::istream* pStream, bool fcomments){
1206  FD_DV("Token::Read(): fcomments=" << fcomments);
1207  char c1;
1208  int lc = 0;
1209  int ll = -1;
1210  // the token is initialized with the type "None"
1211  SetNone();
1212  // check eof
1213  if(pStream->eof()) return(lc);
1214  // read all white space
1215  lc += ReadSpace(pStream,fcomments);
1216  // check eof
1217  if(pStream->eof()) return(lc);
1218  // get the first useful character
1219  c1=pStream->peek();
1220  // token is a quoted string if it starts with '"'
1221  if(c1 == '"') {
1222  pStream->get();
1223  // read the string until '"'
1224  ll=ReadString(pStream,'"');
1225  if(ll>=0) {
1226  lc+=ll;
1227  mType |= String;
1228  pStream->get();
1229  }
1230  }
1231  // token is a quoted string if it starts with '''
1232  else if(c1 == '\'') {
1233  pStream->get();
1234  // read the string until '''
1235  ll=ReadString(pStream,'\'');
1236  if(ll>=0) {
1237  lc+=ll;
1238  mType |= String;
1239  pStream->get();
1240  }
1241  }
1242  // token is an option string if it starts with '+'
1243  else if(c1 == '+') {
1244  pStream->get();
1245  // read the string until '+'
1246  ll=ReadString(pStream,'+');
1248  mStringValue="+" + mOptionValue + "+";
1249  if(ll>=0) {
1250  lc+=ll;
1251  mType |= (Option | String);
1252  pStream->get();
1253  }
1254  }
1255  // token is a binary string if it starts with '='
1256  else if(c1 == '=') {
1257  // read the string until '=', incl padding
1258  ll=ReadBinary(pStream);
1259  if(ll>=0) {
1260  lc+=ll;
1261  mType |= (Binary | String);
1262  }
1263  }
1264  // token is markup if it starts with <
1265  else if(c1 == '<') {
1266  pStream->get();
1267  // check eof
1268  if(pStream->eof()) return(lc);
1269  // read and interpret
1270  ll=ReadMarkup(pStream);
1271  // recurse on non-faudes-recognised but parsable markup (effectively swallowing unrecognised)
1272  if(ll>=0) {
1273  lc+=ll;
1274  if(mType==None) return(Read(pStream));
1275  }
1276  }
1277  // token is a space seperated string, perhaps a number
1278  else if(c1 != '%') {
1279  ll=ReadString(pStream,' ');
1280  if(ll>=0) {
1281  mType |= String;
1282  InterpretNumber();
1283  }
1284  }
1285  // sense error
1286  if(ll<0) {
1287  FD_DV("Token::Read(): failed with '" << c1 <<"'");
1288  return -1;
1289  }
1290  FD_DV("Token::Read(): " << Str());
1291  return(lc);
1292 }
1293 
1294 
1295 // Str()
1296 std::string Token::Str(void) const {
1297  std::stringstream ostr;
1298  ostr << "Token(--- Type=";
1299  if(IsNone()) ostr << "None";
1300  if(IsInteger()) ostr << "Integer";
1301  if(IsInteger16()) ostr << "Integer16";
1302  if(IsBoolean()) ostr << "Boolean";
1303  if(IsFloat()) ostr << "Float";
1304  if(IsString()) ostr << "String";
1305  if(IsEmpty()) ostr << "Begin/End";
1306  if(IsBegin()) ostr << "Begin";
1307  if(IsEnd()) ostr << "End";
1308  if(!IsNone()) {
1309  ostr << " Value=\"";
1310  if(IsFloat()) ostr << FloatValue();
1311  else if(IsBegin() || IsEnd()) ostr << StringValue();
1312  else if(IsString()) ostr << StringValue();
1313  ostr << "\"";
1314  }
1315  ostr << " sp #" << mPreceedingSpace.size();
1316  caiterator ait;
1317  for(ait=mAttributes.begin(); ait!=mAttributes.end(); ait++)
1318  ostr << " attr[" << ait->first << "=\"" << ait->second.mStringValue << "\"]";
1319  ostr << " ---)";
1320  return ostr.str();
1321 }
1322 
1323 
1324 
1325 } // namespace faudes
#define FD_NAMELEN
Length of strings for text fields in token output.
#define FD_DV(message)
Debug: optional low-level report on iterations and token IO.
Class Token.
Elementary type.
Elementary type.
Elementary type.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
std::map< std::string, AttributeValue >::iterator aiterator
Convenience typedef.
Definition: cfl_token.h:668
bool IsCdata(void) const
Test token Type.
Definition: cfl_token.cpp:253
bool IsBinary(void) const
Test token Type.
Definition: cfl_token.cpp:248
bool IsInteger16(void) const
Test token Type.
Definition: cfl_token.cpp:223
void SetNone(void)
Initialize None token.
Definition: cfl_token.cpp:72
int ReadMarkup(std::istream *pStream)
Read and interpret markup an input file stream.
Definition: cfl_token.cpp:1040
~Token(void)
Token destructor.
Definition: cfl_token.cpp:68
Token & operator=(const Token &rOther)
Assignment operator.
Definition: cfl_token.cpp:55
const std::string & PreceedingSpace(void) const
Preceeding space when writing to stream.
Definition: cfl_token.cpp:188
std::string Str(void) const
Pretty print string representation.
Definition: cfl_token.cpp:1296
void SetBinary(const char *data, std::size_t len)
Initialize Binary token.
Definition: cfl_token.cpp:152
void WriteString(std::ostream *pStream, const std::string &delim) const
Write a std::string value to an output stream.
Definition: cfl_token.cpp:838
void SetInteger16(const Int number)
Initialize as Integer16 token.
Definition: cfl_token.cpp:128
const std::string & StringValue(void) const
Get string value of a name token.
Definition: cfl_token.cpp:177
Int AttributeIntegerValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:396
void ClrEnd(void)
Clear End type (resolve empty section)
Definition: cfl_token.cpp:160
void SetInteger(const Int number)
Initialize as Integer token.
Definition: cfl_token.cpp:120
void SetBoolean(const Int number)
Initialize as Boolean token.
Definition: cfl_token.cpp:136
bool ExistsAttributeFloat(const std::string &name)
Test attibute existence.
Definition: cfl_token.cpp:375
TokenType
Token types:
Definition: cfl_token.h:81
@ Integer
1234 (non-negative integer)
Definition: cfl_token.h:87
@ Option
+xyZ+ (option string, may not contain a "+")
Definition: cfl_token.h:86
@ Float
-12.34 ("-" or "." turns an integer to a float)
Definition: cfl_token.h:90
@ Boolean
True/False
Definition: cfl_token.h:89
@ Cdata
... verbatim markup
Definition: cfl_token.h:92
@ End
<\label> (end of section)
Definition: cfl_token.h:84
@ Integer16
0x12fff ("0x" makes an integer an Integer16)
Definition: cfl_token.h:88
@ Begin
<label> (begin of section)
Definition: cfl_token.h:83
@ String
any string, space separated or quoted, must start with a letter
Definition: cfl_token.h:85
@ Binary
=ABhlkjj= (base64 encoded binary data)
Definition: cfl_token.h:91
@ None
Invalid/empty token
Definition: cfl_token.h:82
bool IsString(void) const
Test token Type.
Definition: cfl_token.cpp:243
static void WriteVerbatim(std::ostream *pStream, const std::string &rString, bool lfflag=0)
Write a std::string value to an output stream.
Definition: cfl_token.cpp:416
void Write(std::ostream *pStream) const
Write Token to output stream.
Definition: cfl_token.cpp:749
Int mIntegerValue
Token integer value (if Token is of type Integer or Integer16)
Definition: cfl_token.h:642
faudes::Float mFloatValue
Token float value (if Token is of type Float or Integer)
Definition: cfl_token.h:645
Int IntegerValue(void) const
Get integer value of a numeric token.
Definition: cfl_token.cpp:166
bool IsNone(void) const
Test token Type.
Definition: cfl_token.cpp:213
void InsAttributeBoolean(const std::string &name, Int value)
Insert named attribute with boolean value.
Definition: cfl_token.cpp:336
bool IsInteger(void) const
Test token Type.
Definition: cfl_token.cpp:218
std::string mOptionValue
Token std::string value (if token is of type Option)
Definition: cfl_token.h:639
void SetString(const std::string &rName)
Initialize as String token.
Definition: cfl_token.cpp:84
int ReadSpace(std::istream *pStream, bool fcomments=true)
Read (ignore) spaces on input file stream.
Definition: cfl_token.cpp:589
faudes::Float AttributeFloatValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:406
static int ReadCharacterData(std::istream *pStream, std::string &rString, bool fcomments)
Read chracter data from an input file stream.
Definition: cfl_token.cpp:918
static int ReadEscapedString(std::istream *pStream, char stop, std::string &rString)
Read a std::string value from an input file stream.
Definition: cfl_token.cpp:857
bool ExistsAttributeString(const std::string &name)
Test attibute existence.
Definition: cfl_token.cpp:355
void SetOption(const std::string &rName)
Initialize as Option token.
Definition: cfl_token.cpp:112
bool IsEmpty(void) const
Test token Type.
Definition: cfl_token.cpp:280
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
void SetFloat(const faudes::Float number)
Initialize as Float token.
Definition: cfl_token.cpp:144
void SetEmpty(const std::string &rName)
Initialize as empty-tag token.
Definition: cfl_token.cpp:105
void InsAttribute(const std::string &name, const std::string &value)
Insert named attribute, no type.
Definition: cfl_token.cpp:299
Token(void)
Empty constructor, constructs None token.
Definition: cfl_token.cpp:29
bool IsBoolean(void) const
Test token Type.
Definition: cfl_token.cpp:228
static void WriteBinary(std::ostream *pStream, const char *pData, std::size_t len)
Write specified binary data as base64 string to output stream.
Definition: cfl_token.cpp:445
int ReadAttributes(std::istream *pStream)
Read and interpret attribute definitions of begin tags from an input file stream.
Definition: cfl_token.cpp:957
int ReadBinary(std::istream *pStream)
Read a base64 binary string from an input file stream.
Definition: cfl_token.cpp:513
void InsAttributeFloat(const std::string &name, faudes::Float value)
Insert named attribute with integer value.
Definition: cfl_token.cpp:346
void ClrAttribute(const std::string &name)
Clear attribute.
Definition: cfl_token.cpp:285
void ClearAttributes()
Clear all attributes.
Definition: cfl_token.cpp:292
static int WriteEscapedString(std::ostream *pStream, const std::string &outstr)
Write a std::string value to an output stream.
Definition: cfl_token.cpp:812
int mType
Token type.
Definition: cfl_token.h:633
std::map< std::string, AttributeValue >::const_iterator caiterator
Definition: cfl_token.h:669
const std::string & OptionValue(void) const
Get option value of a name token.
Definition: cfl_token.cpp:183
void SetBegin(const std::string &rName)
Initialize as Begin token.
Definition: cfl_token.cpp:91
int mAttributeCount
Attribute sort index (for nice output only)
Definition: cfl_token.h:665
bool ExistsAttributeInteger(const std::string &name)
Test attibute existence.
Definition: cfl_token.cpp:365
void InsAttributeInteger(const std::string &name, Int value)
Insert named attribute with integer value.
Definition: cfl_token.cpp:318
bool InterpretNumber(void)
Interpret string a s number.
Definition: cfl_token.cpp:653
int Read(std::istream *pStream, bool fcomments=true)
Read Token from input stream.
Definition: cfl_token.cpp:1205
void InsAttributeString(const std::string &name, const std::string &value)
Insert named attribute with string value.
Definition: cfl_token.cpp:309
std::map< std::string, AttributeValue > mAttributes
Attribute value map.
Definition: cfl_token.h:662
bool IsEnd(void) const
Test token Type.
Definition: cfl_token.cpp:269
bool IsFloat(void) const
Test token Type.
Definition: cfl_token.cpp:233
int ReadString(std::istream *pStream, char stop)
Read a std::string value from an input file stream.
Definition: cfl_token.cpp:851
std::string mPreceedingSpace
Preceeding space (cosmetic)
Definition: cfl_token.h:648
bool IsOption(void) const
Test token Type.
Definition: cfl_token.cpp:238
void SetEnd(const std::string &rName)
Initialize as End token.
Definition: cfl_token.cpp:98
const std::string & AttributeStringValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:385
void InterpretAttribute(aiterator ait)
Interpret attribute value from string.
Definition: cfl_token.cpp:644
void InsAttributeInteger16(const std::string &name, Int value)
Insert named attribute with integer value.
Definition: cfl_token.cpp:327
faudes::Float FloatValue(void) const
Get float value of a numeric token.
Definition: cfl_token.cpp:172
std::string mStringValue
Token std::string value (for any token type)
Definition: cfl_token.h:636
TokenType Type(void) const
Get token Type.
Definition: cfl_token.cpp:198
libFAUDES resides within the namespace faudes.
std::string ExpandString(const std::string &rString, unsigned int len)
Fill string with spaces up to a given length if length of the string is smaller than given length par...
Definition: cfl_helper.cpp:80
std::string ToStringFloat(Float number)
float to string
Definition: cfl_helper.cpp:64
std::string ToStringInteger16(Int number)
integer to string base 16
Definition: cfl_helper.cpp:54
double Float
Type definition for real type.
std::string ToStringInteger(Int number)
integer to string
Definition: cfl_helper.cpp:43
long int Int
Type definition for integer type (let target system decide, minimum 32bit)

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen