📄 _monetary.c
字号:
/* * Copyright (c) 1999 * Silicon Graphics Computer Systems, Inc. * * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * */#ifndef _STLP_MONETARY_C#define _STLP_MONETARY_C# ifndef _STLP_INTERNAL_MONETARY_H# include <stl/_monetary.h># endif#ifndef _STLP_INTERNAL_IOS_H# include <stl/_ios.h>#endif#ifndef _STLP_INTERNAL_NUM_PUT_H# include <stl/_num_put.h>#endif#ifndef _STLP_INTERNAL_NUM_GET_H# include <stl/_num_get.h>#endif_STLP_BEGIN_NAMESPACE#if (_STLP_STATIC_TEMPLATE_DATA > 0)# if !defined (__BORLANDC__)template <class _CharT, class _InputIterator>locale::id money_get<_CharT, _InputIterator>::id;template <class _CharT, class _OutputIterator>locale::id money_put<_CharT, _OutputIterator>::id;# endif# if (defined (__CYGWIN__) || defined (__MINGW32__)) && \ defined (_STLP_USE_DYNAMIC_LIB) && !defined (__BUILDING_STLPORT)/* * Under cygwin, when STLport is used as a shared library, the id needs * to be specified as imported otherwise they will be duplicated in the * calling executable. */template <>_STLP_DECLSPEC locale::id money_get<char, istreambuf_iterator<char, char_traits<char> > >::id;/*template <>_STLP_DECLSPEC locale::id money_get<char, const char*>::id;*/template <>_STLP_DECLSPEC locale::id money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;template <>_STLP_DECLSPEC locale::id money_put<char, char*>::id;# if !defined (_STLP_NO_WCHAR_T)template <>_STLP_DECLSPEC locale::id money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;template <>_STLP_DECLSPEC locale::id money_get<wchar_t, const wchar_t*>::id;template <>_STLP_DECLSPEC locale::id money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;template <>_STLP_DECLSPEC locale::id money_put<wchar_t, wchar_t*>::id;# endif# endif#else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) *///typedef money_get<char, const char*> money_get_char;//typedef money_put<char, char*> money_put_char;typedef money_get<char, istreambuf_iterator<char, char_traits<char> > > money_get_char_2;typedef money_put<char, ostreambuf_iterator<char, char_traits<char> > > money_put_char_2;//__DECLARE_INSTANCE(locale::id, money_get_char::id, );//__DECLARE_INSTANCE(locale::id, money_put_char::id, );__DECLARE_INSTANCE(locale::id, money_get_char_2::id, );__DECLARE_INSTANCE(locale::id, money_put_char_2::id, );# ifndef _STLP_NO_WCHAR_T//typedef money_get<wchar_t, const wchar_t*> money_get_wchar_t;//typedef money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > money_get_wchar_t_2;typedef money_put<wchar_t, wchar_t*> money_put_wchar_t;typedef money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > money_put_wchar_t_2;//__DECLARE_INSTANCE(locale::id, money_get_wchar_t::id, );//__DECLARE_INSTANCE(locale::id, money_put_wchar_t::id, );__DECLARE_INSTANCE(locale::id, money_get_wchar_t_2::id, );__DECLARE_INSTANCE(locale::id, money_put_wchar_t_2::id, );# endif#endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */// money_get facets_STLP_MOVE_TO_PRIV_NAMESPACE// helper functions for do_gettemplate <class _InIt1, class _InIt2>pair<_InIt1, bool> __get_string( _InIt1 __first, _InIt1 __last, _InIt2 __str_first, _InIt2 __str_last) { while ( __first != __last && __str_first != __str_last && *__first == *__str_first ) { ++__first; ++__str_first; } return make_pair(__first, __str_first == __str_last);}template <class _InIt, class _OuIt, class _CharT>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;}template <class _CharT, class _InputIter, class _StrType>_InputIter __money_do_get(_InputIter __s, _InputIter __end, bool __intl, ios_base& __str, ios_base::iostate& __err, _StrType& __digits, bool &__is_positive, _CharT* /*__dummy*/) { if (__s == __end) { __err |= ios_base::eofbit; return __s; } typedef _CharT char_type; typedef _StrType string_type; typedef _InputIter iter_type; typedef moneypunct<char_type, false> _Punct; typedef moneypunct<char_type, true> _Punct_intl; typedef ctype<char_type> _Ctype; locale __loc = __str.getloc(); const _Punct& __punct = use_facet<_Punct>(__loc) ; const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ; const _Ctype& __c_type = use_facet<_Ctype>(__loc) ; money_base::pattern __format = __intl ? __punct_intl.neg_format() : __punct.neg_format(); string_type __ns = __intl ? __punct_intl.negative_sign() : __punct.negative_sign(); string_type __ps = __intl ? __punct_intl.positive_sign() : __punct.positive_sign(); int __i; bool __symbol_required = (__str.flags() & ios_base::showbase) != 0; string_type __buf; back_insert_iterator<string_type> __out_ite(__buf); for (__i = 0; __i < 4; ++__i) { switch (__format.field[__i]) { case money_base::none: if (__i == 3) { if (__c_type.is(ctype_base::space, *__s)) { __err = ios_base::failbit; return __s; } break; } while (__s != __end && __c_type.is(ctype_base::space, *__s)) ++__s; break; case money_base::space: if (!__c_type.is(ctype_base::space, *__s)) { __err = ios_base::failbit; return __s; } ++__s; while (__s != __end && __c_type.is(ctype_base::space, *__s)) ++__s; break; case money_base::symbol: { string_type __curs = __intl ? __punct_intl.curr_symbol() : __punct.curr_symbol(); pair<iter_type, bool> __result = __get_string(__s, __end, __curs.begin(), __curs.end()); if (!__result.second && __symbol_required) __err = ios_base::failbit; __s = __result.first; break; } case money_base::sign: { if (__s == __end) { if (__ps.empty()) break; if (__ns.empty()) { __is_positive = false; break; } __err = ios_base::failbit; return __s; } else { if (__ps.empty()) { if (__ns.empty()) break; if (*__s == __ns[0]) { ++__s; __is_positive = false; } break; } else { if (*__s == __ps[0]) { ++__s; break; } if (__ns.empty()) break; if (*__s == __ns[0]) { ++__s; __is_positive = false; break; } __err = ios_base::failbit; } } return __s; } case money_base::value: { char_type __point = __intl ? __punct_intl.decimal_point() : __punct.decimal_point(); int __frac_digits = __intl ? __punct_intl.frac_digits() : __punct.frac_digits(); string __grouping = __intl ? __punct_intl.grouping() : __punct.grouping(); bool __syntax_ok = true; bool __result; char_type __sep = __grouping.empty() ? char_type() : __intl ? __punct_intl.thousands_sep() : __punct.thousands_sep(); __result = __get_monetary_value(__s, __end, __out_ite, __c_type, __point, __frac_digits, __sep,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -