From 6ab31da76f58fd64b295ad045b7509e7a9649d82 Mon Sep 17 00:00:00 2001 From: brad Arant Date: Wed, 27 Nov 2024 15:09:39 -0800 Subject: [PATCH] fixed asInteger method to recognize cursor as asDouble does. --- ZString.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ZString.cpp b/ZString.cpp index f2b749d..d7d0674 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -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() {