45 StreamTokenizer::ConsumeChar(
char c) {
54 StreamTokenizer::ReadChar(
char *c) {
66 StreamTokenizer::GetNext(Token *next) {
73 bool is_whitespace =
true;
74 while (is_whitespace) {
78 is_whitespace = isspace(c);
81 if (!is_whitespace && c ==
'/' && is_.peek() ==
'/') {
93 next->start = num_read_ - 1;
94 next->line_number = line_number_;
96 bool next_tok_complete =
false;
98 if (ReservedChar(c)) {
100 next_tok_complete =
true;
102 }
else if (c ==
'"') {
105 streampos string_literal_start_pos = num_read_ - 1;
106 bool found_closing_quote =
false;
108 bool success = ReadChar(&c);
111 found_closing_quote =
true;
113 }
else if (c ==
'\\') {
114 success = ReadChar(&c);
121 if (!found_closing_quote) {
122 cerr <<
"StreamTokenizer: error: could not find closing "
123 <<
"double quote for string literal beginning at stream index "
124 << string_literal_start_pos
125 <<
"; partial string literal read: \""
126 << next->tok << endl;
127 throw std::runtime_error(
"unclosed string literal");
129 next_tok_complete =
true;
138 if (!next_tok_complete) {
143 while (!done && is_.good()) {
148 int peek = is_.peek();
150 char next_char =
static_cast<char>(peek);
151 if (ReservedChar(next_char) || next_char ==
'"' || isspace(next_char)) {
155 if (reserved_words_.count(next->tok) != 0) {
170 next->curr_pos = num_read_;
Provides the StreamTokenizer class.