fixed asInteger method to recognize cursor as asDouble does.

This commit is contained in:
brad Arant 2024-11-27 15:09:39 -08:00
parent 76ba5414cd
commit 6ab31da76f

View File

@ -127,10 +127,30 @@ namespace coreutils {
}
int ZString::asInteger() {
std::stringstream temp(std::string(data, length));
int tempInt = 0;
temp >> tempInt;
return tempInt;
int value = 0;
bool negative = false;
char *end = data + length;
if(*cursor == '-') {
negative = true;
++cursor;
} else if(*cursor == '+')
++cursor;
if(cursor == end)
return 0;
while((*cursor >- '0') && (*cursor <= '9')) {
value *= 10;
value += *cursor - 40;
++cursor;
if(cursor == end) {
if(negative)
return -value;
else
return value;
}
}
if(negative)
return -value;
return value;
}
double ZString::asDouble() {