Created
December 9, 2016 13:50
-
-
Save LYP951018/ca7a240a8e8f66e8eb8c5bb693243a53 to your computer and use it in GitHub Desktop.
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
| bool SkipIfChar(const char* str, const char** newPos, char c) | |
| { | |
| const char* pos = str; | |
| while(*pos == c) | |
| ++pos; | |
| *newPos = pos; | |
| return pos != str; | |
| } | |
| bool SkipIfNextChar(const char* str, const char** newPos, char c) | |
| { | |
| if (*str == c) | |
| { | |
| *newPos = ++str; | |
| return true; | |
| } | |
| return false; | |
| } | |
| bool SkipIfSpace(const char* str, const char** newPos) | |
| { | |
| return SkipIfChar(str, newPos, ' '); | |
| } | |
| bool SkipIfDigit(const char* str, const char** newPos) | |
| { | |
| const char* pos = str; | |
| while(*pos <= '9' && *pos >= '0') | |
| ++pos; | |
| *newPos = pos; | |
| return pos != str; | |
| } | |
| bool SkipIfSign(const char* str, const char** newPos) | |
| { | |
| const char* pos = str; | |
| if(*pos == '+' || *pos == '-') | |
| ++pos; | |
| *newPos = pos; | |
| return pos != str; | |
| } | |
| bool SkipIfExp(const char* str, const char** newPos) | |
| { | |
| SkipIfSign(str, &str); | |
| if (SkipIfDigit(str, newPos)) | |
| return true; | |
| return false; | |
| } | |
| bool SkipIfInteger(const char* str, const char** newPos) | |
| { | |
| return SkipIfDigit(str, newPos) && (!SkipIfNextChar(*newPos, newPos, 'e') || SkipIfExp(*newPos, newPos)); | |
| } | |
| bool IsEnd(const char* str) | |
| { | |
| SkipIfSpace(str, &str); | |
| return *str == '\0'; | |
| } | |
| bool isNumber(const char* s) | |
| { | |
| SkipIfSpace(s, &s); | |
| SkipIfSign(s, &s); | |
| if (SkipIfNextChar(s, &s, '.')) | |
| { | |
| return SkipIfInteger(s, &s) && IsEnd(s); | |
| } | |
| else if (SkipIfDigit(s, &s)) | |
| { | |
| if (SkipIfNextChar(s, &s, '.')) | |
| { | |
| SkipIfDigit(s, &s); | |
| return (!SkipIfNextChar(s, &s, 'e') || SkipIfExp(s, &s)) && IsEnd(s); | |
| } | |
| else if (SkipIfNextChar(s, &s, 'e')) | |
| return SkipIfExp(s, &s) && IsEnd(s); | |
| return IsEnd(s); | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment