| 5163 | /// @return true if the conversion completes successfully, false otherwise. |
| 5164 | template <typename CharItr, typename IntType> |
| 5165 | inline bool atoi(CharItr begin, CharItr end, IntType& i) noexcept { |
| 5166 | static_assert(is_iterator_of<CharItr, char>::value, "atoi() accepts iterators for char type"); |
| 5167 | static_assert(is_non_bool_integral<IntType>::value, "atoi() accepts non-boolean integral types as an output type"); |
| 5168 | |
| 5169 | if FK_YAML_UNLIKELY (begin == end) { |
| 5170 | return false; |
| 5171 | } |
| 5172 | |
| 5173 | const auto len = static_cast<uint32_t>(std::distance(begin, end)); |
| 5174 | const char* p_begin = &*begin; |
| 5175 | const char* p_end = p_begin + len; |
| 5176 | |
| 5177 | const char first = *begin; |
| 5178 | if (first == '+') { |
| 5179 | return atoi_dec_pos(p_begin + 1, p_end, i); |
| 5180 | } |
| 5181 | |
| 5182 | if (first == '-') { |
| 5183 | if (!std::numeric_limits<IntType>::is_signed) { |
| 5184 | return false; |
| 5185 | } |
| 5186 | |
| 5187 | const bool success = atoi_dec_neg(p_begin + 1, p_end, i); |
| 5188 | if (success) { |
| 5189 | i *= static_cast<IntType>(-1); |
| 5190 | } |
| 5191 | |
| 5192 | return success; |
| 5193 | } |
| 5194 | |
| 5195 | if (first != '0') { |
| 5196 | return atoi_dec_pos(p_begin, p_end, i); |
| 5197 | } |
| 5198 | |
| 5199 | if (p_begin + 1 != p_end) { |
| 5200 | switch (*(p_begin + 1)) { |
| 5201 | case 'o': |
| 5202 | return atoi_oct(p_begin + 2, p_end, i); |
| 5203 | case 'x': |
| 5204 | return atoi_hex(p_begin + 2, p_end, i); |
| 5205 | default: |
| 5206 | // The YAML spec doesn't allow decimals starting with 0. |
| 5207 | return false; |
| 5208 | } |
| 5209 | } |
| 5210 | |
| 5211 | i = 0; |
| 5212 | return true; |
| 5213 | } |
| 5214 | |
| 5215 | /////////////////////////// |
| 5216 | // scalar <--> float // |