diff options
author | Mike <git@mjpa.co.uk> | 2011-02-17 00:41:06 +0300 |
---|---|---|
committer | Mike <git@mjpa.co.uk> | 2011-02-17 00:41:06 +0300 |
commit | 1f30ac8c2611da6c4826c0876889c45870f5fc91 (patch) | |
tree | 7ea90eb81f08118928ef16b5e75d4eb9701edb15 | |
parent | bf972def637387657919617dc462cae2bcdbba78 (diff) |
Added ParseDecimal() and a doc fix on ParseInt()
-rw-r--r-- | src/JSON.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/JSON.cpp b/src/JSON.cpp index a79a477..14f11dc 100644 --- a/src/JSON.cpp +++ b/src/JSON.cpp @@ -253,7 +253,7 @@ bool JSON::ExtractString(const wchar_t **data, std::wstring &str) * * @param wchar_t** data Pointer to a wchar_t* that contains the JSON text * - * @return int Returns the int value of the number found + * @return double Returns the double value of the number found */ double JSON::ParseInt(const wchar_t **data) { @@ -263,3 +263,25 @@ double JSON::ParseInt(const wchar_t **data) return integer; } + +/** + * Parses some text as though it is a decimal + * + * @access protected + * + * @param wchar_t** data Pointer to a wchar_t* that contains the JSON text + * + * @return double Returns the double value of the decimal found + */ +double JSON::ParseDecimal(const wchar_t **data) +{ + double decimal = 0.0; + double factor = 0.1; + while (**data != 0 && **data >= '0' && **data <= '9') + { + int digit = (*(*data)++ - '0'); + decimal = decimal + digit * factor; + factor *= 0.1; + } + return decimal; +} |