46 StreamTokenizer::ConsumeChar(
char c) {
51 line_start_pos_ = num_read_;
56 StreamTokenizer::ReadChar(
char *c) {
68 StreamTokenizer::GetNext(Token *next) {
75 bool is_whitespace =
true;
76 while (is_whitespace) {
80 is_whitespace = isspace(c);
83 if (!is_whitespace && c ==
'/' && is_.peek() ==
'/') {
95 next->start = num_read_ - 1;
96 next->line_number = line_number_;
97 next->line_start_pos = line_start_pos_;
99 bool next_tok_complete =
false;
101 if (ReservedChar(c)) {
103 next_tok_complete =
true;
105 }
else if (c ==
'"') {
108 streampos string_literal_start_pos = num_read_ - 1;
109 bool found_closing_quote =
false;
111 bool success = ReadChar(&c);
114 found_closing_quote =
true;
116 }
else if (c ==
'\\') {
117 success = ReadChar(&c);
124 if (!found_closing_quote) {
125 ostringstream err_ss;
126 err_ss <<
"StreamTokenizer: error: could not find closing "
127 <<
"double quote for string literal beginning at stream index "
128 << string_literal_start_pos
129 <<
"; partial string literal read: \""
133 next_tok_complete =
true;
142 if (!next_tok_complete) {
147 while (!done && is_.good()) {
152 int peek = is_.peek();
154 char next_char =
static_cast<char>(peek);
155 if (ReservedChar(next_char) || next_char ==
'"' || isspace(next_char)) {
159 if (reserved_words_.count(next->tok) != 0) {
174 next->curr_pos = num_read_;
182 string getline(
const string &str,
size_t pos) {
184 for (; pos < str.length() && str[pos] !=
'\n'; ++pos) {
185 curr_line += str[pos];
195 return getline(
str(), token_[next_token_idx_ - 1].line_start_pos);
string str()
Returns the entire sequence of characters read so far by this stream tokenizer as a newly constructed...
Provides the StreamTokenizer class.
void Error(const std::string &message)
Reports an error encountered during parsing and/or construction of an object.
string line()
Returns a string consisting of the characters read so far of the current line containing the most rec...