12 #include <boost/format.hpp> 18 using namespace boost;
26 static double mystrtod(
const char* nptr,
char** endptr)
28 const char*
org = nptr;
35 }
else if(*nptr ==
'-'){
39 if(isdigit((
unsigned char)*nptr)){
42 value = value * 10.0 + (*nptr -
'0');
44 }
while(isdigit((
unsigned char)*nptr));
49 if(isdigit((
unsigned char)*nptr)){
53 value += small * (*nptr -
'0');
56 }
while(isdigit((
unsigned char)*nptr));
59 if(valid && (*nptr ==
'e' || *nptr ==
'E')){
65 }
else if(*nptr ==
'-'){
69 if(isdigit((
unsigned char)*nptr)){
73 p = p * 10.0 + (*nptr -
'0');
75 }
while(isdigit((
unsigned char)*nptr));
76 value *= pow(10.0, psign * p);
80 *endptr = (
char*)nptr;
87 static inline double mystrtod(
const char* nptr,
char** endptr) {
88 return strtod(nptr, endptr);
93 std::string EasyScanner::Exception::getFullMessage()
98 m += str(format(
" at line %1%") % lineNumber);
102 m += str(format(
" of %1%") %
filename);
109 EasyScanner::EasyScanner()
118 EasyScanner::EasyScanner(
string filename)
125 void EasyScanner::init()
130 lineNumberOffset = 1;
134 isLineOriented =
true;
135 defaultErrorMessage =
"unknown error of the lexical scanner";
137 whiteSpaceChars.push_back(
' ');
138 whiteSpaceChars.push_back(
'\t');
150 whiteSpaceChars(org.whiteSpaceChars)
213 SymbolMap::iterator p =
symbols->begin();
215 cout << p->first <<
" = " << p->second << std::endl;
276 this->filename.clear();
278 FILE* file = fopen(filename.c_str(),
"rb");
285 message = filename +
" cannot be found.";
288 message = string(
"I/O error in accessing ") +
filename;
342 }
else if(*
text ==
'\r'){
365 }
else if(*
text ==
'\r'){
379 char* current =
text;
392 if(isdigit((
unsigned char)*
text) || *text ==
'+' || *text ==
'-'){
408 }
else if(isalpha((
unsigned char)*text)){
411 while(isalnum((
unsigned char)*text) || *text ==
'_') text++;
423 }
else if(ispunct((
unsigned char)*text)){
431 }
else if(*text ==
'\0'){
521 if(isgraph((
unsigned char)*
text)){
556 int c = (
unsigned char)*
text;
557 if(!isalnum(c) && isascii(c) && c !=
'_'){
577 int c = (
unsigned char)*
text;
578 if(isspace(c) || iscntrl(c) || c == delimiterChar){
599 if(*str++ != *
text++){
620 }
else if(allowNoQuotedWord){
702 char* end =
text - 1;
757 while(*matchString !=
'\0'){
758 if(*scanner.
text++ != *matchString++){
769 if(*scanner.
text++ != matchChar){
void setLineOriented(bool on)
int extractQuotedString()
void setCommentChar(char cc)
if 0, comment is disabled
bool readString(const int delimiterChar= ',')
Modifications controlling boost library behavior.
void loadFile(const std::string &filename)
bool readLF()
reading a line feed
bool readQuotedString(bool allowNoQuotedWord=false)
void setQuoteChar(char qc)
void setWhiteSpaceChar(char ws)
static double mystrtod(const char *nptr, char **endptr)
void throwException(const char *message)
std::vector< int > whiteSpaceChars
std::map< std::string, int > SymbolMap
int getSymbolID(const std::string &symbol)
void setText(const char *text, int len)
std::string defaultErrorMessage
bool readString0(const int delimiterChar)
friend HRP_UTIL_EXPORT EasyScanner & operator>>(EasyScanner &scanner, double &value)
The header file of a text scanner class.
bool readUnquotedTextBlock()
void setLineNumberOffset(int offset)