ext/include/iv/conversions.h in iv-phonic-0.0.6 vs ext/include/iv/conversions.h in iv-phonic-0.0.7
- old
+ new
@@ -250,11 +250,11 @@
if (pos == 0) {
// empty
return (parse_float && !is_found_zero) ? Conversions::kNaN : 0;
} else {
buffer[pos++] = '\0';
- return std::strtod(buffer.data(), NULL);
+ return std::atof(buffer.data());
}
} else {
return Conversions::kNaN;
}
}
@@ -419,17 +419,24 @@
return d;
}
return std::floor(std::abs(d)) * (std::signbit(d) ? -1 : 1);
}
-inline bool ConvertToUInt32(const UStringPiece& str, uint32_t* value) {
+template<typename Iter>
+inline bool ConvertToUInt32(Iter it, const Iter last, uint32_t* value) {
static const uint32_t uint32_t_max = std::numeric_limits<uint32_t>::max();
uint16_t ch;
*value = 0;
- UStringPiece::const_iterator it = str.begin();
- const UStringPiece::const_iterator last = str.end();
- if (it != last && *it != '0' && Chars::IsDecimalDigit(*it)) {
+ if (it != last && *it == '0') {
+ if (it + 1 != last) {
+ return false;
+ } else {
+ *value = 0;
+ return true;
+ }
+ }
+ if (it != last && Chars::IsDecimalDigit(*it)) {
ch = *it - '0';
*value = ch;
} else {
return false;
}
@@ -445,9 +452,17 @@
}
}
return (prev < (uint32_t_max / 10) ||
((prev == (uint32_t_max / 10)) &&
(ch < (uint32_t_max % 10))));
+}
+
+inline bool ConvertToUInt32(const UStringPiece& str, uint32_t* value) {
+ return ConvertToUInt32(str.begin(), str.end(), value);
+}
+
+inline bool ConvertToUInt32(const StringPiece& str, uint32_t* value) {
+ return ConvertToUInt32(str.begin(), str.end(), value);
}
template<typename T>
inline std::size_t DoubleToStringWithRadix(double v, int radix, T* buf) {
static const int kMaxBufSize = 1100;