! * \brief Parses a decimal number * \return true If successful * * \param str C-string symbolizing the string to parse * \param number Optional argument to return the number parsed * \param endOfRead Optional argument to determine where parsing stopped */
| 20 | * \param endOfRead Optional argument to determine where parsing stopped |
| 21 | */ |
| 22 | bool ParseDecimal(const char* str, unsigned int* number, const char** endOfRead) |
| 23 | { |
| 24 | const char* ptr = str; |
| 25 | unsigned int val = 0; |
| 26 | while (*ptr >= '0' && *ptr <= '9') |
| 27 | { |
| 28 | val *= 10; |
| 29 | val += *ptr - '0'; |
| 30 | |
| 31 | ++ptr; |
| 32 | } |
| 33 | |
| 34 | if (str == ptr) |
| 35 | return false; |
| 36 | |
| 37 | if (number) |
| 38 | *number = val; |
| 39 | |
| 40 | if (endOfRead) |
| 41 | *endOfRead = ptr; |
| 42 | |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | /*! |
| 47 | * \brief Parses a hexadecimal number |