Skip to main content
added 104 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22

or even faster:

#define IsDigit(X) (((uint32_t)X - '0') < 10u)

Here is an example of how this can be used:

Here is an example of how this can be used:

or even faster:

#define IsDigit(X) (((uint32_t)X - '0') < 10u)

Here is an example of how this can be used:

added 124 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22

For parsers where performance is critical, you really can’t beat using old-school C strings. Considering the following code:

  1. For parsers where performance is critical, you really can’t beat using old-school C strings. Considering the following code:

You may also consider creating your own version of isdigit with something like this:

  1. The ctype functions in MSVC are notoriously slow (See this link). You may consider creating your own versions something like this:
bool IsDigitOrNumIsDigit(char c) {
    switchreturn (c) {
        case>= '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case '.':
        case 'e':
        case '-':
        case '+':
            return true;
        default:
            return false;
 && c <= }'9';
}

For parsers where performance is critical, you really can’t beat using old-school C strings. Considering the following code:

You may also consider creating your own version of isdigit with something like this:

bool IsDigitOrNum(char c) {
    switch (c) {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case '.':
        case 'e':
        case '-':
        case '+':
            return true;
        default:
            return false;
    }
}
  1. For parsers where performance is critical, you really can’t beat using old-school C strings. Considering the following code:
  1. The ctype functions in MSVC are notoriously slow (See this link). You may consider creating your own versions something like this:
bool IsDigit(char c) {
    return c >= '0' && c <= '9';
}
added 600 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22

You may also consider creating your own version of isdigit with something like this:

bool IsDigitOrNum(char c) {
    switch (c) {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case '.':
        case 'e':
        case '-':
        case '+':
            return true;
        default:
            return false;
    }
}

Here is an example of how this can be used:

Here is an example of how this can be used:

You may also consider creating your own version of isdigit with something like this:

bool IsDigitOrNum(char c) {
    switch (c) {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case '.':
        case 'e':
        case '-':
        case '+':
            return true;
        default:
            return false;
    }
}

Here is an example of how this can be used:

added 823 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22
Loading
deleted 1 character in body
Source Link
jdt
  • 2.5k
  • 6
  • 22
Loading
Source Link
jdt
  • 2.5k
  • 6
  • 22
Loading