AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Impl::StringConvertImpl::For< T, std::enable_if_t< std::is_floating_point_v< T > > > Struct Template Reference

#include "StringConvert.h"

Static Public Member Functions

static Optional< T > FromString (std::string_view str, std::chars_format fmt=std::chars_format())
 
static Optional< T > FromString (std::string_view str, int base)
 
static std::string ToString (T val)
 

Detailed Description

template<typename T>
struct Acore::Impl::StringConvertImpl::For< T, std::enable_if_t< std::is_floating_point_v< T > > >

Member Function Documentation

◆ FromString() [1/2]

template<typename T >
static Optional< T > Acore::Impl::StringConvertImpl::For< T, std::enable_if_t< std::is_floating_point_v< T > > >::FromString ( std::string_view  str,
int  base 
)
inlinestatic
176 {
177 if (base == 16)
178 {
179 return FromString(str, std::chars_format::hex);
180 }
181 else if (base == 10)
182 {
183 return FromString(str, std::chars_format::general);
184 }
185 else
186 {
187 return FromString(str, std::chars_format());
188 }
189 }
static Optional< T > FromString(std::string_view str, std::chars_format fmt=std::chars_format())
Definition: StringConvert.h:134

◆ FromString() [2/2]

template<typename T >
static Optional< T > Acore::Impl::StringConvertImpl::For< T, std::enable_if_t< std::is_floating_point_v< T > > >::FromString ( std::string_view  str,
std::chars_format  fmt = std::chars_format() 
)
inlinestatic
135 {
136 if (str.empty())
137 {
138 return std::nullopt;
139 }
140
141 if (fmt == std::chars_format())
142 {
143 if (StringEqualI(str.substr(0, 2), "0x"))
144 {
145 fmt = std::chars_format::hex;
146 str.remove_prefix(2);
147 }
148 else
149 {
150 fmt = std::chars_format::general;
151 }
152
153 if (str.empty())
154 {
155 return std::nullopt;
156 }
157 }
158
159 char const* const start = str.data();
160 char const* const end = (start + str.length());
161
162 T val;
163 std::from_chars_result const res = std::from_chars(start, end, val, fmt);
164 if ((res.ptr == end) && (res.ec == std::errc()))
165 {
166 return val;
167 }
168 else
169 {
170 return std::nullopt;
171 }
172 }
bool StringEqualI(std::string_view a, std::string_view b)
Definition: Util.cpp:592

References StringEqualI().

◆ ToString()

template<typename T >
static std::string Acore::Impl::StringConvertImpl::For< T, std::enable_if_t< std::is_floating_point_v< T > > >::ToString ( val)
inlinestatic
192 {
193 return std::to_string(val);
194 }