diff options
author | Henning Baldersheim <balder@oath.com> | 2019-06-05 06:22:15 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2019-06-14 13:34:21 +0000 |
commit | f1fcc615286a9637101458c298980525a0d1eaa7 (patch) | |
tree | 68c9d0cf096ab5da8bb30b0c68071254e2699473 /searchlib | |
parent | 766e77eecd02a1a5de1a1639a687f9aa4ad6e5a0 (diff) |
Use from_chars
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/attribute/enumstore/enumstore_test.cpp | 6 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/features/utils.cpp | 31 |
2 files changed, 26 insertions, 11 deletions
diff --git a/searchlib/src/tests/attribute/enumstore/enumstore_test.cpp b/searchlib/src/tests/attribute/enumstore/enumstore_test.cpp index 6b6abd956fc..5476f0f8e66 100644 --- a/searchlib/src/tests/attribute/enumstore/enumstore_test.cpp +++ b/searchlib/src/tests/attribute/enumstore/enumstore_test.cpp @@ -1,13 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("enumstore_test"); #include <vespa/vespalib/testkit/testapp.h> -//#define LOG_ENUM_STORE #include <vespa/searchlib/attribute/enumstore.hpp> #include <limits> #include <string> #include <iostream> +#include <vespa/log/log.h> +LOG_SETUP("enumstore_test"); + namespace search { size_t enumStoreAlign(size_t size) diff --git a/searchlib/src/vespa/searchlib/features/utils.cpp b/searchlib/src/vespa/searchlib/features/utils.cpp index 3f68e69ff25..6270ff2bb39 100644 --- a/searchlib/src/vespa/searchlib/features/utils.cpp +++ b/searchlib/src/vespa/searchlib/features/utils.cpp @@ -1,28 +1,43 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "utils.hpp" +#include <charconv> namespace search::features::util { +template <typename T> +T strToInt(vespalib::stringref str) +{ + T retval = 0; + if ((str.size() > 2) && (str[0] == '0') && ((str[0] | 0x20) == 'x')) { + std::from_chars(str.data(), str.data()+str.size(), retval, 16); + } else { + std::from_chars(str.data(), str.data()+str.size(), retval, 10); + } + + return retval; +} + template <> uint8_t strToNum<uint8_t>(vespalib::stringref str) { - return strToNum<uint16_t>(str); + return strToInt<uint16_t>(str); } template <> int8_t strToNum<int8_t>(vespalib::stringref str) { - return strToNum<int16_t>(str); + return strToInt<int16_t>(str); } template double strToNum<double>(vespalib::stringref str); template float strToNum<float>(vespalib::stringref str); -template uint16_t strToNum<uint16_t>(vespalib::stringref str); -template uint32_t strToNum<uint32_t>(vespalib::stringref str); -template uint64_t strToNum<uint64_t>(vespalib::stringref str); -template int16_t strToNum<int16_t>(vespalib::stringref str); -template int32_t strToNum<int32_t>(vespalib::stringref str); -template int64_t strToNum<int64_t>(vespalib::stringref str); + +template <> uint16_t strToNum<uint16_t>(vespalib::stringref str) { return strToInt<uint16_t>(str); } +template <> uint32_t strToNum<uint32_t>(vespalib::stringref str) { return strToInt<uint32_t>(str); } +template <> uint64_t strToNum<uint64_t>(vespalib::stringref str) { return strToInt<uint64_t>(str); } +template <> int16_t strToNum<int16_t>(vespalib::stringref str) { return strToInt<int16_t>(str); } +template <> int32_t strToNum<int32_t>(vespalib::stringref str) { return strToInt<int32_t>(str); } +template <> int64_t strToNum<int64_t>(vespalib::stringref str) { return strToInt<int64_t>(str); } } |