First public contribution.
2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
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.
21 #include "stlport_prefix.h"
26 #ifdef __SYMBIAN32__WSD__
27 #include <libstdcppwsd.h>
28 #endif //__SYMBIAN32__WSD__
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).
37 __insert_grouping_aux(Char* first, Char* last, const string& grouping,
38 Char separator, Char Plus, Char Minus,
40 typedef string::size_type str_size;
47 if (*first == Plus || *first == Minus) {
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.
59 groupsize = n < grouping.size() ? grouping[n] : groupsize;
62 if (groupsize <= 0 || groupsize >= cur_group - first)
65 // Insert a separator character just before position cur_group - groupsize
66 cur_group -= groupsize;
68 copy_backward(cur_group, last, last + 1);
69 *cur_group = separator;
72 return (last - first) + sign + basechars;
75 //Dynamic output buffer version.
76 template <class Char, class Str>
78 __insert_grouping_aux( /* __basic_iostring<Char> */ Str& iostr, size_t __group_pos,
79 const string& grouping,
80 Char separator, Char Plus, Char Minus,
82 typedef string::size_type str_size;
84 if (iostr.size() < __group_pos)
87 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
90 size_t __first_pos = 0;
92 Char __first = *iostr.begin();
94 if (__first == Plus || __first == Minus) {
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))
105 for ( str_size n = 0; ; ) { // Index of the current group
106 if ( n < grouping.size() ) {
107 groupsize = __STATIC_CAST( int, grouping[n++] );
110 if ( (groupsize <= 0) || (groupsize >= ((cur_group - iostr.begin()) - __first_pos)) ||
111 (groupsize == CHAR_MAX)) {
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.
121 groupsize = n < grouping.size() ? grouping[n] : groupsize;
124 if (groupsize <= 0 || groupsize >= ((cur_group - iostr.begin()) + __first_pos))
128 // Insert a separator character just before position cur_group - groupsize
129 cur_group -= groupsize;
130 cur_group = iostr.insert(cur_group, separator);
134 //----------------------------------------------------------------------
137 _STLP_MOVE_TO_PRIV_NAMESPACE
139 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo()
140 { return "0123456789abcdefx"; }
142 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi()
143 { return "0123456789ABCDEFX"; }
146 __write_integer(char* buf, ios_base::fmtflags flags, long x) {
148 char* bufend = tmp+64;
149 char* beg = __write_integer_backward(bufend, flags, x);
150 return copy(beg, bufend, buf);
153 ///-------------------------------------
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);
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);
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,
173 return __insert_grouping_aux(first, last, grouping, separator,
174 Plus, Minus, basechars);
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,
181 __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars);
185 _STLP_MOVE_TO_STD_NAMESPACE
187 #if defined (__SYMBIAN32__WSD__)
189 _STLP_DECLSPEC locale::id& num_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()
191 return get_libcpp_wsd().num_put_char_ostreambuf_iterator_id;
193 # ifndef _STLP_NO_WCHAR_T
195 _STLP_DECLSPEC locale::id& num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()
197 return get_libcpp_wsd().num_put_wchar_ostreambuf_iterator_id;
199 # endif /* _STLP_NO_WCHAR_T */
200 #endif /* __SYMBIAN32__WSD__ */
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 */
215 #if defined(__EPOC32__)
217 locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id={14};
219 # if !defined (_STLP_NO_WCHAR_T)
221 locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id={33};