simplified myatoi64()
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5200 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
74bf17be17
commit
8f7c0e3679
1 changed files with 13 additions and 43 deletions
|
@ -26,56 +26,26 @@ int my_atoi(char *s)
|
|||
return (int)v;
|
||||
}
|
||||
|
||||
// Updated for int64 and simple bitwise operations
|
||||
__int64 myatoi64(char *s)
|
||||
{
|
||||
__int64 v=0;
|
||||
// Check for right input
|
||||
if (!s) return 0;
|
||||
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
|
||||
{
|
||||
s++;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s);
|
||||
if (c >= '0' && c <= '9') c-='0';
|
||||
else if (c >= 'a' && c <= 'f') c-='a'-10;
|
||||
else if (c >= 'A' && c <= 'F') c-='A'-10;
|
||||
else break;
|
||||
v<<=4;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s);
|
||||
if (c >= '0' && c <= '7') c-='0';
|
||||
else break;
|
||||
v<<=3;
|
||||
v+=c;
|
||||
}
|
||||
}
|
||||
int sign=0;
|
||||
|
||||
if (*s == '-')
|
||||
sign++;
|
||||
else
|
||||
s--;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int sign=0;
|
||||
if (*s == '-') sign++; else s--;
|
||||
for (;;)
|
||||
{
|
||||
int c=*(++s) - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
}
|
||||
if (sign) v = -v;
|
||||
int c=*(++s) - '0';
|
||||
if (c < 0 || c > 9) break;
|
||||
v*=10;
|
||||
v+=c;
|
||||
}
|
||||
|
||||
// Support for simple ORed expressions
|
||||
if (*s == '|')
|
||||
{
|
||||
v |= myatoi64(s+1);
|
||||
}
|
||||
if (sign)
|
||||
v = -v;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue