Last active
August 29, 2015 14:07
-
-
Save hnsl/afd2caa13f5051c26eb0 to your computer and use it in GitHub Desktop.
validate_number with librcd re2c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static _Bool validate_number(fstr_t str) { | |
do { | |
uint8_t cur_rune; | |
re2c_state_000001: | |
goto re2c_state_000002; | |
re2c_state_000002: | |
if (str.len == 0) { | |
break; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if (cur_rune == '-') { | |
goto re2c_state_000003; | |
} | |
if (cur_rune == '0') { | |
goto re2c_state_000004; | |
} | |
if ((cur_rune >= '1' && cur_rune <= '9')) { | |
goto re2c_state_000010; | |
} | |
goto re2c_state_00000d; | |
re2c_state_000003: | |
if (str.len == 0) { | |
break; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if (cur_rune == '0') { | |
goto re2c_state_000004; | |
} | |
if ((cur_rune >= '1' && cur_rune <= '9')) { | |
goto re2c_state_000010; | |
} | |
goto re2c_state_00000d; | |
re2c_state_000004: | |
if (str.len == 0) { | |
goto re2c_state_00000c; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if (cur_rune == '.') { | |
goto re2c_state_000005; | |
} | |
if (cur_rune == 'e') { | |
goto re2c_state_000008; | |
} | |
if (cur_rune == 'E') { | |
goto re2c_state_00000f; | |
} | |
goto re2c_state_00000d; | |
re2c_state_00000c: | |
return 1; | |
re2c_state_000005: | |
if (str.len == 0) { | |
break; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_000006; | |
} | |
goto re2c_state_00000d; | |
re2c_state_000006: | |
if (str.len == 0) { | |
goto re2c_state_00000c; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_000007; | |
} | |
if (cur_rune == 'e') { | |
goto re2c_state_000008; | |
} | |
if (cur_rune == 'E') { | |
goto re2c_state_00000f; | |
} | |
goto re2c_state_00000d; | |
re2c_state_000007: | |
if (str.len == 0) { | |
goto re2c_state_00000c; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_000007; | |
} | |
if (cur_rune == 'e') { | |
goto re2c_state_000008; | |
} | |
if (cur_rune == 'E') { | |
goto re2c_state_00000f; | |
} | |
goto re2c_state_00000d; | |
re2c_state_000008: | |
if (str.len == 0) { | |
break; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if (cur_rune == '-') { | |
goto re2c_state_000009; | |
} | |
if (cur_rune == '+') { | |
goto re2c_state_00000e; | |
} | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_00000a; | |
} | |
goto re2c_state_00000d; | |
re2c_state_000009: | |
if (str.len == 0) { | |
break; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_00000a; | |
} | |
goto re2c_state_00000d; | |
re2c_state_00000a: | |
if (str.len == 0) { | |
goto re2c_state_00000c; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_00000b; | |
} | |
goto re2c_state_00000d; | |
re2c_state_00000b: | |
if (str.len == 0) { | |
goto re2c_state_00000c; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_00000b; | |
} | |
goto re2c_state_00000d; | |
re2c_state_00000d: | |
if (str.len == 0) { | |
break; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
break; | |
re2c_state_00000e: | |
if (str.len == 0) { | |
break; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_00000a; | |
} | |
goto re2c_state_00000d; | |
re2c_state_00000f: | |
if (str.len == 0) { | |
break; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if (cur_rune == '-') { | |
goto re2c_state_000009; | |
} | |
if (cur_rune == '+') { | |
goto re2c_state_00000e; | |
} | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_00000a; | |
} | |
goto re2c_state_00000d; | |
re2c_state_000010: | |
if (str.len == 0) { | |
goto re2c_state_00000c; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_000011; | |
} | |
if (cur_rune == '.') { | |
goto re2c_state_000005; | |
} | |
if (cur_rune == 'e') { | |
goto re2c_state_000008; | |
} | |
if (cur_rune == 'E') { | |
goto re2c_state_00000f; | |
} | |
goto re2c_state_00000d; | |
re2c_state_000011: | |
if (str.len == 0) { | |
goto re2c_state_00000c; | |
} | |
cur_rune = *str.str; | |
str.str++; | |
str.len--; | |
if ((cur_rune >= '0' && cur_rune <= '9')) { | |
goto re2c_state_000011; | |
} | |
if (cur_rune == '.') { | |
goto re2c_state_000005; | |
} | |
if (cur_rune == 'e') { | |
goto re2c_state_000008; | |
} | |
if (cur_rune == 'E') { | |
goto re2c_state_00000f; | |
} | |
goto re2c_state_00000d; | |
} while (0); | |
return ((_Bool)0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment