bool _STLP_CALL __copy_grouped_digits(_InputIter& __first, _InputIter __last, __iostring& __v, const _CharT * __digits, _CharT __sep, const string& __grouping, bool& __grouping_ok) { bool __ok = false; char __group_sizes[64]; char*__group_sizes_end = __group_sizes; char __current_group_size = 0; for ( ; __first != __last; ++__first) { _CharT __c = *__first; bool __tmp = __get_fdigit_or_sep(__c, __sep, __digits); if (__tmp) { if (__c == ',') { *__group_sizes_end++ = __current_group_size; __current_group_size = 0; } else { __ok = true; __v.push_back((char)__c); ++__current_group_size; } } else break; } if (__group_sizes_end != __group_sizes) *__group_sizes_end++ = __current_group_size; __grouping_ok = __valid_grouping(__group_sizes, __group_sizes_end, __grouping.data(), __grouping.data() + __grouping.size()); return __ok; }
bool _STLP_CALL __get_integer(_InputIter& __first, _InputIter& __last, int __base, _Integer& __val, int __got, bool __is_negative, _CharT __separator, const string& __grouping, const __false_type& /*_IsSigned*/) { bool __ovflow = false; _Integer __result = 0; bool __is_group = !__grouping.empty(); char __group_sizes[64]; char __current_group_size = 0; char* __group_sizes_end = __group_sizes; _Integer __over_base = (numeric_limits<_Integer>::max)() / __STATIC_CAST(_Integer, __base); for ( ; __first != __last ; ++__first) { const _CharT __c = *__first; if (__is_group && __c == __separator) { *__group_sizes_end++ = __current_group_size; __current_group_size = 0; continue; } int __n = __get_digit_from_table(__c); if (__n >= __base) break; ++__got; ++__current_group_size; if (__result > __over_base) __ovflow = true; //don't need to keep accumulating else { _Integer __next = __STATIC_CAST(_Integer, __base * __result + __n); if (__result != 0) __ovflow = __ovflow || __next <= __result; __result = __next; } } if (__is_group && __group_sizes_end != __group_sizes) { *__group_sizes_end++ = __current_group_size; } // fbp : added to not modify value if nothing was read if (__got > 0) { __val = __ovflow ? (numeric_limits<_Integer>::max)() : (__is_negative ? __STATIC_CAST(_Integer, -__result) : __result); } // overflow is being treated as failure return ((__got > 0) && !__ovflow) && (__is_group == 0 || __valid_grouping(__group_sizes, __group_sizes_end, __grouping.data(), __grouping.data()+ __grouping.size())); }
bool __get_monetary_value(_InIt& __first, _InIt __last, _OuIt __out_ite, const ctype<_CharT>& _c_type, _CharT __point, int __frac_digits, _CharT __sep, const string& __grouping, bool &__syntax_ok) { if (__first == __last || !_c_type.is(ctype_base::digit, *__first)) return false; char __group_sizes[128]; char* __group_sizes_end = __grouping.empty()? 0 : __group_sizes; char __current_group_size = 0; while (__first != __last) { if (_c_type.is(ctype_base::digit, *__first)) { ++__current_group_size; *__out_ite++ = *__first++; } else if (__group_sizes_end) { if (*__first == __sep) { *__group_sizes_end++ = __current_group_size; __current_group_size = 0; ++__first; } else break; } else break; } if (__grouping.empty()) __syntax_ok = true; else { if (__group_sizes_end != __group_sizes) *__group_sizes_end++ = __current_group_size; __syntax_ok = __valid_grouping(__group_sizes, __group_sizes_end, __grouping.data(), __grouping.data()+ __grouping.size()); if (__first == __last || *__first != __point) { for (int __digits = 0; __digits != __frac_digits; ++__digits) *__out_ite++ = _CharT('0'); return true; // OK not to have decimal point } } ++__first; int __digits = 0; while (__first != __last && _c_type.is(ctype_base::digit, *__first)) { *__out_ite++ = *__first++; ++__digits; } __syntax_ok = __syntax_ok && (__digits == __frac_digits); return true; }