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