Go to the documentation of this file. 1 #ifndef CNOID_UTIL_SIMPLE_SCANNER_H
2 #define CNOID_UTIL_SIMPLE_SCANNER_H
5 #include <cnoid/stdx/filesystem>
6 #include <fast_float/fast_float.h>
7 #include <fmt/format.h>
38 void clear(
bool doRelease =
true)
87 }
else if(!
ifs.eof() &&
ifs.fail()){
89 if(
ifs.peek() ==
'\n'){
101 int gcount =
ifs.gcount();
110 ifs.seekg(-gcount, std::ios::cur);
122 if(*end ==
'\n' || *end ==
'\0'){
145 while(*
pos ==
' ' || *
pos ==
'\t'){
184 }
else if(*
pos ==
'\r'){
208 const char* pos0 =
pos;
226 const char* org =
str;
228 throwEx(fmt::format(
"\"{}\" is expected", org));
234 ifs.seekg(initialSeekPos);
237 pos_type currentLinePos = initialSeekPos;
239 const char* str0 =
str;
240 char* found =
nullptr;
248 currentLinePos = nextLinePos;
249 nextLinePos =
ifs.tellg();
250 if(currentLinePos - initialSeekPos > maxLength){
260 out_seekPos = currentLinePos;
261 ifs.seekg(out_seekPos);
272 out_seekPos = initialSeekPos;
278 const char* pos0 =
pos;
280 while((*
pos !=
' ') && (*
pos !=
'\t') && (*
pos !=
'\r') && (*
pos !=
'\0')){
283 out_string.assign(pos0,
pos - pos0);
284 return !out_string.empty();
296 const char* pos0 =
pos;
297 while((*
pos !=
'\r') && (*
pos !=
'\n') && (*
pos !=
'\0')){
300 out_string.assign(pos0,
pos - pos0);
301 return !out_string.empty();
307 auto result = fast_float::from_chars(
pos,
bufEndPos, value);
308 if(result.ec == std::errc()){
319 out_value = std::strtol(
pos, &tail, 0);
330 int value = std::strtol(
pos, &tail, 0);
342 throw std::runtime_error(
343 fmt::format(
"{0} at line {1} of \"{2}\".",
const std::string & fromUTF8(const std::string &text)
Definition: UTF8.h:20
bool seekToString(pos_type initialSeekPos, const char *str, size_t maxLength, pos_type &out_seekPos)
Definition: SimpleScanner.h:232
std::string filename
Definition: SimpleScanner.h:26
std::vector< char > buf2
Definition: SimpleScanner.h:31
bool getLine()
Definition: SimpleScanner.h:73
int readIntEx()
Definition: SimpleScanner.h:327
std::string str(const Vector3 &v)
Definition: EigenUtil.cpp:206
static constexpr size_t buf1size
Definition: SimpleScanner.h:29
bool open(const std::string &filename)
Definition: SimpleScanner.h:53
const char * pos
Definition: SimpleScanner.h:22
int peekChar()
Definition: SimpleScanner.h:150
bool readString(std::string &out_string)
Definition: SimpleScanner.h:287
bool checkEOF()
Definition: SimpleScanner.h:198
void skipSpaces()
Definition: SimpleScanner.h:136
bool checkLF()
Definition: SimpleScanner.h:179
int readChar()
Definition: SimpleScanner.h:155
std::string tmpString
Definition: SimpleScanner.h:27
char * buf
Definition: SimpleScanner.h:20
bool readInt(int &out_value)
Definition: SimpleScanner.h:316
bool readStringToEOL(std::string &out_string)
Definition: SimpleScanner.h:293
bool checkCharAtCurrentPosition(int chara)
Definition: SimpleScanner.h:164
std::ifstream ifs
Definition: SimpleScanner.h:19
bool readStringAtCurrentPosition(std::string &out_string)
Definition: SimpleScanner.h:276
void checkStringEx(const char *str)
Definition: SimpleScanner.h:224
Definition: AbstractSceneLoader.h:11
SimpleScanner()
Definition: SimpleScanner.h:33
char buf1[buf1size]
Definition: SimpleScanner.h:30
const char * dummy
Definition: SimpleScanner.h:23
const char * bufEndPos
Definition: SimpleScanner.h:24
float readFloatEx()
Definition: SimpleScanner.h:304
Definition: SimpleScanner.h:14
size_t bufsize
Definition: SimpleScanner.h:21
size_t lineNumber
Definition: SimpleScanner.h:25
void clear(bool doRelease=true)
Definition: SimpleScanner.h:38
void moveForward()
Definition: SimpleScanner.h:131
void skipSpacesAndTabs()
Definition: SimpleScanner.h:143
void checkLFEx()
Definition: SimpleScanner.h:191
void close()
Definition: SimpleScanner.h:66
const std::string & toUTF8(const std::string &text)
Definition: UTF8.h:19
void throwEx(const std::string &error)
Definition: SimpleScanner.h:339
bool checkString(const char *str)
Definition: SimpleScanner.h:218
bool checkChar(int chara)
Definition: SimpleScanner.h:173
bool checkStringAtCurrentPosition(const char *str)
Definition: SimpleScanner.h:206
const std::string & currentLine()
Definition: SimpleScanner.h:118
std::ifstream::pos_type pos_type
Definition: SimpleScanner.h:17