|
1 /* |
|
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. 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 # include "stlport_prefix.h" |
|
21 #include <stl/_num_get.h> |
|
22 #include <stl/_istream.h> |
|
23 #include <stl/_algo.h> |
|
24 |
|
25 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) |
|
26 #include "libstdcppwsd.h" |
|
27 # endif |
|
28 |
|
29 _STLP_BEGIN_NAMESPACE |
|
30 |
|
31 //---------------------------------------------------------------------- |
|
32 // num_get |
|
33 |
|
34 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) |
|
35 //initialize the static array |
|
36 void num_get_array_init() |
|
37 { |
|
38 strcpy(get_num_get_narrow_digits(),"0123456789"); |
|
39 strcpy(get_num_get_narrow_xdigits(),"aAbBcCdDeEfF"); |
|
40 } |
|
41 # else |
|
42 static char narrow_digits[11] = "0123456789"; |
|
43 static char narrow_xdigits[13] = "aAbBcCdDeEfF"; |
|
44 # endif |
|
45 |
|
46 # ifndef _STLP_NO_WCHAR_T |
|
47 |
|
48 void _STLP_CALL |
|
49 _Initialize_get_digit(wchar_t* digits, wchar_t* xdigits, |
|
50 const ctype<wchar_t>& ct) |
|
51 { |
|
52 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_) |
|
53 ct.widen(get_num_get_narrow_digits() + 0, get_num_get_narrow_digits() + 10, digits); |
|
54 ct.widen(get_num_get_narrow_xdigits() + 0, get_num_get_narrow_xdigits() + 10, xdigits); |
|
55 #else |
|
56 ct.widen(narrow_digits + 0, narrow_digits + 10, digits); |
|
57 ct.widen(narrow_xdigits + 0, narrow_xdigits + 10, xdigits); |
|
58 # endif |
|
59 } |
|
60 |
|
61 // Return either the digit corresponding to c, or a negative number if |
|
62 // if c isn't a digit. We return -1 if c is the separator character, and |
|
63 // -2 if it's some other non-digit. |
|
64 int _STLP_CALL __get_digit(wchar_t c, |
|
65 const wchar_t* digits, const wchar_t* xdigits, |
|
66 wchar_t separator) |
|
67 { |
|
68 // Test if it's the separator. |
|
69 if (c == separator) |
|
70 return -1; |
|
71 |
|
72 const wchar_t* p; |
|
73 |
|
74 // Test if it's a decimal digit. |
|
75 p = find(digits, digits + 10, c); |
|
76 if (p != digits + 10) |
|
77 return (int)(p - digits); |
|
78 |
|
79 // Test if it's a hex digit. |
|
80 p = find(xdigits, xdigits + 12, c); |
|
81 if (p != xdigits + 12) |
|
82 return (int)(10 + (xdigits - p) / 2); |
|
83 else |
|
84 return -2; // It's not a digit and not the separator. |
|
85 } |
|
86 |
|
87 # endif /* _STLP_NO_WCHAR_T */ |
|
88 |
|
89 // __valid_grouping compares two strings, one representing the |
|
90 // group sizes encountered when reading an integer, and the other |
|
91 // representing the valid group sizes as returned by the numpunct |
|
92 // grouping() member function. Both are interpreted right-to-left. |
|
93 // The grouping string is treated as if it were extended indefinitely |
|
94 // with its last value. For a grouping to be valid, each term in |
|
95 // the first string must be equal to the corresponding term in the |
|
96 // second, except for the last, which must be less than or equal. |
|
97 |
|
98 // boris : this takes reversed first string ! |
|
99 _STLP_EXP_DECLSPEC bool _STLP_CALL |
|
100 __valid_grouping(const char * first1, const char * last1, |
|
101 const char * first2, const char * last2) |
|
102 { |
|
103 if (first1 == last1 || first2 == last2) return true; |
|
104 |
|
105 --last1; --last2; |
|
106 |
|
107 while (first1 != last1) { |
|
108 if (*last1 != *first2) |
|
109 return false; |
|
110 --last1; |
|
111 if (first2 != last2) ++first2; |
|
112 } |
|
113 |
|
114 return *last1 <= *first2; |
|
115 } |
|
116 |
|
117 // this needed for some compilers to make sure sumbols are extern |
|
118 extern const unsigned char __digit_val_table[]; |
|
119 extern const char __narrow_atoms[]; |
|
120 |
|
121 |
|
122 const unsigned char __digit_val_table[128] = |
|
123 { |
|
124 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
|
125 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
|
126 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
|
127 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
|
128 0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
|
129 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
|
130 0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, |
|
131 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF |
|
132 }; |
|
133 |
|
134 const char __narrow_atoms[5] = {'+', '-', '0', 'x', 'X'}; |
|
135 |
|
136 _STLP_EXP_DECLSPEC unsigned char* _STLP_CALL __get_digit_val_table(void) |
|
137 { |
|
138 return (unsigned char*)__digit_val_table; |
|
139 } |
|
140 _STLP_EXP_DECLSPEC char* _STLP_CALL __get_narrow_atoms(void) |
|
141 { |
|
142 return (char*)__narrow_atoms; |
|
143 } |
|
144 // index is actually a char |
|
145 |
|
146 # ifndef _STLP_NO_WCHAR_T |
|
147 |
|
148 |
|
149 //---------------------------------------------------------------------- |
|
150 // Force instantiation of of num_get<> |
|
151 |
|
152 #if !defined(_STLP_NO_FORCE_INSTANTIATE) |
|
153 template class _STLP_CLASS_DECLSPEC istreambuf_iterator<wchar_t, char_traits<wchar_t> >; |
|
154 template class num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >; |
|
155 // template class num_get<wchar_t, const wchar_t*>; |
|
156 #endif |
|
157 |
|
158 # endif /* _STLP_NO_WCHAR_T */ |
|
159 |
|
160 //---------------------------------------------------------------------- |
|
161 // Force instantiation of of num_get<> |
|
162 |
|
163 #if !defined(_STLP_NO_FORCE_INSTANTIATE) |
|
164 template class _STLP_CLASS_DECLSPEC istreambuf_iterator<char, char_traits<char> >; |
|
165 // template class num_get<char, const char*>; |
|
166 template class num_get<char, istreambuf_iterator<char, char_traits<char> > >; |
|
167 #endif |
|
168 |
|
169 // basic_streambuf<char, char_traits<char> >* _STLP_CALL _M_get_istreambuf(basic_istream<char, char_traits<char> >& ) ; |
|
170 |
|
171 _STLP_END_NAMESPACE |
|
172 |
|
173 // Local Variables: |
|
174 // mode:C++ |
|
175 // End: |
|
176 |
|
177 |