Ticket #5417: lexical_cast.hpp.diff

File lexical_cast.hpp.diff, 7.4 KB (added by Antony Polukhin <antoshkka@…>, 12 years ago)

Patch for trunk version of lexical_cast (for revision 70966)

Line 
1662a667,720
2> namespace detail // lcast_ret_unsigned
3> {
4> template<class Traits, class T, class CharT>
5> inline bool lcast_ret_unsigned(T& value, const CharT* begin, const CharT* end)
6> {
7> #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
8> BOOST_STATIC_ASSERT(!std::numeric_limits<T>::is_signed);
9> #endif
10>
11>
12> #ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
13> // TODO: use BOOST_NO_STD_LOCALE
14> std::locale loc;
15> typedef std::numpunct<CharT> numpunct;
16> numpunct const& np = BOOST_USE_FACET(numpunct, loc);
17> std::string const& grouping = np.grouping();
18> std::string::size_type const grouping_size = grouping.size();
19> CharT thousands_sep = grouping_size ? np.thousands_sep() : 0;
20> #endif
21>
22> typedef typename Traits::int_type int_type;
23> CharT const czero = lcast_char_constants<CharT>::zero;
24> int_type const zero = Traits::to_int_type(czero);
25>
26> value = 0;
27>
28> if ( *begin < czero || *begin > czero + 10)
29> return false;
30> value = *begin - zero;
31> ++ begin;
32>
33> while ( begin != end )
34> {
35> #ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
36> if ( Traits::eq(*begin, thousands_sep) ){
37> ++ begin;
38> continue;
39> }
40> #endif
41>
42> if ( *begin < czero
43> || *begin > czero + 10
44> || static_cast<T>(value * 10) < value)
45> return false;
46> value *= 10;
47> value += *begin - zero;
48> ++begin;
49> };
50>
51> return true;
52> }
53>
54> }
55>
56760a819,894
57> #define BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_UNSIGNED(type) \
58> bool operator>>(type& output) \
59> { \
60> CharT const minus = lcast_char_constants<CharT>::minus; \
61> if( Traits::eq(minus,*start) ) return false; \
62> return lcast_ret_unsigned<Traits>(output, start, finish); \
63> }
64>
65> #define BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_SIGNED(type) \
66> bool operator>>(type& output) \
67> { \
68> CharT const minus = lcast_char_constants<CharT>::minus; \
69> unsigned type out_tmp =0; \
70> bool const has_minus = Traits::eq(minus,*start); \
71> if (has_minus) ++ start; \
72> bool result = ( (*this)>>out_tmp ); \
73> if (has_minus) -- start; \
74> unsigned type const comp_val \
75> = minus \
76> ? static_cast<unsigned type>(-(std::numeric_limits<type>::min)()) \
77> : static_cast<unsigned type>((std::numeric_limits<type>::max)()); \
78> result = result && out_tmp<=comp_val; \
79> output = has_minus ? -1 * out_tmp : out_tmp; \
80> return result; \
81> }
82>
83> BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_UNSIGNED(unsigned short)
84> BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_UNSIGNED(unsigned int)
85> BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_UNSIGNED(unsigned long int)
86> #if defined(BOOST_HAS_LONG_LONG)
87> BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_UNSIGNED( boost::ulong_long_type )
88> #elif defined(BOOST_HAS_MS_INT64)
89> BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_UNSIGNED(unsigned __int64)
90> #endif
91>
92> BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_SIGNED(short)
93> BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_SIGNED(int)
94> BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_SIGNED(long int)
95> #if defined(BOOST_HAS_LONG_LONG)
96> bool operator>>(boost::long_long_type& output)
97> {
98> CharT const minus = lcast_char_constants<CharT>::minus;
99> boost::ulong_long_type out_tmp =0;
100> bool const has_minus = Traits::eq(minus,*start);
101> if (has_minus) ++ start;
102> bool result = ( (*this)>>out_tmp );
103> if (has_minus) -- start;
104> boost::ulong_long_type const comp_val
105> = minus
106> ? static_cast<boost::ulong_long_type>(
107> -(std::numeric_limits<boost::long_long_type>::min)()
108> )
109> : static_cast<boost::ulong_long_type>(
110> (std::numeric_limits<boost::long_long_type>::max)()
111> );
112> result = result && out_tmp<=comp_val;
113> output = has_minus ? -1 * out_tmp : out_tmp;
114> return result;
115> }
116> #elif defined(BOOST_HAS_MS_INT64)
117> BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_SIGNED(__int64)
118> #endif
119>
120> #undef BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_UNSIGNED
121> #undef BOOST_DECLARE_INTERNAL_FAST_OUTPUT_OPERATORS_SIGNED
122>
123> bool operator>>(bool& output)
124> {
125> output = (start[0] == lcast_char_constants<CharT>::zero + 1);
126> return finish-start==1
127> && (
128> start[0] == lcast_char_constants<CharT>::zero
129> || start[0] == lcast_char_constants<CharT>::zero + 1
130> );
131> }
132>
1331064a1199,1223
134>
135> template<>
136> struct lcast_streambuf_for_target<unsigned short>
137> {
138> BOOST_STATIC_CONSTANT(bool, value = false);
139> };
140>
141> template<>
142> struct lcast_streambuf_for_target<unsigned int>
143> {
144> BOOST_STATIC_CONSTANT(bool, value = false);
145> };
146>
147> template<>
148> struct lcast_streambuf_for_target<unsigned long>
149> {
150> BOOST_STATIC_CONSTANT(bool, value = false);
151> };
152>
153> template<>
154> struct lcast_streambuf_for_target<boost::ulong_long_type>
155> {
156> BOOST_STATIC_CONSTANT(bool, value = false);
157> };
158>
1591071a1231,1259
160> template<>
161> struct lcast_streambuf_for_target<short>
162> {
163> BOOST_STATIC_CONSTANT(bool, value = false);
164> };
165>
166> template<>
167> struct lcast_streambuf_for_target<int>
168> {
169> BOOST_STATIC_CONSTANT(bool, value = false);
170> };
171>
172> template<>
173> struct lcast_streambuf_for_target<long>
174> {
175> BOOST_STATIC_CONSTANT(bool, value = false);
176> };
177>
178> template<>
179> struct lcast_streambuf_for_target<bool>
180> {
181> BOOST_STATIC_CONSTANT(bool, value = false);
182> };
183>
184> template<>
185> struct lcast_streambuf_for_target<boost::long_long_type>
186> {
187> BOOST_STATIC_CONSTANT(bool, value = false);
188> };