|
1 /* |
|
2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
3 * |
|
4 * Copyright (c) 1999 |
|
5 * Silicon Graphics Computer Systems, Inc. |
|
6 * |
|
7 * Copyright (c) 1999 |
|
8 * Boris Fomitchev |
|
9 * |
|
10 * This material is provided "as is", with absolutely no warranty expressed |
|
11 * or implied. Any use is at your own risk. |
|
12 * |
|
13 * Permission to use or copy this software for any purpose is hereby granted |
|
14 * without fee, provided the above notices are retained on all copies. |
|
15 * Permission to modify the code and to distribute modified code is granted, |
|
16 * provided the above notices are retained, and a notice that the code was |
|
17 * modified is included with the above copyright notice. |
|
18 * |
|
19 */ |
|
20 |
|
21 #include "stlport_prefix.h" |
|
22 |
|
23 #include <locale> |
|
24 #include <ostream> |
|
25 |
|
26 #ifdef __SYMBIAN32__WSD__ |
|
27 #include <libstdcppwsd.h> |
|
28 #endif //__SYMBIAN32__WSD__ |
|
29 |
|
30 _STLP_BEGIN_NAMESPACE |
|
31 |
|
32 // Note that grouping[0] is the number of digits in the *rightmost* group. |
|
33 // We assume, without checking, that *last is null and that there is enough |
|
34 // space in the buffer to extend the number past [first, last). |
|
35 template <class Char> |
|
36 static ptrdiff_t |
|
37 __insert_grouping_aux(Char* first, Char* last, const string& grouping, |
|
38 Char separator, Char Plus, Char Minus, |
|
39 int basechars) { |
|
40 typedef string::size_type str_size; |
|
41 |
|
42 if (first == last) |
|
43 return 0; |
|
44 |
|
45 int sign = 0; |
|
46 |
|
47 if (*first == Plus || *first == Minus) { |
|
48 sign = 1; |
|
49 ++first; |
|
50 } |
|
51 |
|
52 first += basechars; |
|
53 str_size n = 0; // Index of the current group. |
|
54 Char* cur_group = last; // Points immediately beyond the rightmost |
|
55 // digit of the current group. |
|
56 int groupsize = 0; // Size of the current group. |
|
57 |
|
58 for (;;) { |
|
59 groupsize = n < grouping.size() ? grouping[n] : groupsize; |
|
60 ++n; |
|
61 |
|
62 if (groupsize <= 0 || groupsize >= cur_group - first) |
|
63 break; |
|
64 |
|
65 // Insert a separator character just before position cur_group - groupsize |
|
66 cur_group -= groupsize; |
|
67 ++last; |
|
68 copy_backward(cur_group, last, last + 1); |
|
69 *cur_group = separator; |
|
70 } |
|
71 |
|
72 return (last - first) + sign + basechars; |
|
73 } |
|
74 |
|
75 //Dynamic output buffer version. |
|
76 template <class Char, class Str> |
|
77 static void |
|
78 __insert_grouping_aux( /* __basic_iostring<Char> */ Str& iostr, size_t __group_pos, |
|
79 const string& grouping, |
|
80 Char separator, Char Plus, Char Minus, |
|
81 int basechars) { |
|
82 typedef string::size_type str_size; |
|
83 |
|
84 if (iostr.size() < __group_pos) |
|
85 return; |
|
86 |
|
87 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT |
|
88 int __first_pos = 0; |
|
89 #else |
|
90 size_t __first_pos = 0; |
|
91 #endif |
|
92 Char __first = *iostr.begin(); |
|
93 |
|
94 if (__first == Plus || __first == Minus) { |
|
95 ++__first_pos; |
|
96 } |
|
97 |
|
98 __first_pos += basechars; |
|
99 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT |
|
100 typename basic_string<Char>::iterator cur_group(iostr.begin() + __group_pos); // Points immediately beyond the rightmost |
|
101 // digit of the current group. |
|
102 int groupsize = 0; // Size of the current group (if grouping.size() == 0, size |
|
103 // of group unlimited: we force condition (groupsize <= 0)) |
|
104 |
|
105 for ( str_size n = 0; ; ) { // Index of the current group |
|
106 if ( n < grouping.size() ) { |
|
107 groupsize = __STATIC_CAST( int, grouping[n++] ); |
|
108 } |
|
109 |
|
110 if ( (groupsize <= 0) || (groupsize >= ((cur_group - iostr.begin()) - __first_pos)) || |
|
111 (groupsize == CHAR_MAX)) { |
|
112 break; |
|
113 } |
|
114 #else |
|
115 str_size n = 0; // Index of the current group. |
|
116 typename basic_string<Char>::iterator cur_group(iostr.begin() + __group_pos); // Points immediately beyond the rightmost |
|
117 // digit of the current group. |
|
118 unsigned int groupsize = 0; // Size of the current group. |
|
119 |
|
120 for (;;) { |
|
121 groupsize = n < grouping.size() ? grouping[n] : groupsize; |
|
122 ++n; |
|
123 |
|
124 if (groupsize <= 0 || groupsize >= ((cur_group - iostr.begin()) + __first_pos)) |
|
125 break; |
|
126 #endif |
|
127 |
|
128 // Insert a separator character just before position cur_group - groupsize |
|
129 cur_group -= groupsize; |
|
130 cur_group = iostr.insert(cur_group, separator); |
|
131 } |
|
132 } |
|
133 |
|
134 //---------------------------------------------------------------------- |
|
135 // num_put |
|
136 |
|
137 _STLP_MOVE_TO_PRIV_NAMESPACE |
|
138 |
|
139 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo() |
|
140 { return "0123456789abcdefx"; } |
|
141 |
|
142 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi() |
|
143 { return "0123456789ABCDEFX"; } |
|
144 |
|
145 char* _STLP_CALL |
|
146 __write_integer(char* buf, ios_base::fmtflags flags, long x) { |
|
147 char tmp[64]; |
|
148 char* bufend = tmp+64; |
|
149 char* beg = __write_integer_backward(bufend, flags, x); |
|
150 return copy(beg, bufend, buf); |
|
151 } |
|
152 |
|
153 ///------------------------------------- |
|
154 |
|
155 _STLP_DECLSPEC ptrdiff_t _STLP_CALL |
|
156 __insert_grouping(char * first, char * last, const string& grouping, |
|
157 char separator, char Plus, char Minus, int basechars) { |
|
158 return __insert_grouping_aux(first, last, grouping, |
|
159 separator, Plus, Minus, basechars); |
|
160 } |
|
161 |
|
162 _STLP_DECLSPEC void _STLP_CALL |
|
163 __insert_grouping(__iostring &str, size_t group_pos, const string& grouping, |
|
164 char separator, char Plus, char Minus, int basechars) { |
|
165 __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars); |
|
166 } |
|
167 |
|
168 #if !defined (_STLP_NO_WCHAR_T) |
|
169 _STLP_DECLSPEC ptrdiff_t _STLP_CALL |
|
170 __insert_grouping(wchar_t* first, wchar_t* last, const string& grouping, |
|
171 wchar_t separator, wchar_t Plus, wchar_t Minus, |
|
172 int basechars) { |
|
173 return __insert_grouping_aux(first, last, grouping, separator, |
|
174 Plus, Minus, basechars); |
|
175 } |
|
176 |
|
177 _STLP_DECLSPEC void _STLP_CALL |
|
178 __insert_grouping(__iowstring &str, size_t group_pos, const string& grouping, |
|
179 wchar_t separator, wchar_t Plus, wchar_t Minus, |
|
180 int basechars) { |
|
181 __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars); |
|
182 } |
|
183 #endif |
|
184 |
|
185 _STLP_MOVE_TO_STD_NAMESPACE |
|
186 |
|
187 #if defined (__SYMBIAN32__WSD__) |
|
188 template <> |
|
189 _STLP_DECLSPEC locale::id& num_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId() |
|
190 { |
|
191 return get_libcpp_wsd().num_put_char_ostreambuf_iterator_id; |
|
192 } |
|
193 # ifndef _STLP_NO_WCHAR_T |
|
194 template <> |
|
195 _STLP_DECLSPEC locale::id& num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId() |
|
196 { |
|
197 return get_libcpp_wsd().num_put_wchar_ostreambuf_iterator_id; |
|
198 } |
|
199 # endif /* _STLP_NO_WCHAR_T */ |
|
200 #endif /* __SYMBIAN32__WSD__ */ |
|
201 |
|
202 //---------------------------------------------------------------------- |
|
203 // Force instantiation of num_put<> |
|
204 #if !defined(_STLP_NO_FORCE_INSTANTIATE) |
|
205 template class _STLP_CLASS_DECLSPEC ostreambuf_iterator<char, char_traits<char> >; |
|
206 // template class num_put<char, char*>; |
|
207 template class num_put<char, ostreambuf_iterator<char, char_traits<char> > >; |
|
208 # ifndef _STLP_NO_WCHAR_T |
|
209 template class ostreambuf_iterator<wchar_t, char_traits<wchar_t> >; |
|
210 template class num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >; |
|
211 // template class num_put<wchar_t, wchar_t*>; |
|
212 # endif /* INSTANTIATE_WIDE_STREAMS */ |
|
213 #endif |
|
214 |
|
215 #if defined(__EPOC32__) |
|
216 template <> |
|
217 locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id={14}; |
|
218 |
|
219 # if !defined (_STLP_NO_WCHAR_T) |
|
220 template <> |
|
221 locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id={33}; |
|
222 # endif |
|
223 |
|
224 #endif |
|
225 |
|
226 _STLP_END_NAMESPACE |
|
227 |
|
228 // Local Variables: |
|
229 // mode:C++ |
|
230 // End: |