fixed asInteger method to recognize cursor as asDouble does.
This commit is contained in:
parent
76ba5414cd
commit
6ab31da76f
28
ZString.cpp
28
ZString.cpp
@ -127,10 +127,30 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ZString::asInteger() {
|
int ZString::asInteger() {
|
||||||
std::stringstream temp(std::string(data, length));
|
int value = 0;
|
||||||
int tempInt = 0;
|
bool negative = false;
|
||||||
temp >> tempInt;
|
char *end = data + length;
|
||||||
return tempInt;
|
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() {
|
double ZString::asDouble() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user