diff --git a/include/linphone/utils/utils.h b/include/linphone/utils/utils.h index c6ffd2855..8a160d63b 100644 --- a/include/linphone/utils/utils.h +++ b/include/linphone/utils/utils.h @@ -70,11 +70,13 @@ namespace Utils { LINPHONE_PUBLIC std::string toString (const void *val); LINPHONE_PUBLIC int stoi (const std::string &str, size_t *idx = 0, int base = 10); + LINPHONE_PUBLIC long long stoll (const std::string &str, size_t *idx = 0, int base = 10); LINPHONE_PUBLIC double stod (const std::string &str, size_t *idx = 0); LINPHONE_PUBLIC float stof (const std::string &str, size_t *idx = 0); LINPHONE_PUBLIC bool stob (const std::string &str); LINPHONE_PUBLIC int stoi (const char *str, size_t *idx = 0, int base = 10); + LINPHONE_PUBLIC long long stoll (const char *str, size_t *idx = 0, int base = 10); LINPHONE_PUBLIC double stod (const char *str, size_t *idx = 0); LINPHONE_PUBLIC float stof (const char *str, size_t *idx = 0); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 877206952..e91583b34 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -85,33 +85,19 @@ string Utils::toString (const void *val) { } int Utils::stoi (const string &str, size_t *idx, int base) { - char *p; - int v = static_cast(strtol(str.c_str(), &p, base)); + return stoi(str.c_str(), idx, base); +} - if (idx) - *idx = static_cast(p - str.c_str()); - - return v; +long long Utils::stoll (const string &str, size_t *idx, int base) { + return stoll(str.c_str(), idx, base); } double Utils::stod (const string &str, size_t *idx) { - char *p; - double v = strtod(str.c_str(), &p); - - if (idx) - *idx = static_cast(p - str.c_str()); - - return v; + return stod(str.c_str(), idx); } float Utils::stof (const string &str, size_t *idx) { - char *p; - float v = strtof(str.c_str(), &p); - - if (idx) - *idx = static_cast(p - str.c_str()); - - return v; + return stof(str.c_str(), idx); } bool Utils::stob (const string &str) { @@ -129,6 +115,16 @@ int Utils::stoi (const char *str, size_t *idx, int base) { return v; } +long long Utils::stoll (const char *str, size_t *idx, int base) { + char *p; + long long v = static_cast(strtoll(str, &p, base)); + + if (idx) + *idx = static_cast(p - str); + + return v; +} + double Utils::stod (const char *str, size_t *idx) { char *p; double v = strtod(str, &p); diff --git a/src/variant/variant.cpp b/src/variant/variant.cpp index 96e5484d2..defd7b847 100644 --- a/src/variant/variant.cpp +++ b/src/variant/variant.cpp @@ -315,7 +315,38 @@ static inline unsigned long long getAssumedUnsignedNumber (const VariantPrivate // ----------------------------------------------------------------------------- static inline long long getValueAsNumber (const VariantPrivate &p, bool *soFarSoGood) { - // TODO. + const int type = p.getType(); + L_ASSERT(type > Variant::Invalid && type < Variant::MaxDefaultTypes); + + switch (static_cast(type)) { + case Variant::Int: + case Variant::Short: + case Variant::Long: + case Variant::LongLong: + case Variant::Char: + case Variant::Double: + case Variant::Float: + return getAssumedNumber(p); + + case Variant::UnsignedInt: + case Variant::UnsignedShort: + case Variant::UnsignedLong: + case Variant::UnsignedLongLong: + return static_cast(getAssumedUnsignedNumber(p)); + + case Variant::Bool: + return static_cast(p.value.b); + + case Variant::String: + return Utils::stoll(*p.value.str); + + case Variant::Generic: + return static_cast(!!p.value.g); + + default: + *soFarSoGood = false; + } + return 0; }