diff options
author | Michi Henning <michi@zeroc.com> | 2002-07-08 02:26:16 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2002-07-08 02:26:16 +0000 |
commit | b6b4680a72e2d45ed9fca0fde867ce7564dccc21 (patch) | |
tree | 73b4ba7f47fc1ca5ac00a2d77d18c5ac4d99bf0f /cpp/src/IceUtil/InputUtil.cpp | |
parent | Move the ICE_INT64_LITERAL macro into its own header file (Ice/Const.h). (diff) | |
download | ice-b6b4680a72e2d45ed9fca0fde867ce7564dccc21.tar.bz2 ice-b6b4680a72e2d45ed9fca0fde867ce7564dccc21.tar.xz ice-b6b4680a72e2d45ed9fca0fde867ce7564dccc21.zip |
Added stringToInt64() to IceUtil. (Windows only for the moment)
Diffstat (limited to 'cpp/src/IceUtil/InputUtil.cpp')
-rw-r--r-- | cpp/src/IceUtil/InputUtil.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/cpp/src/IceUtil/InputUtil.cpp b/cpp/src/IceUtil/InputUtil.cpp new file mode 100644 index 00000000000..54eaa341889 --- /dev/null +++ b/cpp/src/IceUtil/InputUtil.cpp @@ -0,0 +1,59 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <IceUtil/InputUtil.h> +#include <stdlib.h> + +using namespace std; + +namespace IceUtil +{ + +Int64 +strToInt64(const char* s, char** endptr, int base) +{ +#if defined(_WIN32) + // TODO: WIN32 implementation is missing +#else + return strtoll(s, endptr, base); +#endif +} + +bool +stringToInt64(const string& stringToParse, Int64& result, string::size_type& pos) +{ + string::const_iterator i = stringToParse.begin(); + while(i != stringToParse.end() && isspace(*i)) + { + ++i; + } + if(i == stringToParse.end()) // String empty or nothing but whitespace + { + result = 0; + pos = string::npos; + return false; + } + string::const_reverse_iterator j = stringToParse.rbegin(); + while(isspace(*j)) + { + ++j; + } // j now points at last non-whitespace char + + string nonWhite(i, j.base()); // nonWhite has leading and trailing whitespace stripped + + errno = 0; + const char* startp = nonWhite.c_str(); + char* endp; + result = strtoll(startp, &endp, 0); + pos = *endp == '\0' ? string::npos : (i - stringToParse.begin()) + (endp - startp); + return startp != endp && errno != ERANGE && errno != EINVAL; +} + +} |