MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / parse

Function parse

src/openrct2/core/String.hpp:135–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133
134 template<typename T>
135 inline T parse(std::string_view input)
136 {
137 static_assert(!std::is_same_v<T, float> && !std::is_same_v<T, double>, "Float support is currently unsupported");
138
139 if (input.empty())
140 {
141 throw std::invalid_argument("Input is empty");
142 }
143 T result;
144 auto [ptr, ec] = std::from_chars(input.data(), input.data() + input.size(), result);
145 if (ec == std::errc::invalid_argument)
146 {
147 throw std::invalid_argument("Invalid argument in conversion");
148 }
149 if (ec == std::errc::result_out_of_range)
150 {
151 throw std::out_of_range("Result out of range");
152 }
153 if (ec != std::errc())
154 {
155 throw std::runtime_error("Conversion error");
156 }
157 if (ptr != input.data() + input.size())
158 {
159 throw std::invalid_argument("Trailing characters after number");
160 }
161 return result;
162 }
163
164 /**
165 * Returns string representation of a hexadecimal input, such as SHA256 hash

Callers 3

ReadFromFileFunction · 0.85
FromStringFunction · 0.85
FromVectorFunction · 0.85

Calls 3

emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected