diff --git a/Jupiter/Functions.c b/Jupiter/Functions.c index 7af4b52..4b17f85 100644 --- a/Jupiter/Functions.c +++ b/Jupiter/Functions.c @@ -598,12 +598,24 @@ int Jupiter_strtoi(const char *str, int base) return Jupiter_strtoi_nospace(str, base); } +long long Jupiter_strtoll(const char *str, int base) +{ + while (isspace(*str)) str++; + return Jupiter_strtoll_nospace(str, base); +} + unsigned int Jupiter_strtoui(const char *str, int base) { while (isspace(*str)) str++; return Jupiter_strtoui_nospace(str, base); } +unsigned long long Jupiter_strtoull(const char *str, int base) +{ + while (isspace(*str)) str++; + return Jupiter_strtoull_nospace(str, base); +} + double Jupiter_strtod(const char *str) { while (isspace(*str)) str++; @@ -616,6 +628,12 @@ int Jupiter_strtoi_nospace(const char *str, int base) return -1 * Jupiter_strtoui_nospace(++str, base); } +long long Jupiter_strtoll_nospace(const char *str, int base) +{ + if (*str != '-') return Jupiter_strtoull_nospace(str, base); + return -1 * Jupiter_strtoull_nospace(++str, base); +} + unsigned int Jupiter_strtoui_nospace(const char *str, int base) { unsigned int total = 0; @@ -666,6 +684,56 @@ unsigned int Jupiter_strtoui_nospace(const char *str, int base) return total; } +unsigned long long Jupiter_strtoull_nospace(const char *str, int base) +{ + unsigned long long total = 0; + int tval; + if (*str == '-') return Jupiter_strtoi_nospace(str, base); + + if (*str == '+') str++; + + if (base == 0) // Guess a base. + { + if (*str == '0') + { + str++; + switch (*str) + { + case 'X': + case 'x': + str++; + base = 16; + break; + case 'B': + case 'b': + str++; + base = 2; + break; + default: + base = 8; + break; + } + } + else base = 10; + } + else if (base == 16) // check for optional preceeding hexadecimal prefix. + { + if (*str == '0') + { + str++; + if (*str == 'x' || *str == 'X') str++; + } + } + + while ((tval = Jupiter_getBase(*str, base)) != -1) + { + total = base * total + tval; + str++; + } + + return total; +} + double Jupiter_strtod_nospace(const char *str) { const int base = 10; @@ -711,6 +779,16 @@ int Jupiter_strtoi_s(const char *str, size_t length, int base) return Jupiter_strtoi_nospace_s(str, length, base); } +long long Jupiter_strtoll_s(const char *str, size_t length, int base) +{ + while (length != 0 && isspace(*str)) + { + str++; + length--; + } + return Jupiter_strtoll_nospace_s(str, length, base); +} + unsigned int Jupiter_strtoui_s(const char *str, size_t length, int base) { while (length != 0 && isspace(*str)) @@ -721,6 +799,16 @@ unsigned int Jupiter_strtoui_s(const char *str, size_t length, int base) return Jupiter_strtoui_nospace_s(str, length, base); } +unsigned long long Jupiter_strtoull_s(const char *str, size_t length, int base) +{ + while (length != 0 && isspace(*str)) + { + str++; + length--; + } + return Jupiter_strtoull_nospace_s(str, length, base); +} + double Jupiter_strtod_s(const char *str, size_t length) { while (length != 0 && isspace(*str)) @@ -731,7 +819,7 @@ double Jupiter_strtod_s(const char *str, size_t length) return Jupiter_strtod_nospace_s(str, length); } -signed int Jupiter_strtoi_nospace_s(const char *str, size_t length, int base) +int Jupiter_strtoi_nospace_s(const char *str, size_t length, int base) { if (length == 0) return 0; if (*str != '-') return Jupiter_strtoui_nospace_s(str, length, base); @@ -802,6 +890,77 @@ unsigned int Jupiter_strtoui_nospace_s(const char *str, size_t length, int base) return total; } +long long Jupiter_strtoll_nospace_s(const char *str, size_t length, int base) +{ + if (length == 0) return 0; + if (*str != '-') return Jupiter_strtoull_nospace_s(str, length, base); + return -1 * Jupiter_strtoull_nospace_s(++str, --length, base); +} + +unsigned long long Jupiter_strtoull_nospace_s(const char *str, size_t length, int base) +{ + unsigned long long total = 0; + int tval; + if (length == 0) return total; + if (*str == '-') return Jupiter_strtoi_nospace(str, base); + + if (*str == '+') + { + if (--length == 0) return total; + str++; + } + + if (base == 0) // Guess a base. + { + if (*str == '0') + { + if (--length == 0) return total; + str++; + switch (*str) + { + case 'X': + case 'x': + if (--length == 0) return total; + str++; + base = 16; + break; + case 'B': + case 'b': + if (--length == 0) return total; + str++; + base = 2; + break; + default: + base = 8; + break; + } + } + else base = 10; + } + else if (base == 16) // check for optional preceeding hexadecimal prefix. + { + if (*str == '0') + { + if (--length == 0) return total; + str++; + if (*str == 'x' || *str == 'X') + { + if (--length == 0) return total; + str++; + } + } + } + + while ((tval = Jupiter_getBase(*str, base)) != -1) + { + total = base * total + tval; + if (--length == 0) return total; + str++; + } + + return total; +} + double Jupiter_strtod_nospace_s(const char *str, size_t length) { const int base = 10; diff --git a/Jupiter/Functions.h b/Jupiter/Functions.h index 39548d2..66bf489 100644 --- a/Jupiter/Functions.h +++ b/Jupiter/Functions.h @@ -355,7 +355,9 @@ JUPITER_API int Jupiter_getBase(unsigned char c, int base); * @return Interpretation of the string as an integer on success, 0 otherwise. */ JUPITER_API int Jupiter_strtoi(const char *str, int base); +JUPITER_API long long Jupiter_strtoll(const char *str, int base); JUPITER_API unsigned int Jupiter_strtoui(const char *str, int base); +JUPITER_API unsigned long long Jupiter_strtoull(const char *str, int base); /** * @brief Interpets a string into a floating point decimal number. @@ -375,7 +377,9 @@ JUPITER_API double Jupiter_strtod(const char *str); * @return Interpretation of the string as an integer on success, 0 otherwise. */ JUPITER_API int Jupiter_strtoi_nospace(const char *str, int base); +JUPITER_API long long Jupiter_strtoll_nospace(const char *str, int base); JUPITER_API unsigned int Jupiter_strtoui_nospace(const char *str, int base); +JUPITER_API unsigned long long Jupiter_strtoull_nospace(const char *str, int base); /** * @brief Interpets a string into a floating point decimal number. @@ -396,7 +400,9 @@ JUPITER_API double Jupiter_strtod_nospace(const char *str); * @return Interpretation of the string as an integer on success, 0 otherwise. */ JUPITER_API int Jupiter_strtoi_s(const char *str, size_t length, int base); +JUPITER_API long long Jupiter_strtoll_s(const char *str, size_t length, int base); JUPITER_API unsigned int Jupiter_strtoui_s(const char *str, size_t length, int base); +JUPITER_API unsigned long long Jupiter_strtoull_s(const char *str, size_t length, int base); /** * @brief Interpets a string into a floating point decimal number. @@ -417,7 +423,9 @@ JUPITER_API double Jupiter_strtod_s(const char *str, size_t length); * @return Interpretation of the string as an integer on success, 0 otherwise. */ JUPITER_API int Jupiter_strtoi_nospace_s(const char *str, size_t length, int base); +JUPITER_API long long Jupiter_strtoll_nospace_s(const char *str, size_t length, int base); JUPITER_API unsigned int Jupiter_strtoui_nospace_s(const char *str, size_t length, int base); +JUPITER_API unsigned long long Jupiter_strtoull_nospace_s(const char *str, size_t length, int base); /** * @brief Interpets a string into a floating point decimal number. diff --git a/Jupiter/Readable_String.h b/Jupiter/Readable_String.h index 570a9d7..e5f31e5 100644 --- a/Jupiter/Readable_String.h +++ b/Jupiter/Readable_String.h @@ -204,7 +204,9 @@ namespace Jupiter * @return Integer representation of the string. */ int asInt(int base = 0) const; + long long asLongLong(int base = 0) const; unsigned int asUnsignedInt(int base = 0) const; + unsigned long long asUnsignedLongLong(int base = 0) const; /** * @brief Interprets the string as a floating-point decimal number. diff --git a/Jupiter/Readable_String_Imp.h b/Jupiter/Readable_String_Imp.h index 607d693..4607b9c 100644 --- a/Jupiter/Readable_String_Imp.h +++ b/Jupiter/Readable_String_Imp.h @@ -878,6 +878,16 @@ template int Jupiter::Readable_String::asInt(int base) const return 0; } +template<> long long inline Jupiter::Readable_String::asLongLong(int base) const +{ + return Jupiter_strtoll_s(this->ptr(), this->size(), base); +} + +template long long Jupiter::Readable_String::asLongLong(int base) const +{ + return 0; +} + template<> unsigned int inline Jupiter::Readable_String::asUnsignedInt(int base) const { return Jupiter_strtoui_s(this->ptr(), this->size(), base); @@ -888,6 +898,16 @@ template unsigned int Jupiter::Readable_String::asUnsignedInt(int return 0; } +template<> unsigned long long inline Jupiter::Readable_String::asUnsignedLongLong(int base) const +{ + return Jupiter_strtoull_s(this->ptr(), this->size(), base); +} + +template unsigned long long Jupiter::Readable_String::asUnsignedLongLong(int base) const +{ + return 0; +} + template<> double inline Jupiter::Readable_String::asDouble() const { return Jupiter_strtod_s(this->ptr(), this->size()); diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index a4cb876..918c480 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ