strtonum.cpp revision f3ce8123823edcdc352ae29f877990bff36a84cb
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync 255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync 255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255, 0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
255,
255,
255,
255,
255,
255,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync 255,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
255,
255,
255,
255,
255,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync 255,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
255,
255,
255,
255,
255,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync 255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync 255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync 255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255,
255 /** Approximated overflow shift checks. */ /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 */ 64,
64,
63,
63,
62,
62,
62,
62,
61,
61,
61,
61,
61,
61,
61,
61,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
60,
59,
59,
59,
59 printf("static const unsigned char g_auchDigits[256] =\n" for (i = 0; i < 256; i++) if (i >= '0' && i <= '9') else if (i >= 'a' && i <= 'z') else if (i >= 'A' && i <= 'Z') * Converts a string representation of a number to a 64-bit unsigned number. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_NEGATIVE_UNSIGNED * @retval VWRN_TRAILING_CHARS * @retval VWRN_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param ppszNext Where to store the pointer to the first char following the number. (Optional) * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pu64 Where to store the converted number. (optional) && (
psz[
1] ==
'x' ||
psz[
1] ==
'X')
&& (
psz[
1] ==
'x' ||
psz[
1] ==
'X')
* Note: We only support ascii digits at this time... :-) pszValue =
psz;
/* (Prefix and sign doesn't count in the digit counting.) */ while ((
uch = (
unsigned char)*
psz) != 0)
while (*
psz ==
' ' || *
psz ==
'\t')
* Converts a string representation of a number to a 64-bit unsigned number, * making sure the full string is converted. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_NEGATIVE_UNSIGNED * @retval VERR_TRAILING_SPACES * @retval VERR_TRAILING_CHARS * @param pszValue Pointer to the string value. * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pu64 Where to store the converted number. (optional) while (*
psz ==
' ' || *
psz ==
'\t')
* Converts a string representation of a number to a 64-bit unsigned number. * @returns 64-bit unsigned number on success. * @param pszValue Pointer to the string value. * Converts a string representation of a number to a 32-bit unsigned number. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_NEGATIVE_UNSIGNED * @retval VWRN_TRAILING_CHARS * @retval VWRN_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param ppszNext Where to store the pointer to the first char following the number. (Optional) * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pu32 Where to store the converted number. (optional) if (
u64 & ~
0xffffffffULL)
* Converts a string representation of a number to a 32-bit unsigned number, * making sure the full string is converted. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_NEGATIVE_UNSIGNED * @retval VERR_TRAILING_SPACES * @retval VERR_TRAILING_CHARS * @param pszValue Pointer to the string value. * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pu32 Where to store the converted number. (optional) if (
u64 & ~
0xffffffffULL)
* Converts a string representation of a number to a 64-bit unsigned number. * @returns 32-bit unsigned number on success. * @param pszValue Pointer to the string value. * Converts a string representation of a number to a 16-bit unsigned number. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_NEGATIVE_UNSIGNED * @retval VWRN_TRAILING_CHARS * @retval VWRN_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param ppszNext Where to store the pointer to the first char following the number. (Optional) * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pu16 Where to store the converted number. (optional) * Converts a string representation of a number to a 16-bit unsigned number, * making sure the full string is converted. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_NEGATIVE_UNSIGNED * @retval VERR_TRAILING_SPACES * @retval VERR_TRAILING_CHARS * @param pszValue Pointer to the string value. * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pu16 Where to store the converted number. (optional) * Converts a string representation of a number to a 16-bit unsigned number. * @returns 16-bit unsigned number on success. * @param pszValue Pointer to the string value. * Converts a string representation of a number to a 8-bit unsigned number. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_NEGATIVE_UNSIGNED * @retval VWRN_TRAILING_CHARS * @retval VWRN_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param ppszNext Where to store the pointer to the first char following the number. (Optional) * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pu8 Where to store the converted number. (optional) * Converts a string representation of a number to a 8-bit unsigned number, * making sure the full string is converted. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_NEGATIVE_UNSIGNED * @retval VERR_TRAILING_SPACES * @retval VERR_TRAILING_CHARS * @param pszValue Pointer to the string value. * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pu8 Where to store the converted number. (optional) * Converts a string representation of a number to a 8-bit unsigned number. * @returns 8-bit unsigned number on success. * @param pszValue Pointer to the string value. * Converts a string representation of a number to a 64-bit signed number. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_TRAILING_CHARS * @retval VWRN_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param ppszNext Where to store the pointer to the first char following the number. (Optional) * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pi64 Where to store the converted number. (optional) && (
psz[
1] ==
'x' ||
psz[
1] ==
'X')
&& (
psz[
1] ==
'x' ||
psz[
1] ==
'X')
* Note: We only support ascii digits at this time... :-) pszValue =
psz;
/* (Prefix and sign doesn't count in the digit counting.) */ while ((
uch = (
unsigned char)*
psz) != 0)
while (*
psz ==
' ' || *
psz ==
'\t')
* Converts a string representation of a number to a 64-bit signed number, * making sure the full string is converted. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VERR_TRAILING_CHARS * @retval VERR_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pi64 Where to store the converted number. (optional) while (*
psz ==
' ' || *
psz ==
'\t')
* Converts a string representation of a number to a 64-bit signed number. * @returns 64-bit signed number on success. * @param pszValue Pointer to the string value. * Converts a string representation of a number to a 32-bit signed number. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_TRAILING_CHARS * @retval VWRN_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param ppszNext Where to store the pointer to the first char following the number. (Optional) * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pi32 Where to store the converted number. (optional) * Converts a string representation of a number to a 32-bit signed number, * making sure the full string is converted. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VERR_TRAILING_CHARS * @retval VERR_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pi32 Where to store the converted number. (optional) * Converts a string representation of a number to a 32-bit signed number. * @returns 32-bit signed number on success. * @param pszValue Pointer to the string value. * Converts a string representation of a number to a 16-bit signed number. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_TRAILING_CHARS * @retval VWRN_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param ppszNext Where to store the pointer to the first char following the number. (Optional) * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pi16 Where to store the converted number. (optional) * Converts a string representation of a number to a 16-bit signed number, * making sure the full string is converted. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VERR_TRAILING_CHARS * @retval VERR_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pi16 Where to store the converted number. (optional) * Converts a string representation of a number to a 16-bit signed number. * @returns 16-bit signed number on success. * @param pszValue Pointer to the string value. * Converts a string representation of a number to a 8-bit signed number. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VWRN_TRAILING_CHARS * @retval VWRN_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param ppszNext Where to store the pointer to the first char following the number. (Optional) * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pi8 Where to store the converted number. (optional) * Converts a string representation of a number to a 8-bit signed number, * making sure the full string is converted. * @returns iprt status code. * Warnings are used to indicate conversion problems. * @retval VWRN_NUMBER_TOO_BIG * @retval VERR_TRAILING_CHARS * @retval VERR_TRAILING_SPACES * @param pszValue Pointer to the string value. * @param uBase The base of the representation used. * If the function will look for known prefixes before defaulting to 10. * @param pi8 Where to store the converted number. (optional) * Converts a string representation of a number to a 8-bit signed number. * @returns 8-bit signed number on success. * @param pszValue Pointer to the string value. /* Pick the next two digit from the string. */ while (
ch ==
' ' ||
ch ==
'\t')
/* Add the byte to the output buffer. */