/* Parse one to six hex digits, optionally followed by a single whitespace character. (In a string, a backslash followed by this is interpreted as a hex escape.) */ static int parse_escaped_hex(mincss_context *context, int32_t *retval) { /* The backslash has already been accepted. */ int count = 0; int32_t res = 0; int32_t ch = -1; while (1) { ch = next_char(context); if (ch == -1) { if (count) *retval = res; return count; } count++; if (count > 6) break; if (!IS_HEX_DIGIT(ch)) break; if (ch >= '0' && ch <= '9') ch -= '0'; else if (ch >= 'A' && ch <= 'F') ch -= ('A'-10); else if (ch >= 'a' && ch <= 'f') ch -= ('a'-10); else ch = 0; res = (res << 4) + ch; } if (ch == '\r' && count >= 2) { /* swallow the \r, plus an \n if one follows */ ch = next_char(context); if (ch == -1) { *retval = res; return count; } count++; if (ch == '\n') { *retval = res; return count; } putback_char(context, 1); count -= 1; *retval = res; return count; } if (IS_WHITESPACE(ch) && count >= 2) { /* swallow it */ *retval = res; return count; } putback_char(context, 1); count -= 1; if (count) *retval = res; return count; }
/* * Enumerate new number */ void _lex::_enum_number(void) { trace( LEX_TRACE_ENABLE, TRACE_ENTRY, "lex::enum_number" ); _typ = LEX_TOKEN_NUMBER; _txt += get_char(); if(next_char()) { if(get_char() == HEX_DEC_L || get_char() == HET_DEC_U) { _typ = LEX_TOKEN_HEX_NUMBER; _txt.clear(); if(!next_char()) throw std::runtime_error( _format_exception( LEX_EXC_INVALID_HEX_NUM, get_line() )); while(IS_HEX_DIGIT(get_char())) { _txt += get_char(); if(has_next_char()) { if(!next_char()) throw std::runtime_error( _format_exception( LEX_EXC_UNEXP_EOF, get_line() )); } else break; } } else if(isdigit(get_char())) { _txt += get_char(); if(!next_char()) throw std::runtime_error( _format_exception( LEX_EXC_UNEXP_EOF, get_line() )); while(isdigit(get_char())) { _txt += get_char(); if(has_next_char()) { if(!next_char()) throw std::runtime_error( _format_exception( LEX_EXC_UNEXP_EOF, get_line() )); } else break; } } } trace( LEX_TRACE_ENABLE, TRACE_EXIT, "lex::enum_number" ); }