38 #ifndef vtkStringScanner_h
39 #define vtkStringScanner_h
41 #include "vtkCharConvCompatibility.h"
42 #include "vtkCommonCoreModule.h"
45 #include "vtkfast_float.h"
49 #include VTK_SCN(scn/chrono.h) // For scn's chrono
50 #include VTK_SCN(scn/scan.h) // For scn's scan
54 #include <string_view>
58 VTK_ABI_NAMESPACE_BEGIN
68 std::chars_format format = std::chars_format::general) -> std::from_chars_result
70 static constexpr std::array<fast_float::chars_format, 5> std_to_fast_float_chars_format = { {
71 fast_float::chars_format::general,
72 fast_float::chars_format::scientific,
73 fast_float::chars_format::fixed,
74 fast_float::chars_format::general,
75 fast_float::chars_format::hex,
77 auto result = fast_float::from_chars<T>(first, last,
value,
78 std_to_fast_float_chars_format[
static_cast<std::underlying_type_t<std::chars_format>
>(format)]);
79 return { result.ptr, result.ec };
84 const char* first,
const char* last, T& value,
int base = 10) -> std::from_chars_result
86 auto result = fast_float::from_chars<T>(first, last,
value, base);
87 return { result.ptr, result.ec };
98 VTK_ALWAYS_INLINE
auto from_chars(
const std::string_view str, T& value,
99 std::chars_format format = std::chars_format::general) -> std::from_chars_result
101 return vtk::from_chars<T>(str.data(), str.data() + str.size(),
value, format);
103 template <
typename T,
106 const std::string_view str, T& value,
int base = 10) -> std::from_chars_result
108 return vtk::from_chars<T>(str.data(), str.data() + str.size(),
value, base);
113 #define VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND(from_chars_result, value, command) \
116 switch (from_chars_result.ec) \
118 case std::errc::invalid_argument: \
120 vtkLogF(ERROR, "The given argument was invalid, failed to get the converted " #value "."); \
123 case std::errc::result_out_of_range: \
125 vtkLogF(ERROR, "The result is out of range, failed to get the converted " #value "."); \
134 #define VTK_FROM_CHARS_RESULT_IF_ERROR_BREAK(from_chars_result, value) \
135 VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND(from_chars_result, value, break)
137 #define VTK_FROM_CHARS_RESULT_IF_ERROR_RETURN(from_chars_result, value, returnValue) \
138 VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND(from_chars_result, value, return returnValue)
141 #define VTK_FROM_CHARS_CONCAT_INNER(a, b) a##b
142 #define VTK_FROM_CHARS_CONCAT(a, b) VTK_FROM_CHARS_CONCAT_INNER(a, b)
145 #define VTK_FROM_CHARS_IF_ERROR_COMMAND(string, value, command) \
146 auto VTK_FROM_CHARS_CONCAT(_from_chars_result_, __LINE__) = vtk::from_chars(string, value); \
147 VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND( \
148 VTK_FROM_CHARS_CONCAT(_from_chars_result_, __LINE__), value, command)
150 #define VTK_FROM_CHARS_IF_ERROR_BREAK(string, value) \
151 VTK_FROM_CHARS_IF_ERROR_COMMAND(string, value, break)
153 #define VTK_FROM_CHARS_IF_ERROR_RETURN(string, value, returnValue) \
154 VTK_FROM_CHARS_IF_ERROR_COMMAND(string, value, return returnValue)
157 #define VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND(string, value, param, command) \
158 auto VTK_FROM_CHARS_CONCAT(_from_chars_result_, __LINE__) = \
159 vtk::from_chars(string, value, param); \
160 VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND( \
161 VTK_FROM_CHARS_CONCAT(_from_chars_result_, __LINE__), value, command)
163 #define VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_BREAK(string, value, param) \
164 VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND(string, value, param, break)
166 #define VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_RETURN(string, value, param, returnValue) \
167 VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND(string, value, param, return returnValue)
172 using scn::scan_result_type;
179 using scn::runtime_format;
188 using scn::scan_value;
206 VTK_ABI_NAMESPACE_END
209 #endif // vtkStringScanner_h
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
VTK_ALWAYS_INLINE auto from_chars(const char *first, const char *last, T &value, std::chars_format format=std::chars_format::general) -> std::from_chars_result
Given a char* first and char* last, convert it to a number, and return a from_chars_result;.