3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
19 #include "stlport_prefix.h"
26 // Note that grouping[0] is the number of digits in the *rightmost* group.
27 // We assume, without checking, that *last is null and that there is enough
28 // space in the buffer to extend the number past [first, last).
31 __insert_grouping_aux(Char* first, Char* last, const string& grouping,
32 Char separator, Char Plus, Char Minus,
34 typedef string::size_type str_size;
41 if (*first == Plus || *first == Minus) {
47 str_size n = 0; // Index of the current group.
48 Char* cur_group = last; // Points immediately beyond the rightmost
49 // digit of the current group.
50 int groupsize = 0; // Size of the current group.
53 groupsize = n < grouping.size() ? grouping[n] : groupsize;
56 if (groupsize <= 0 || groupsize >= cur_group - first)
59 // Insert a separator character just before position cur_group - groupsize
60 cur_group -= groupsize;
62 copy_backward(cur_group, last, last + 1);
63 *cur_group = separator;
66 return (last - first) + sign + basechars;
69 //Dynamic output buffer version.
70 template <class Char, class Str>
72 __insert_grouping_aux( /* __basic_iostring<Char> */ Str& iostr, size_t __group_pos,
73 const string& grouping,
74 Char separator, Char Plus, Char Minus,
76 typedef string::size_type str_size;
78 if (iostr.size() < __group_pos)
81 size_t __first_pos = 0;
82 Char __first = *iostr.begin();
84 if (__first == Plus || __first == Minus) {
88 __first_pos += basechars;
89 str_size n = 0; // Index of the current group.
90 typename basic_string<Char>::iterator cur_group(iostr.begin() + __group_pos); // Points immediately beyond the rightmost
91 // digit of the current group.
92 unsigned int groupsize = 0; // Size of the current group.
95 groupsize = n < grouping.size() ? grouping[n] : groupsize;
98 if (groupsize <= 0 || groupsize >= ((cur_group - iostr.begin()) + __first_pos))
101 // Insert a separator character just before position cur_group - groupsize
102 cur_group -= groupsize;
103 cur_group = iostr.insert(cur_group, separator);
107 //----------------------------------------------------------------------
110 _STLP_MOVE_TO_PRIV_NAMESPACE
112 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo()
113 { return "0123456789abcdefx"; }
115 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi()
116 { return "0123456789ABCDEFX"; }
119 __write_integer(char* buf, ios_base::fmtflags flags, long x) {
121 char* bufend = tmp+64;
122 char* beg = __write_integer_backward(bufend, flags, x);
123 return copy(beg, bufend, buf);
126 ///-------------------------------------
129 __insert_grouping(char * first, char * last, const string& grouping,
130 char separator, char Plus, char Minus, int basechars) {
131 return __insert_grouping_aux(first, last, grouping,
132 separator, Plus, Minus, basechars);
136 __insert_grouping(__iostring &str, size_t group_pos, const string& grouping,
137 char separator, char Plus, char Minus, int basechars) {
138 __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars);
141 #if !defined (_STLP_NO_WCHAR_T)
143 __insert_grouping(wchar_t* first, wchar_t* last, const string& grouping,
144 wchar_t separator, wchar_t Plus, wchar_t Minus,
146 return __insert_grouping_aux(first, last, grouping, separator,
147 Plus, Minus, basechars);
151 __insert_grouping(__iowstring &str, size_t group_pos, const string& grouping,
152 wchar_t separator, wchar_t Plus, wchar_t Minus,
154 __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars);
158 _STLP_MOVE_TO_STD_NAMESPACE
160 //----------------------------------------------------------------------
161 // Force instantiation of num_put<>
162 #if !defined(_STLP_NO_FORCE_INSTANTIATE)
163 template class _STLP_CLASS_DECLSPEC ostreambuf_iterator<char, char_traits<char> >;
164 // template class num_put<char, char*>;
165 template class num_put<char, ostreambuf_iterator<char, char_traits<char> > >;
166 # ifndef _STLP_NO_WCHAR_T
167 template class ostreambuf_iterator<wchar_t, char_traits<wchar_t> >;
168 template class num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
169 // template class num_put<wchar_t, wchar_t*>;
170 # endif /* INSTANTIATE_WIDE_STREAMS */