diff --git a/include/linphone/utils/utils.h b/include/linphone/utils/utils.h index 8a160d63b..cf384f01c 100644 --- a/include/linphone/utils/utils.h +++ b/include/linphone/utils/utils.h @@ -71,12 +71,14 @@ namespace Utils { 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 unsigned long long stoull (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 unsigned long long stoull (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 e91583b34..66261305b 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -92,6 +92,10 @@ long long Utils::stoll (const string &str, size_t *idx, int base) { return stoll(str.c_str(), idx, base); } +unsigned long long Utils::stoull (const string &str, size_t *idx, int base) { + return stoull(str.c_str(), idx, base); +} + double Utils::stod (const string &str, size_t *idx) { return stod(str.c_str(), idx); } @@ -125,6 +129,16 @@ long long Utils::stoll (const char *str, size_t *idx, int base) { return v; } +unsigned long long Utils::stoull (const char *str, size_t *idx, int base) { + char *p; + unsigned long long v = static_cast(strtoull(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 defd7b847..7590002dd 100644 --- a/src/variant/variant.cpp +++ b/src/variant/variant.cpp @@ -351,7 +351,38 @@ static inline long long getValueAsNumber (const VariantPrivate &p, bool *soFarSo } static inline unsigned long long getValueAsUnsignedNumber (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 static_cast(getAssumedNumber(p)); + + case Variant::UnsignedInt: + case Variant::UnsignedShort: + case Variant::UnsignedLong: + case Variant::UnsignedLongLong: + return getAssumedUnsignedNumber(p); + + case Variant::Bool: + return static_cast(p.value.b); + + case Variant::String: + return Utils::stoull(*p.value.str); + + case Variant::Generic: + return static_cast(!!p.value.g); + + default: + *soFarSoGood = false; + } + return 0; }