|
MXL : Media eXchange Layer
MXL
|
#include <cstdint>#include <stdexcept>#include <catch2/catch_test_macros.hpp>#include "mxl-internal/JsonUtils.hpp"#include "mxl-internal/StringUtils.hpp"
Go to the source code of this file.
Functions | |
| template<std::integral T> | |
| T | jsonStringToInteger (picojson::value const &value, std::string_view name) |
| template<std::integral T> | |
| T | stringToInteger (std::string_view text, std::string_view name) |
| TEST_CASE ("jsonStringToInteger : requires a JSON string", "[string]") | |
| TEST_CASE ("stringToInteger : converts decimal numbers in range", "[string]") | |
| TEST_CASE ("stringToInteger : rejects what std::stoull accepts", "[string]") | |
|
inline |
Convert a JSON string holding a decimal number to the integer type T.
Use this for values such as memory addresses and keys, which are stored as strings because a JSON number is a double and cannot hold every 64-bit integer exactly.
| value | The JSON value. |
| name | The field name, used in the error message. |
| std::invalid_argument | If the value is not a string, or not a decimal number in the range of T. |
Definition at line 270 of file JsonUtils.hpp.
| T mxl::lib::stringToInteger | ( | std::string_view | text, |
| std::string_view | name ) |
Convert a decimal string to the integer type T.
| text | The string to convert. |
| name | The field name, used in the error message. |
| std::invalid_argument | If the string is not a decimal number in the range of T. |
Definition at line 24 of file StringUtils.hpp.
| TEST_CASE | ( | "jsonStringToInteger : requires a JSON string" | , |
| "" | [string] ) |
Definition at line 32 of file test_stringutils.cpp.
| TEST_CASE | ( | "stringToInteger : converts decimal numbers in range" | , |
| "" | [string] ) |
Definition at line 13 of file test_stringutils.cpp.
| TEST_CASE | ( | "stringToInteger : rejects what std::stoull accepts" | , |
| "" | [string] ) |
Definition at line 21 of file test_stringutils.cpp.