Ticket #4952: time_facet.hpp.diff
File time_facet.hpp.diff, 21.0 KB (added by , 12 years ago) |
---|
-
boost/boost/date_time/time_facet.hpp
-
/
old new 244 244 #endif 245 245 246 246 //! sets default formats for ptime, local_date_time, and time_duration 247 explicit time_facet(::size_t a_ref= 0)248 : base_type(default_time_format, period_formatter_type(), special_values_formatter_type(), date_gen_formatter_type(), a_ref),247 explicit time_facet(::size_t ref_arg = 0) 248 : base_type(default_time_format, period_formatter_type(), special_values_formatter_type(), date_gen_formatter_type(), ref_arg), 249 249 m_time_duration_format(string_type(duration_sign_negative_only) + default_time_duration_format) 250 250 {} 251 251 252 252 //! Construct the facet with an explicitly specified format 253 explicit time_facet(const char_type* a_format,254 period_formatter_type period_formatter = period_formatter_type(),253 explicit time_facet(const char_type* format_arg, 254 period_formatter_type period_formatter_arg = period_formatter_type(), 255 255 const special_values_formatter_type& special_value_formatter = special_values_formatter_type(), 256 256 date_gen_formatter_type dg_formatter = date_gen_formatter_type(), 257 ::size_t a_ref= 0)258 : base_type( a_format,259 period_formatter ,257 ::size_t ref_arg = 0) 258 : base_type(format_arg, 259 period_formatter_arg, 260 260 special_value_formatter, 261 261 dg_formatter, 262 a_ref),262 ref_arg), 263 263 m_time_duration_format(string_type(duration_sign_negative_only) + default_time_duration_format) 264 264 {} 265 265 … … 278 278 this->m_format = iso_time_format_extended_specifier; 279 279 } 280 280 281 OutItrT put(OutItrT a_next,282 std::ios_base& a_ios,283 char_type a_fill,284 const time_type& a_time) const281 OutItrT put(OutItrT next_arg, 282 std::ios_base& ios_arg, 283 char_type fill_arg, 284 const time_type& time_arg) const 285 285 { 286 if ( a_time.is_special()) {287 return this->do_put_special( a_next, a_ios, a_fill,288 a_time.date().as_special());286 if (time_arg.is_special()) { 287 return this->do_put_special(next_arg, ios_arg, fill_arg, 288 time_arg.date().as_special()); 289 289 } 290 string_type format(this->m_format);290 string_type local_format(this->m_format); 291 291 292 292 // %T and %R have to be replaced here since they are not standard 293 boost::algorithm::replace_all( format,293 boost::algorithm::replace_all(local_format, 294 294 boost::as_literal(formats_type::full_24_hour_time_format), 295 295 boost::as_literal(formats_type::full_24_hour_time_expanded_format)); 296 boost::algorithm::replace_all( format,296 boost::algorithm::replace_all(local_format, 297 297 boost::as_literal(formats_type::short_24_hour_time_format), 298 298 boost::as_literal(formats_type::short_24_hour_time_expanded_format)); 299 299 300 300 string_type frac_str; 301 if ( format.find(seconds_with_fractional_seconds_format) != string_type::npos) {301 if (local_format.find(seconds_with_fractional_seconds_format) != string_type::npos) { 302 302 // replace %s with %S.nnn 303 303 frac_str = 304 fractional_seconds_as_string( a_time.time_of_day(), false);305 char_type sep = std::use_facet<std::numpunct<char_type> >( a_ios.getloc()).decimal_point();304 fractional_seconds_as_string(time_arg.time_of_day(), false); 305 char_type sep = std::use_facet<std::numpunct<char_type> >(ios_arg.getloc()).decimal_point(); 306 306 307 307 string_type replace_string(seconds_format); 308 308 replace_string += sep; 309 309 replace_string += frac_str; 310 boost::algorithm::replace_all( format,310 boost::algorithm::replace_all(local_format, 311 311 seconds_with_fractional_seconds_format, 312 312 replace_string); 313 313 } 314 314 /* NOTE: replacing posix_zone_string_format must be done BEFORE 315 315 * zone_name_format: "%ZP" & "%Z", if Z is checked first it will 316 316 * incorrectly replace a zone_name where a posix_string should go */ 317 if ( format.find(posix_zone_string_format) != string_type::npos) {318 if( a_time.zone_abbrev().empty()) {317 if (local_format.find(posix_zone_string_format) != string_type::npos) { 318 if(time_arg.zone_abbrev().empty()) { 319 319 // if zone_abbrev() returns an empty string, we want to 320 320 // erase posix_zone_string_format from format 321 boost::algorithm::erase_all( format, posix_zone_string_format);321 boost::algorithm::erase_all(local_format, posix_zone_string_format); 322 322 } 323 323 else{ 324 boost::algorithm::replace_all( format,324 boost::algorithm::replace_all(local_format, 325 325 posix_zone_string_format, 326 a_time.zone_as_posix_string());326 time_arg.zone_as_posix_string()); 327 327 } 328 328 } 329 if ( format.find(zone_name_format) != string_type::npos) {330 if( a_time.zone_name().empty()) {329 if (local_format.find(zone_name_format) != string_type::npos) { 330 if(time_arg.zone_name().empty()) { 331 331 /* TODO: this'll probably create problems if a user places 332 332 * the zone_*_format flag in the format with a ptime. This 333 333 * code removes the flag from the default formats */ … … 336 336 // erase zone_name_format & one preceeding space 337 337 std::basic_ostringstream<char_type> ss; 338 338 ss << ' ' << zone_name_format; 339 boost::algorithm::erase_all( format, ss.str());339 boost::algorithm::erase_all(local_format, ss.str()); 340 340 } 341 341 else{ 342 boost::algorithm::replace_all( format,342 boost::algorithm::replace_all(local_format, 343 343 zone_name_format, 344 a_time.zone_name());344 time_arg.zone_name()); 345 345 } 346 346 } 347 if ( format.find(zone_abbrev_format) != string_type::npos) {348 if( a_time.zone_abbrev(false).empty()) {347 if (local_format.find(zone_abbrev_format) != string_type::npos) { 348 if(time_arg.zone_abbrev(false).empty()) { 349 349 /* TODO: this'll probably create problems if a user places 350 350 * the zone_*_format flag in the format with a ptime. This 351 351 * code removes the flag from the default formats */ … … 354 354 // erase zone_abbrev_format & one preceeding space 355 355 std::basic_ostringstream<char_type> ss; 356 356 ss << ' ' << zone_abbrev_format; 357 boost::algorithm::erase_all( format, ss.str());357 boost::algorithm::erase_all(local_format, ss.str()); 358 358 } 359 359 else{ 360 boost::algorithm::replace_all( format,360 boost::algorithm::replace_all(local_format, 361 361 zone_abbrev_format, 362 a_time.zone_abbrev(false));362 time_arg.zone_abbrev(false)); 363 363 } 364 364 } 365 if ( format.find(zone_iso_extended_format) != string_type::npos) {366 if( a_time.zone_name(true).empty()) {365 if (local_format.find(zone_iso_extended_format) != string_type::npos) { 366 if(time_arg.zone_name(true).empty()) { 367 367 /* TODO: this'll probably create problems if a user places 368 368 * the zone_*_format flag in the format with a ptime. This 369 369 * code removes the flag from the default formats */ 370 370 371 371 // if zone_name() returns an empty string, we want to 372 372 // erase zone_iso_extended_format from format 373 boost::algorithm::erase_all( format, zone_iso_extended_format);373 boost::algorithm::erase_all(local_format, zone_iso_extended_format); 374 374 } 375 375 else{ 376 boost::algorithm::replace_all( format,376 boost::algorithm::replace_all(local_format, 377 377 zone_iso_extended_format, 378 a_time.zone_name(true));378 time_arg.zone_name(true)); 379 379 } 380 380 } 381 381 382 if ( format.find(zone_iso_format) != string_type::npos) {383 if( a_time.zone_abbrev(true).empty()) {382 if (local_format.find(zone_iso_format) != string_type::npos) { 383 if(time_arg.zone_abbrev(true).empty()) { 384 384 /* TODO: this'll probably create problems if a user places 385 385 * the zone_*_format flag in the format with a ptime. This 386 386 * code removes the flag from the default formats */ 387 387 388 388 // if zone_abbrev() returns an empty string, we want to 389 389 // erase zone_iso_format from format 390 boost::algorithm::erase_all( format, zone_iso_format);390 boost::algorithm::erase_all(local_format, zone_iso_format); 391 391 } 392 392 else{ 393 boost::algorithm::replace_all( format,393 boost::algorithm::replace_all(local_format, 394 394 zone_iso_format, 395 a_time.zone_abbrev(true));395 time_arg.zone_abbrev(true)); 396 396 } 397 397 } 398 if ( format.find(fractional_seconds_format) != string_type::npos) {398 if (local_format.find(fractional_seconds_format) != string_type::npos) { 399 399 // replace %f with nnnnnnn 400 400 if (frac_str.empty()) { 401 frac_str = fractional_seconds_as_string( a_time.time_of_day(), false);401 frac_str = fractional_seconds_as_string(time_arg.time_of_day(), false); 402 402 } 403 boost::algorithm::replace_all( format,403 boost::algorithm::replace_all(local_format, 404 404 fractional_seconds_format, 405 405 frac_str); 406 406 } 407 407 408 if ( format.find(fractional_seconds_or_none_format) != string_type::npos) {408 if (local_format.find(fractional_seconds_or_none_format) != string_type::npos) { 409 409 // replace %F with nnnnnnn or nothing if fs == 0 410 410 frac_str = 411 fractional_seconds_as_string( a_time.time_of_day(), true);411 fractional_seconds_as_string(time_arg.time_of_day(), true); 412 412 if (frac_str.size()) { 413 char_type sep = std::use_facet<std::numpunct<char_type> >( a_ios.getloc()).decimal_point();413 char_type sep = std::use_facet<std::numpunct<char_type> >(ios_arg.getloc()).decimal_point(); 414 414 string_type replace_string; 415 415 replace_string += sep; 416 416 replace_string += frac_str; 417 boost::algorithm::replace_all( format,417 boost::algorithm::replace_all(local_format, 418 418 fractional_seconds_or_none_format, 419 419 replace_string); 420 420 } 421 421 else { 422 boost::algorithm::erase_all( format,422 boost::algorithm::erase_all(local_format, 423 423 fractional_seconds_or_none_format); 424 424 } 425 425 } 426 426 427 return this->do_put_tm( a_next, a_ios, a_fill,428 to_tm( a_time),format);427 return this->do_put_tm(next_arg, ios_arg, fill_arg, 428 to_tm(time_arg), local_format); 429 429 } 430 430 431 431 //! put function for time_duration 432 OutItrT put(OutItrT a_next,433 std::ios_base& a_ios,434 char_type a_fill,435 const time_duration_type& a_time_dur) const432 OutItrT put(OutItrT next_arg, 433 std::ios_base& ios_arg, 434 char_type fill_arg, 435 const time_duration_type& time_dur_arg) const 436 436 { 437 if ( a_time_dur.is_special()) {438 return this->do_put_special( a_next, a_ios, a_fill,439 a_time_dur.get_rep().as_special());437 if (time_dur_arg.is_special()) { 438 return this->do_put_special(next_arg, ios_arg, fill_arg, 439 time_dur_arg.get_rep().as_special()); 440 440 } 441 441 442 442 string_type format(m_time_duration_format); 443 if ( a_time_dur.is_negative()) {443 if (time_dur_arg.is_negative()) { 444 444 // replace %- with minus sign. Should we use the numpunct facet? 445 445 boost::algorithm::replace_all(format, 446 446 duration_sign_negative_only, … … 477 477 */ 478 478 string_type hours_str; 479 479 if (format.find(unrestricted_hours_format) != string_type::npos) { 480 hours_str = hours_as_string( a_time_dur);480 hours_str = hours_as_string(time_dur_arg); 481 481 boost::algorithm::replace_all(format, unrestricted_hours_format, hours_str); 482 482 } 483 483 // We still have to process restricted hours format specifier. In order to … … 485 485 // restrict the stringified hours length to 2 characters. 486 486 if (format.find(hours_format) != string_type::npos) { 487 487 if (hours_str.empty()) 488 hours_str = hours_as_string( a_time_dur);488 hours_str = hours_as_string(time_dur_arg); 489 489 BOOST_ASSERT(hours_str.length() <= 2); 490 490 boost::algorithm::replace_all(format, hours_format, hours_str); 491 491 } … … 494 494 if (format.find(seconds_with_fractional_seconds_format) != string_type::npos) { 495 495 // replace %s with %S.nnn 496 496 frac_str = 497 fractional_seconds_as_string( a_time_dur, false);498 char_type sep = std::use_facet<std::numpunct<char_type> >( a_ios.getloc()).decimal_point();497 fractional_seconds_as_string(time_dur_arg, false); 498 char_type sep = std::use_facet<std::numpunct<char_type> >(ios_arg.getloc()).decimal_point(); 499 499 500 500 string_type replace_string(seconds_format); 501 501 replace_string += sep; … … 507 507 if (format.find(fractional_seconds_format) != string_type::npos) { 508 508 // replace %f with nnnnnnn 509 509 if (!frac_str.size()) { 510 frac_str = fractional_seconds_as_string( a_time_dur, false);510 frac_str = fractional_seconds_as_string(time_dur_arg, false); 511 511 } 512 512 boost::algorithm::replace_all(format, 513 513 fractional_seconds_format, … … 517 517 if (format.find(fractional_seconds_or_none_format) != string_type::npos) { 518 518 // replace %F with nnnnnnn or nothing if fs == 0 519 519 frac_str = 520 fractional_seconds_as_string( a_time_dur, true);520 fractional_seconds_as_string(time_dur_arg, true); 521 521 if (frac_str.size()) { 522 char_type sep = std::use_facet<std::numpunct<char_type> >( a_ios.getloc()).decimal_point();522 char_type sep = std::use_facet<std::numpunct<char_type> >(ios_arg.getloc()).decimal_point(); 523 523 string_type replace_string; 524 524 replace_string += sep; 525 525 replace_string += frac_str; … … 533 533 } 534 534 } 535 535 536 return this->do_put_tm( a_next, a_ios, a_fill,537 to_tm( a_time_dur), format);536 return this->do_put_tm(next_arg, ios_arg, fill_arg, 537 to_tm(time_dur_arg), format); 538 538 } 539 539 540 OutItrT put(OutItrT next, std::ios_base& a_ios,540 OutItrT put(OutItrT next, std::ios_base& ios_arg, 541 541 char_type fill, const period_type& p) const 542 542 { 543 return this->m_period_formatter.put_period(next, a_ios, fill,p,*this);543 return this->m_period_formatter.put_period(next, ios_arg, fill,p,*this); 544 544 } 545 545 546 546 … … 548 548 549 549 static 550 550 string_type 551 fractional_seconds_as_string(const time_duration_type& a_time,551 fractional_seconds_as_string(const time_duration_type& time_arg, 552 552 bool null_when_zero) 553 553 { 554 554 typename time_duration_type::fractional_seconds_type frac_sec = 555 a_time.fractional_seconds();555 time_arg.fractional_seconds(); 556 556 557 557 if (null_when_zero && (frac_sec == 0)) { 558 558 return string_type(); … … 566 566 567 567 static 568 568 string_type 569 hours_as_string(const time_duration_type& a_time, int width = 2)569 hours_as_string(const time_duration_type& time_arg, int width = 2) 570 570 { 571 return integral_as_string(date_time::absolute_value( a_time.hours()), width);571 return integral_as_string(date_time::absolute_value(time_arg.hours()), width); 572 572 } 573 573 574 574 template< typename IntT > … … 731 731 static std::locale::id id; 732 732 733 733 //! Constructor that takes a format string for a ptime 734 explicit time_input_facet(const string_type& format, ::size_t a_ref= 0)735 : base_type(format, a_ref),734 explicit time_input_facet(const string_type& format, ::size_t ref_arg = 0) 735 : base_type(format, ref_arg), 736 736 m_time_duration_format(default_time_duration_format) 737 737 { } 738 738 … … 741 741 const special_values_parser_type& sv_parser, 742 742 const period_parser_type& per_parser, 743 743 const date_gen_parser_type& date_gen_parser, 744 ::size_t a_ref= 0)744 ::size_t ref_arg = 0) 745 745 : base_type(format, 746 746 date_parser, 747 747 sv_parser, 748 748 per_parser, 749 749 date_gen_parser, 750 a_ref),750 ref_arg), 751 751 m_time_duration_format(default_time_duration_format) 752 752 {} 753 753 754 754 //! sets default formats for ptime, local_date_time, and time_duration 755 explicit time_input_facet(::size_t a_ref= 0)756 : base_type(default_time_input_format, a_ref),755 explicit time_input_facet(::size_t ref_arg = 0) 756 : base_type(default_time_input_format, ref_arg), 757 757 m_time_duration_format(default_time_duration_format) 758 758 { } 759 759 … … 772 772 773 773 InItrT get(InItrT& sitr, 774 774 InItrT& stream_end, 775 std::ios_base& a_ios,775 std::ios_base& ios_arg, 776 776 period_type& p) const 777 777 { 778 778 p = this->m_period_parser.get_period(sitr, 779 779 stream_end, 780 a_ios,780 ios_arg, 781 781 p, 782 782 time_duration_type::unit(), 783 783 *this); … … 789 789 790 790 InItrT get(InItrT& sitr, 791 791 InItrT& stream_end, 792 std::ios_base& a_ios,792 std::ios_base& ios_arg, 793 793 time_duration_type& td) const 794 794 { 795 795 // skip leading whitespace … … 813 813 typename time_duration_type::fractional_seconds_type frac(0); 814 814 815 815 typedef std::num_get<CharT, InItrT> num_get; 816 if(!std::has_facet<num_get>( a_ios.getloc())) {816 if(!std::has_facet<num_get>(ios_arg.getloc())) { 817 817 num_get* ng = new num_get(); 818 std::locale loc = std::locale( a_ios.getloc(), ng);819 a_ios.imbue(loc);818 std::locale loc = std::locale(ios_arg.getloc(), ng); 819 ios_arg.imbue(loc); 820 820 } 821 821 822 822 const_itr itr(m_time_duration_format.begin()); … … 928 928 //! Parses a time object from the input stream 929 929 InItrT get(InItrT& sitr, 930 930 InItrT& stream_end, 931 std::ios_base& a_ios,931 std::ios_base& ios_arg, 932 932 time_type& t) const 933 933 { 934 934 string_type tz_str; 935 return get(sitr, stream_end, a_ios, t, tz_str, false);935 return get(sitr, stream_end, ios_arg, t, tz_str, false); 936 936 } 937 937 //! Expects a time_zone in the input stream 938 938 InItrT get_local_time(InItrT& sitr, 939 939 InItrT& stream_end, 940 std::ios_base& a_ios,940 std::ios_base& ios_arg, 941 941 time_type& t, 942 942 string_type& tz_str) const 943 943 { 944 return get(sitr, stream_end, a_ios, t, tz_str, true);944 return get(sitr, stream_end, ios_arg, t, tz_str, true); 945 945 } 946 946 947 947 protected: 948 948 949 949 InItrT get(InItrT& sitr, 950 950 InItrT& stream_end, 951 std::ios_base& a_ios,951 std::ios_base& ios_arg, 952 952 time_type& t, 953 953 string_type& tz_str, 954 954 bool time_is_local) const … … 985 985 day_type t_day(1); 986 986 987 987 typedef std::num_get<CharT, InItrT> num_get; 988 if(!std::has_facet<num_get>( a_ios.getloc())) {988 if(!std::has_facet<num_get>(ios_arg.getloc())) { 989 989 num_get* ng = new num_get(); 990 std::locale loc = std::locale( a_ios.getloc(), ng);991 a_ios.imbue(loc);990 std::locale loc = std::locale(ios_arg.getloc(), ng); 991 ios_arg.imbue(loc); 992 992 } 993 993 994 994 const_itr itr(this->m_format.begin());