diff --git a/ZString.cpp b/ZString.cpp index c17c812..b313f23 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -1,6 +1,7 @@ #include "ZString.h" #include "Log.h" #include "Exception.h" +#include #include namespace coreutils { @@ -106,6 +107,10 @@ namespace coreutils { return tempInt; } + double ZString::asDouble() { + return strtod(cursor, &cursor); + } + int ZString::incrementCursor(int length) { char *temp = cursor; if((cursor + length) > (data + this->length)) diff --git a/ZString.h b/ZString.h index 830674f..e9fd32f 100644 --- a/ZString.h +++ b/ZString.h @@ -128,6 +128,13 @@ namespace coreutils { int asInteger(); + /// + /// Return the floating point value of the ZString from the cursor to the first + /// non-numeric character. + /// + + double asDouble(); + /// /// /// diff --git a/testing/mstring_test b/testing/mstring_test index abdf6a1..aca8e24 100755 Binary files a/testing/mstring_test and b/testing/mstring_test differ diff --git a/testing/zstring_test b/testing/zstring_test index 065d9ae..b9466d4 100755 Binary files a/testing/zstring_test and b/testing/zstring_test differ diff --git a/testing/zstring_test.cpp b/testing/zstring_test.cpp index c075315..4e30791 100644 --- a/testing/zstring_test.cpp +++ b/testing/zstring_test.cpp @@ -4,6 +4,12 @@ int main(int argc, char **argv) { + // Test floating point reader. + + coreutils::ZString pi("3.14159"); + double x = pi.asDouble(); + std::cout << "pi: " << x << std::endl; + // Test comparison operations. coreutils::ZString test1("else");