#include <array>
#include <iomanip>
#include <limits>
#include <locale>
#include <sstream>
#include <string>
#include <string_view>
Go to the source code of this file.
|
| namespace | a_util |
| | Serves as the root component, with common functionality documented in core functionality.
|
| |
| namespace | a_util::strings |
| | Serves as component for string handling and conversion functionality.
|
| |
|
| enum class | float_format { general = 0
, scientific = 1
, fixed = 2
, hex = 3
} |
| |
|
|
const std::locale & | a_util::strings::conversion::detail::get_c_locale () |
| |
|
template<typename T> |
| std::string | a_util::strings::conversion::detail::float_to_string (T value, float_format format) |
| |
|
template<typename T> |
| T | a_util::strings::conversion::detail::string_to_float (std::string_view value) |
| |
|
std::pair< int, size_t > | a_util::strings::conversion::detail::get_base (std::string_view value) |
| |
|
template<typename T> |
| std::string | a_util::strings::conversion::to_string (T value, float_format=float_format::fixed) |
| |
|
template<> |
| std::string | a_util::strings::conversion::to_string (float value, float_format format) |
| |
|
template<> |
| std::string | a_util::strings::conversion::to_string (double value, float_format format) |
| |
| template<typename T> |
| T | a_util::strings::conversion::to_number (std::string_view value, int base=0) |
| |
|
template<> |
| float | a_util::strings::conversion::to_number (std::string_view value, int) |
| |
|
template<> |
| double | a_util::strings::conversion::to_number (std::string_view value, int) |
| |
Common include for string conversion functions
- Copyright
Copyright 2025 Digitalwerk GmbH.
This Source Code Form is subject to the terms of the Mozilla
Public License, v. 2.0. If a copy of the MPL was not distributed
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
◆ to_number()
template<typename T>
| T a_util::strings::conversion::to_number |
( |
std::string_view | value, |
|
|
int | base = 0 ) |
|
inline |
Convert a string representation of an integer to a numeric value of type T.
Supports an optional leading sign ('+' or '-') as well as the base prefixes "0x"/"0X" (hexadecimal), "0b"/"0B" (binary) and a leading '0' (octal). A negative value is only accepted when T is a signed type; the most negative value (e.g. "-0x80" for int8_t) is representable.
- Template Parameters
-
| T | The numeric type the string gets converted to. |
- Parameters
-
| [in] | value | String to convert. |
| [in] | base | Numeric base to use. When 0 (the default), the base is auto-detected from the prefix (see above), otherwise value is parsed using the given base. |
- Warning
- When an explicit
base (non-zero) is passed together with a prefixed value (e.g. "0x" or "0b"), the behavior is undefined: the prefix is not stripped and the result depends on the underlying conversion backend.
- Returns
- Numeric value parsed from
value.
- Exceptions
-
| std::out_of_range | If the parsed value does not fit into the numeric limits of T. |
| std::runtime_error | If value is not a valid number, contains trailing characters, or carries a negative sign while T is an unsigned type. |