12 #include <boost/format.hpp> 18 using namespace boost;
24 static inline double mystrtod(
const char* nptr,
char** endptr)
26 const char*
org = nptr;
33 }
else if(*nptr ==
'-'){
37 if(*nptr ==
'n' || *nptr ==
'N')
40 if(*nptr ==
'a' || *nptr ==
'A')
43 if(*nptr ==
'n' || *nptr ==
'N')
46 *endptr = (
char *)nptr;
53 *endptr = (
char *)org;
57 if(isdigit((
unsigned char)*nptr)){
60 value = value * 10.0 + (*nptr -
'0');
62 }
while(isdigit((
unsigned char)*nptr));
67 if(isdigit((
unsigned char)*nptr)){
71 value += small * (*nptr -
'0');
74 }
while(isdigit((
unsigned char)*nptr));
77 if(valid && (*nptr ==
'e' || *nptr ==
'E')){
83 }
else if(*nptr ==
'-'){
87 if(isdigit((
unsigned char)*nptr)){
91 p = p * 10.0 + (*nptr -
'0');
93 }
while(isdigit((
unsigned char)*nptr));
94 value *= pow(10.0, psign * p);
98 *endptr = (
char*)nptr;
100 *endptr = (
char*)org;
106 std::string EasyScanner::Exception::getFullMessage()
111 m += str(format(
" at line %1%") % lineNumber);
115 m += str(format(
" of %1%") %
filename);
122 EasyScanner::EasyScanner()
131 EasyScanner::EasyScanner(
string filename)
138 void EasyScanner::init()
143 lineNumberOffset = 1;
147 isLineOriented =
true;
148 defaultErrorMessage =
"unknown error of the lexical scanner";
150 whiteSpaceChars.push_back(
' ');
151 whiteSpaceChars.push_back(
'\t');
163 whiteSpaceChars(org.whiteSpaceChars)
226 SymbolMap::iterator p =
symbols->begin();
228 cout << p->first <<
" = " << p->second << std::endl;
289 this->filename.clear();
291 FILE* file = fopen(filename.c_str(),
"rb");
298 message = filename +
" cannot be found.";
301 message = string(
"I/O error in accessing ") +
filename;
355 }
else if(*
text ==
'\r'){
378 }
else if(*
text ==
'\r'){
392 char* current =
text;
405 if(isdigit((
unsigned char)*
text) || *text ==
'+' || *text ==
'-'){
421 }
else if(isalpha((
unsigned char)*text)){
424 while(isalnum((
unsigned char)*text) || *text ==
'_') text++;
436 }
else if(ispunct((
unsigned char)*text)){
444 }
else if(*text ==
'\0'){
534 if(isgraph((
unsigned char)*
text)){
569 int c = (
unsigned char)*
text;
570 if(!isalnum(c) && isascii(c) && c !=
'_'){
590 int c = (
unsigned char)*
text;
591 if(isspace(c) || iscntrl(c) || c == delimiterChar){
612 if(*str++ != *
text++){
633 }
else if(allowNoQuotedWord){
715 char* end =
text - 1;
770 while(*matchString !=
'\0'){
771 if(*scanner.
text++ != *matchString++){
782 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)