23#ifndef GUL17_TO_NUMBER_H_ 
   24#define GUL17_TO_NUMBER_H_ 
   50constexpr inline bool is_digit(
char c) 
noexcept 
   52    return c >= 
'0' && 
c <= 
'9';
 
   57    if (
c >= 
'0' && 
c <= 
'9')
 
   59    if (
c >= 
'a' && 
c <= 
'z')
 
   61    if (
c >= 
'A' && 
c <= 
'Z')
 
   68template <
typename NumberType, 
bool count_magnitude = false>
 
  123        str.remove_prefix(1);
 
  126        str.remove_prefix(1);
 
  149template <
typename NumberType>
 
  151    typename std::conditional<
 
  152        (std::numeric_limits<std::uint64_t>::digits10 >= std::numeric_limits<NumberType>::digits10),
 
  177template <
typename NumberType>
 
  178constexpr inline std::optional<NumberType> 
to_normalized_float(std::string_view 
i1, std::string_view 
i2) 
noexcept 
  180    static_assert(std::numeric_limits<FloatConversionIntType<NumberType>>
::digits10 
  181            >= std::numeric_limits<NumberType>::digits10,
 
  182            "FloatConversionIntType is too small for NumberType");
 
  184    i1 = 
i1.substr(0, std::min(
i1.length(),
 
  186    i2 = 
i2.substr(0, std::min(
i2.length(),
 
  193    if (
not i2.empty()) {
 
  195        if (
not f2.has_value())
 
  199    if (
not i1.empty()) {
 
  202        if (
not f1.has_value())
 
  210template <
typename NumberType>
 
  213    std::optional<NumberType> result;
 
  235template <
typename NumberType>
 
  244            return { 
true, std::make_optional(std::numeric_limits<NumberType>::infinity()) };
 
  247            return { 
true, std::make_optional(std::numeric_limits<NumberType>::infinity()) };
 
  253            return { 
true, std::make_optional(std::numeric_limits<NumberType>::quiet_NaN()) };
 
  256        str.remove_prefix(4);
 
  257        str.remove_suffix(1);
 
  258        while (
str.length()) {
 
  261            str.remove_prefix(1);
 
  264        return { 
true, std::make_optional(std::numeric_limits<NumberType>::quiet_NaN()) };
 
  266    return { 
false, {} };
 
  300template <
typename NumberType>
 
  308    auto e_pos = 
str.find_first_of(
"eE");
 
  309    if (
e_pos != std::string_view::npos)
 
  365    using CalcType = std::conditional_t<
 
  366        std::greater<>()(
sizeof(
NumberType), 
sizeof(
double)),
 
  393template <
typename NumberType>
 
  409    catch (
const std::exception &)
 
  496template <
typename NumberType>
 
  497constexpr inline std::enable_if_t<std::is_integral<NumberType>::value 
and 
  498                                  std::is_unsigned<NumberType>::value,
 
  499                                  std::optional<NumberType>>
 
  502    return detail::to_unsigned_integer<NumberType>(
str);
 
 
  506template <
typename NumberType>
 
  507constexpr inline std::enable_if_t<std::is_integral<NumberType>::value 
and 
  508                                  std::is_signed<NumberType>::value,
 
  509                                  std::optional<NumberType>>
 
  515    if (
str.front() == 
'-')
 
  517        using UnsignedT = std::make_unsigned_t<NumberType>;
 
  519            static_cast<UnsignedT>(std::numeric_limits<NumberType>::max()) + 1;
 
  521        str.remove_prefix(1);
 
  523        auto result = detail::to_unsigned_integer<UnsignedT>(
str);
 
  528            return std::numeric_limits<NumberType>::lowest();
 
  535    return detail::to_unsigned_integer<NumberType>(
str);
 
  539template <
typename NumberType>
 
  540constexpr inline std::enable_if_t<std::is_floating_point<NumberType>::value,
 
  541                                  std::optional<NumberType>>
 
  555#    pragma warning( pop ) 
  560        return detail::strtold_wrapper<NumberType>(
str);
 
  563    if (
str.front() == 
'-')
 
  565        str.remove_prefix(1);
 
  566        auto result = detail::to_unsigned_float<NumberType>(
str);
 
  572    return detail::to_unsigned_float<NumberType>(
str);
 
  577constexpr inline std::optional<bool> to_number<bool>(std::string_view 
str) 
noexcept 
  579    if (
str.length() == 1) {
 
auto constexpr bit_set(unsigned bit) noexcept -> ReturnT
Set a bit in an integral type.
Definition bit_manip.h:121
 
constexpr bool equals_nocase(std::string_view str1, std::string_view str2) noexcept
Determine whether a string is equal to another one, making no distinction between upper and lower cas...
Definition substring_checks.h:166
 
constexpr bool starts_with_nocase(std::string_view str, std::string_view prefix) noexcept
Determine whether a string starts with another string.
Definition substring_checks.h:314
 
constexpr std::enable_if_t< std::is_integral< NumberType >::value and std::is_unsigned< NumberType >::value, std::optional< NumberType > > to_number(std::string_view str) noexcept
Convert an ASCII std::string_view into a number.
Definition to_number.h:500
 
Definition of macros used internally by GUL.
 
Namespace gul17 contains all functions and classes of the General Utility Library.
Definition doxygen.h:26
 
Definition of contains(), ends_with(), and starts_with().