Ticket #4659: patchfile.patch
File patchfile.patch, 12.1 KB (added by , 12 years ago) |
---|
-
format_implementation.hpp
235 235 if( static_cast<size_type>(item.fmtstate_.width_) > res.size() ) 236 236 res.append( static_cast<size_type>(item.fmtstate_.width_) - res.size(), 237 237 item.fmtstate_.fill_ ); 238 }else if( item.argN_ == format_item_t::argN_repeat) { // added by Francis (Grizzly) Smit // 239 BOOST_ASSERT( item.pad_scheme_ & format_item_t::repeat); 240 res.append( static_cast<size_type>(item.fmtstate_.width_), item.fmtstate_.fill_ ); 238 241 } 239 242 res += item.appendix_; 240 243 } -
feed_args.hpp
116 116 } 117 117 #endif 118 118 #endif // -msvc workaround 119 120 // Added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 121 template< class T> 122 inline long long cast_to_long_long(T t) 123 { // should never be called // 124 return 0; 125 } 119 126 127 inline long long cast_to_long_long(char v) 128 { 129 return static_cast<long long>(v); 130 } 120 131 132 inline long long cast_to_long_long(signed char v) 133 { 134 return static_cast<long long>(v); 135 } 136 137 inline long long cast_to_long_long(short v) 138 { 139 return static_cast<long long>(v); 140 } 141 142 inline long long cast_to_long_long(int v) 143 { 144 return static_cast<long long>(v); 145 } 146 147 inline long long cast_to_long_long(long v) 148 { 149 return static_cast<long long>(v); 150 } 151 152 inline long long cast_to_long_long(long long v) 153 { 154 return static_cast<long long>(v); 155 } 156 157 // Added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 158 template< class T> 159 inline unsigned long long cast_to_unsigned_long_long(T t) 160 { // should never be called // 161 return 0; 162 } 163 164 inline unsigned long long cast_to_unsigned_long_long(unsigned char v) 165 { 166 return static_cast<unsigned long long>(v); 167 } 168 169 inline unsigned long long cast_to_unsigned_long_long(unsigned short v) 170 { 171 return static_cast<unsigned long long>(v); 172 } 173 174 inline unsigned long long cast_to_unsigned_long_long(unsigned int v) 175 { 176 return static_cast<unsigned long long>(v); 177 } 178 179 inline unsigned long long cast_to_unsigned_long_long(unsigned long v) 180 { 181 return static_cast<unsigned long long>(v); 182 } 183 184 inline unsigned long long cast_to_unsigned_long_long(unsigned long long v) 185 { 186 return static_cast<unsigned long long>(v); 187 } 188 121 189 template< class Ch, class Tr, class Alloc, class T> 122 190 void put( T x, 123 191 const format_item<Ch, Tr, Alloc>& specs, … … 137 205 138 206 typedef typename basic_format<Ch, Tr, Alloc>::string_type string_type; 139 207 typedef typename basic_format<Ch, Tr, Alloc>::format_item_t format_item_t; 208 typedef typename basic_format<Ch, Tr, Alloc>::format_item_t::base_args base_args_t; 140 209 typedef typename string_type::size_type size_type; 141 210 142 211 basic_oaltstringstream<Ch, Tr, Alloc> oss( &buf); 143 212 specs.fmtstate_.apply_on(oss, loc_p); 213 214 //* 215 unsigned char base = static_cast<unsigned char>(specs.base); 216 if(base) 217 { 218 bool uppercase = (specs.fmtstate_.flags_ & std::ios_base::uppercase); 219 if((2 <= base) && (base <= 36)) 220 { 221 if((typeid(T) == typeid(char)) || (typeid(T) == typeid(short)) || 222 (typeid(T) == typeid(int)) || (typeid(T) == typeid(long)) || 223 (typeid(T) == typeid(long long)) || (typeid(T) == typeid(signed char))) 224 { 225 string_type buffer; 226 long long l = cast_to_long_long(x); 227 int sign = (l < 0)?-1:1; 228 char digit; 229 if(sign == -1) 230 { 231 l = -l; 232 } 233 for(; l > 0; l /= base) 234 { 235 digit = l % base; 236 digit += (digit < 10)?('0'):((uppercase)?('A' - 10):('a' - 10)); 237 buffer = digit + buffer; 238 } 239 if(sign == -1) 240 { 241 buffer = '-' + buffer; 242 } 243 format_item<Ch, Tr, Alloc> specs1 = specs; 244 specs1.base = static_cast<base_args_t>(0); 245 put(buffer, specs1, res, buf, loc_p); 246 return; 247 }else if((typeid(T) == typeid(unsigned char)) || 248 (typeid(T) == typeid(unsigned short)) || (typeid(T) == typeid(unsigned int)) || 249 (typeid(T) == typeid(unsigned long)) || (typeid(T) == typeid(unsigned long long))) 250 { 251 string_type buffer; 252 unsigned long long l = cast_to_unsigned_long_long(x); 253 char digit; 254 for(; l > 0; l /= base) 255 { 256 digit = l % base; 257 digit += (digit < 10)?('0'):((uppercase)?('A' - 10):('a' - 10)); 258 buffer += digit + buffer; 259 } 260 format_item<Ch, Tr, Alloc> specs1 = specs; 261 specs1.base = static_cast<base_args_t>(0); 262 put(buffer, specs1, res, buf, loc_p); 263 return; 264 } 265 } 266 } 267 //*/ 144 268 145 269 // the stream format state can be modified by manipulators in the argument : 146 270 put_head( oss, x ); -
internals.hpp
63 63 template<class Ch, class Tr, class Alloc> 64 64 struct format_item 65 65 { 66 enum pad_values { zeropad = 1, spacepad =2, centered=4, tabulation = 8 };66 enum pad_values { zeropad = 1, spacepad =2, centered=4, tabulation = 8, repeat = 16 }; 67 67 // 1. if zeropad is set, all other bits are not, 68 68 // 2. if tabulation is set, all others are not. 69 69 // centered and spacepad can be mixed freely. 70 // repeat added by Francis (Grizzly) Smit // 70 71 enum arg_values { argN_no_posit = -1, // non-positional directive. will set argN later 71 72 argN_tabulation = -2, // tabulation directive. (no argument read) 72 argN_ignored = -3 // ignored directive. (no argument read) 73 argN_ignored = -3, // ignored directive. (no argument read) 74 argN_repeat = -4 // repeat. (no argument read) // added by Francis (Grizzly) Smit // 73 75 }; 76 // added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 77 enum base_args { base_io = 63, repeat_chars = 1 << 7 }; 78 // 2 ... 36 base number // 79 // 128 ... 255 xor'd with repeat_chars gives a value of from 0 ... 127 // 74 80 typedef BOOST_IO_STD basic_ios<Ch, Tr> basic_ios; 75 81 typedef detail::stream_format_state<Ch, Tr> stream_format_state; 76 82 typedef ::std::basic_string<Ch, Tr, Alloc> string_type; 77 83 78 format_item(Ch fill) :argN_(argN_no_posit), fmtstate_(fill), 84 format_item(Ch fill) :argN_(argN_no_posit), fmtstate_(fill), base(static_cast<base_args>(0)), 85 // base added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 79 86 truncate_(max_streamsize()), pad_scheme_(0) {} 80 87 void reset(Ch fill); 81 88 void compute_states(); // sets states according to truncate and pad_scheme. … … 92 99 93 100 stream_format_state fmtstate_;// set by parsing, is only affected by modify_item 94 101 102 base_args base; // added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 103 95 104 std::streamsize truncate_;//- is set for directives like %.5s that ask truncation 96 105 unsigned int pad_scheme_;//- several possible padding schemes can mix. see pad_values 106 format_item& operator=(const format_item& fi) // added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 107 { 108 argN_ = fi.argN_; 109 res_ = fi.res_; 110 appendix_ = fi.appendix_; 111 fmtstate_ = fi.fmtstate_; 112 base = fi.base; 113 truncate_ = fi.truncate_; 114 pad_scheme_ = fi.pad_scheme_; 115 } 97 116 }; 98 117 99 118 -
parsing.hpp
126 126 std::size_t offset, unsigned char exceptions) 127 127 { 128 128 typedef typename basic_format<Ch, Tr, Alloc>::format_item_t format_item_t; 129 typedef typename basic_format<Ch, Tr, Alloc>::format_item_t::base_args base_args; 129 130 130 131 fpar->argN_ = format_item_t::argN_no_posit; // if no positional-directive 131 132 bool precision_set = false; … … 265 266 return true; 266 267 } 267 268 switch ( wrap_narrow(fac, *start, 0) ) { 269 case 'B': // added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 270 fpar->fmtstate_.flags_ |= std::ios_base::boolalpha; 271 break; 272 case 'b': // added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 273 if(wrap_narrow(fac, *(start + 1), 0) == '(') 274 { 275 start += 2; 276 if(wrap_narrow(fac, *start, 0) == '-') 277 { 278 fpar->fmtstate_.flags_ &= ~std::ios_base::uppercase; 279 ++start; 280 }else{ 281 if(wrap_narrow(fac, *start, 0) == '+') ++start; 282 fpar->fmtstate_.flags_ |= std::ios_base::uppercase; 283 } 284 unsigned char base; 285 start = str2int(start, last, base, fac); 286 if((2 <= base) && (base <= 36)) 287 { 288 fpar->base = static_cast<base_args>(base); 289 }else{ 290 maybe_throw_exception(exceptions, start-start0+offset, fstring_size); 291 } 292 if(wrap_narrow(fac, *start, 0) != ')') 293 maybe_throw_exception(exceptions, start-start0+offset, fstring_size); 294 }else{ 295 fpar->base = static_cast<base_args>(2); 296 } 297 break; 298 case 'r': // added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 299 fpar->fmtstate_.fill_ = const_or_not(fac).widen( ' '); 300 fpar->pad_scheme_ |= format_item_t::repeat; 301 fpar->argN_ = format_item_t::argN_repeat; 302 break; 303 case 'R': // added by Francis (Grizzly) Smit <grizzlysmit@smit.id.au> // 304 ++start; 305 if( start >= last) 306 maybe_throw_exception(exceptions, start-start0+offset, fstring_size); 307 else 308 fpar->fmtstate_.fill_ = *start; 309 fpar->pad_scheme_ |= format_item_t::repeat; 310 fpar->argN_ = format_item_t::argN_repeat; 311 break; 312 268 313 case 'X': 269 314 fpar->fmtstate_.flags_ |= std::ios_base::uppercase; 270 315 case 'p': // pointer => set hex. … … 460 505 if(argN ==format_item_t::argN_no_posit) 461 506 ordered_args=false; 462 507 else if(argN == format_item_t::argN_tabulation) special_things=true; 508 else if(argN == format_item_t::argN_repeat) special_things=true; // added by Francis (Grizzly) Smit // 463 509 else if(argN > max_argN) max_argN = argN; 464 510 ++num_items; 465 511 ++cur_item;