InputIterator extract_lws (InputIterator begin, InputIterator end) { InputIterator it = begin; // strip leading CRLF if (end - begin > 2 && *begin == '\r' && * (begin + 1) == '\n' && is_whitespace_char (static_cast<unsigned char> (* (begin + 2) ) ) ) { it += 3; } it = std::find_if (it, end, &is_not_whitespace_char); return it; }
bool VLogLexer::consume_char() { bool found_whitespace = false; ConsumeCharState state = CONSUME_IDLE; char next_char; do { if(input_stream.is_eof()) { eof = true; switch(state) { case CONSUME_BLOCK_COMMENT: throw TokenErr("Unterminated block comment at end of file", line_char, current_line); case CONSUME_BEGUN_COMMENT: throw TokenErr("Unexpected EOF", line_char, current_line); } return true; } next_char = input_stream.peek(); switch(state) { case CONSUME_IDLE: if(next_char == '/') { state = CONSUME_BEGUN_COMMENT; } else if(next_char == '\n') { current_line++; line_char = 0; } break; case CONSUME_BEGUN_COMMENT: if(next_char == '/') { state = CONSUME_LINE_COMMENT; found_whitespace = true; } else if(next_char == '*') { state = CONSUME_BLOCK_COMMENT; found_whitespace = true; } else { return found_whitespace; } break; case CONSUME_BLOCK_COMMENT: if(next_char == '*') { state = CONSUME_FINISHING_BLOCK_COMMENT; } break; case CONSUME_FINISHING_BLOCK_COMMENT: if(next_char == '/') { state = CONSUME_FINISHING_BLOCK_COMMENT2; break; } state = CONSUME_BLOCK_COMMENT; break; case CONSUME_FINISHING_BLOCK_COMMENT2: state = CONSUME_IDLE; break; case CONSUME_LINE_COMMENT: if(next_char == '\n') { state = CONSUME_IDLE; line_char = 0; current_line++; } break; } current_char = input_stream.get(); current_pos++; line_char++; if(is_whitespace_char(current_char)) found_whitespace = true; } while (is_whitespace_char(current_char) || (state != CONSUME_IDLE)); return found_whitespace; }