sl@0: /* sl@0: * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: * sl@0: * Copyright (c) 1999 sl@0: * Silicon Graphics Computer Systems, Inc. sl@0: * sl@0: * Copyright (c) 1999 sl@0: * Boris Fomitchev sl@0: * sl@0: * This material is provided "as is", with absolutely no warranty expressed sl@0: * or implied. Any use is at your own risk. sl@0: * sl@0: * Permission to use or copy this software for any purpose is hereby granted sl@0: * without fee, provided the above notices are retained on all copies. sl@0: * Permission to modify the code and to distribute modified code is granted, sl@0: * provided the above notices are retained, and a notice that the code was sl@0: * modified is included with the above copyright notice. sl@0: * sl@0: */ sl@0: sl@0: #include "stlport_prefix.h" sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __SYMBIAN32__WSD__ sl@0: #include sl@0: #endif //__SYMBIAN32__WSD__ sl@0: sl@0: _STLP_BEGIN_NAMESPACE sl@0: sl@0: // Note that grouping[0] is the number of digits in the *rightmost* group. sl@0: // We assume, without checking, that *last is null and that there is enough sl@0: // space in the buffer to extend the number past [first, last). sl@0: template sl@0: static ptrdiff_t sl@0: __insert_grouping_aux(Char* first, Char* last, const string& grouping, sl@0: Char separator, Char Plus, Char Minus, sl@0: int basechars) { sl@0: typedef string::size_type str_size; sl@0: sl@0: if (first == last) sl@0: return 0; sl@0: sl@0: int sign = 0; sl@0: sl@0: if (*first == Plus || *first == Minus) { sl@0: sign = 1; sl@0: ++first; sl@0: } sl@0: sl@0: first += basechars; sl@0: str_size n = 0; // Index of the current group. sl@0: Char* cur_group = last; // Points immediately beyond the rightmost sl@0: // digit of the current group. sl@0: int groupsize = 0; // Size of the current group. sl@0: sl@0: for (;;) { sl@0: groupsize = n < grouping.size() ? grouping[n] : groupsize; sl@0: ++n; sl@0: sl@0: if (groupsize <= 0 || groupsize >= cur_group - first) sl@0: break; sl@0: sl@0: // Insert a separator character just before position cur_group - groupsize sl@0: cur_group -= groupsize; sl@0: ++last; sl@0: copy_backward(cur_group, last, last + 1); sl@0: *cur_group = separator; sl@0: } sl@0: sl@0: return (last - first) + sign + basechars; sl@0: } sl@0: sl@0: //Dynamic output buffer version. sl@0: template sl@0: static void sl@0: __insert_grouping_aux( /* __basic_iostring */ Str& iostr, size_t __group_pos, sl@0: const string& grouping, sl@0: Char separator, Char Plus, Char Minus, sl@0: int basechars) { sl@0: typedef string::size_type str_size; sl@0: sl@0: if (iostr.size() < __group_pos) sl@0: return; sl@0: sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: int __first_pos = 0; sl@0: #else sl@0: size_t __first_pos = 0; sl@0: #endif sl@0: Char __first = *iostr.begin(); sl@0: sl@0: if (__first == Plus || __first == Minus) { sl@0: ++__first_pos; sl@0: } sl@0: sl@0: __first_pos += basechars; sl@0: #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT sl@0: typename basic_string::iterator cur_group(iostr.begin() + __group_pos); // Points immediately beyond the rightmost sl@0: // digit of the current group. sl@0: int groupsize = 0; // Size of the current group (if grouping.size() == 0, size sl@0: // of group unlimited: we force condition (groupsize <= 0)) sl@0: sl@0: for ( str_size n = 0; ; ) { // Index of the current group sl@0: if ( n < grouping.size() ) { sl@0: groupsize = __STATIC_CAST( int, grouping[n++] ); sl@0: } sl@0: sl@0: if ( (groupsize <= 0) || (groupsize >= ((cur_group - iostr.begin()) - __first_pos)) || sl@0: (groupsize == CHAR_MAX)) { sl@0: break; sl@0: } sl@0: #else sl@0: str_size n = 0; // Index of the current group. sl@0: typename basic_string::iterator cur_group(iostr.begin() + __group_pos); // Points immediately beyond the rightmost sl@0: // digit of the current group. sl@0: unsigned int groupsize = 0; // Size of the current group. sl@0: sl@0: for (;;) { sl@0: groupsize = n < grouping.size() ? grouping[n] : groupsize; sl@0: ++n; sl@0: sl@0: if (groupsize <= 0 || groupsize >= ((cur_group - iostr.begin()) + __first_pos)) sl@0: break; sl@0: #endif sl@0: sl@0: // Insert a separator character just before position cur_group - groupsize sl@0: cur_group -= groupsize; sl@0: cur_group = iostr.insert(cur_group, separator); sl@0: } sl@0: } sl@0: sl@0: //---------------------------------------------------------------------- sl@0: // num_put sl@0: sl@0: _STLP_MOVE_TO_PRIV_NAMESPACE sl@0: sl@0: _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo() sl@0: { return "0123456789abcdefx"; } sl@0: sl@0: _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi() sl@0: { return "0123456789ABCDEFX"; } sl@0: sl@0: char* _STLP_CALL sl@0: __write_integer(char* buf, ios_base::fmtflags flags, long x) { sl@0: char tmp[64]; sl@0: char* bufend = tmp+64; sl@0: char* beg = __write_integer_backward(bufend, flags, x); sl@0: return copy(beg, bufend, buf); sl@0: } sl@0: sl@0: ///------------------------------------- sl@0: sl@0: _STLP_DECLSPEC ptrdiff_t _STLP_CALL sl@0: __insert_grouping(char * first, char * last, const string& grouping, sl@0: char separator, char Plus, char Minus, int basechars) { sl@0: return __insert_grouping_aux(first, last, grouping, sl@0: separator, Plus, Minus, basechars); sl@0: } sl@0: sl@0: _STLP_DECLSPEC void _STLP_CALL sl@0: __insert_grouping(__iostring &str, size_t group_pos, const string& grouping, sl@0: char separator, char Plus, char Minus, int basechars) { sl@0: __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars); sl@0: } sl@0: sl@0: #if !defined (_STLP_NO_WCHAR_T) sl@0: _STLP_DECLSPEC ptrdiff_t _STLP_CALL sl@0: __insert_grouping(wchar_t* first, wchar_t* last, const string& grouping, sl@0: wchar_t separator, wchar_t Plus, wchar_t Minus, sl@0: int basechars) { sl@0: return __insert_grouping_aux(first, last, grouping, separator, sl@0: Plus, Minus, basechars); sl@0: } sl@0: sl@0: _STLP_DECLSPEC void _STLP_CALL sl@0: __insert_grouping(__iowstring &str, size_t group_pos, const string& grouping, sl@0: wchar_t separator, wchar_t Plus, wchar_t Minus, sl@0: int basechars) { sl@0: __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars); sl@0: } sl@0: #endif sl@0: sl@0: _STLP_MOVE_TO_STD_NAMESPACE sl@0: sl@0: #if defined (__SYMBIAN32__WSD__) sl@0: template <> sl@0: _STLP_DECLSPEC locale::id& num_put > >::GetFacetLocaleId() sl@0: { sl@0: return get_libcpp_wsd().num_put_char_ostreambuf_iterator_id; sl@0: } sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: template <> sl@0: _STLP_DECLSPEC locale::id& num_put > >::GetFacetLocaleId() sl@0: { sl@0: return get_libcpp_wsd().num_put_wchar_ostreambuf_iterator_id; sl@0: } sl@0: # endif /* _STLP_NO_WCHAR_T */ sl@0: #endif /* __SYMBIAN32__WSD__ */ sl@0: sl@0: //---------------------------------------------------------------------- sl@0: // Force instantiation of num_put<> sl@0: #if !defined(_STLP_NO_FORCE_INSTANTIATE) sl@0: template class _STLP_CLASS_DECLSPEC ostreambuf_iterator >; sl@0: // template class num_put; sl@0: template class num_put > >; sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: template class ostreambuf_iterator >; sl@0: template class num_put > >; sl@0: // template class num_put; sl@0: # endif /* INSTANTIATE_WIDE_STREAMS */ sl@0: #endif sl@0: sl@0: #if defined(__EPOC32__) sl@0: template <> sl@0: locale::id num_put > >::id={14}; sl@0: sl@0: # if !defined (_STLP_NO_WCHAR_T) sl@0: template <> sl@0: locale::id num_put > >::id={33}; sl@0: # endif sl@0: sl@0: #endif sl@0: sl@0: _STLP_END_NAMESPACE sl@0: sl@0: // Local Variables: sl@0: // mode:C++ sl@0: // End: