Ticket #4952: time_facet.hpp.diff

File time_facet.hpp.diff, 21.0 KB (added by Rich McKeever <richmckeever@…>, 12 years ago)
  • boost/boost/date_time/time_facet.hpp

  • /

    old new  
    244244#endif
    245245
    246246    //! 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),
    249249        m_time_duration_format(string_type(duration_sign_negative_only) + default_time_duration_format)
    250250    {}
    251251
    252252    //! 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(),
    255255                        const special_values_formatter_type& special_value_formatter = special_values_formatter_type(),
    256256                        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,
    260260                  special_value_formatter,
    261261                  dg_formatter,
    262                   a_ref),
     262                  ref_arg),
    263263        m_time_duration_format(string_type(duration_sign_negative_only) + default_time_duration_format)
    264264    {}
    265265
     
    278278      this->m_format = iso_time_format_extended_specifier;
    279279    }
    280280
    281     OutItrT put(OutItrT a_next,
    282                 std::ios_base& a_ios,
    283                 char_type a_fill,
    284                 const time_type& a_time) const
     281    OutItrT put(OutItrT next_arg,
     282                std::ios_base& ios_arg,
     283                char_type fill_arg,
     284                const time_type& time_arg) const
    285285    {
    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());
    289289      }
    290       string_type format(this->m_format);
     290      string_type local_format(this->m_format);
    291291
    292292      // %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,
    294294        boost::as_literal(formats_type::full_24_hour_time_format),
    295295        boost::as_literal(formats_type::full_24_hour_time_expanded_format));
    296       boost::algorithm::replace_all(format,
     296      boost::algorithm::replace_all(local_format,
    297297        boost::as_literal(formats_type::short_24_hour_time_format),
    298298        boost::as_literal(formats_type::short_24_hour_time_expanded_format));
    299299
    300300      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) {
    302302        // replace %s with %S.nnn
    303303        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();
    306306
    307307        string_type replace_string(seconds_format);
    308308        replace_string += sep;
    309309        replace_string += frac_str;
    310         boost::algorithm::replace_all(format,
     310        boost::algorithm::replace_all(local_format,
    311311                                      seconds_with_fractional_seconds_format,
    312312                                      replace_string);
    313313      }
    314314      /* NOTE: replacing posix_zone_string_format must be done BEFORE
    315315       * zone_name_format: "%ZP" & "%Z", if Z is checked first it will
    316316       * 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()) {
    319319          // if zone_abbrev() returns an empty string, we want to
    320320          // 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);
    322322        }
    323323        else{
    324           boost::algorithm::replace_all(format,
     324          boost::algorithm::replace_all(local_format,
    325325                                        posix_zone_string_format,
    326                                         a_time.zone_as_posix_string());
     326                                        time_arg.zone_as_posix_string());
    327327        }
    328328      }
    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()) {
    331331          /* TODO: this'll probably create problems if a user places
    332332           * the zone_*_format flag in the format with a ptime. This
    333333           * code removes the flag from the default formats */
     
    336336          // erase zone_name_format & one preceeding space
    337337          std::basic_ostringstream<char_type> ss;
    338338          ss << ' ' << zone_name_format;
    339           boost::algorithm::erase_all(format, ss.str());
     339          boost::algorithm::erase_all(local_format, ss.str());
    340340        }
    341341        else{
    342           boost::algorithm::replace_all(format,
     342          boost::algorithm::replace_all(local_format,
    343343                                        zone_name_format,
    344                                         a_time.zone_name());
     344                                        time_arg.zone_name());
    345345        }
    346346      }
    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()) {
    349349          /* TODO: this'll probably create problems if a user places
    350350           * the zone_*_format flag in the format with a ptime. This
    351351           * code removes the flag from the default formats */
     
    354354          // erase zone_abbrev_format & one preceeding space
    355355          std::basic_ostringstream<char_type> ss;
    356356          ss << ' ' << zone_abbrev_format;
    357           boost::algorithm::erase_all(format, ss.str());
     357          boost::algorithm::erase_all(local_format, ss.str());
    358358        }
    359359        else{
    360           boost::algorithm::replace_all(format,
     360          boost::algorithm::replace_all(local_format,
    361361                                        zone_abbrev_format,
    362                                         a_time.zone_abbrev(false));
     362                                        time_arg.zone_abbrev(false));
    363363        }
    364364      }
    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()) {
    367367          /* TODO: this'll probably create problems if a user places
    368368           * the zone_*_format flag in the format with a ptime. This
    369369           * code removes the flag from the default formats */
    370370
    371371          // if zone_name() returns an empty string, we want to
    372372          // 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);
    374374        }
    375375        else{
    376           boost::algorithm::replace_all(format,
     376          boost::algorithm::replace_all(local_format,
    377377                                        zone_iso_extended_format,
    378                                         a_time.zone_name(true));
     378                                        time_arg.zone_name(true));
    379379        }
    380380      }
    381381
    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()) {
    384384          /* TODO: this'll probably create problems if a user places
    385385           * the zone_*_format flag in the format with a ptime. This
    386386           * code removes the flag from the default formats */
    387387
    388388          // if zone_abbrev() returns an empty string, we want to
    389389          // 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);
    391391        }
    392392        else{
    393           boost::algorithm::replace_all(format,
     393          boost::algorithm::replace_all(local_format,
    394394                                        zone_iso_format,
    395                                         a_time.zone_abbrev(true));
     395                                        time_arg.zone_abbrev(true));
    396396        }
    397397      }
    398       if (format.find(fractional_seconds_format) != string_type::npos) {
     398      if (local_format.find(fractional_seconds_format) != string_type::npos) {
    399399        // replace %f with nnnnnnn
    400400        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);
    402402        }
    403         boost::algorithm::replace_all(format,
     403        boost::algorithm::replace_all(local_format,
    404404                                      fractional_seconds_format,
    405405                                      frac_str);
    406406      }
    407407
    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) {
    409409        // replace %F with nnnnnnn or nothing if fs == 0
    410410        frac_str =
    411           fractional_seconds_as_string(a_time.time_of_day(), true);
     411          fractional_seconds_as_string(time_arg.time_of_day(), true);
    412412        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();
    414414          string_type replace_string;
    415415          replace_string += sep;
    416416          replace_string += frac_str;
    417           boost::algorithm::replace_all(format,
     417          boost::algorithm::replace_all(local_format,
    418418                                        fractional_seconds_or_none_format,
    419419                                        replace_string);
    420420        }
    421421        else {
    422           boost::algorithm::erase_all(format,
     422          boost::algorithm::erase_all(local_format,
    423423                                      fractional_seconds_or_none_format);
    424424        }
    425425      }
    426426
    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);
    429429    }
    430430
    431431    //! 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) const
     432    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
    436436    {
    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());
    440440      }
    441441
    442442      string_type format(m_time_duration_format);
    443       if (a_time_dur.is_negative()) {
     443      if (time_dur_arg.is_negative()) {
    444444        // replace %- with minus sign.  Should we use the numpunct facet?
    445445        boost::algorithm::replace_all(format,
    446446                                      duration_sign_negative_only,
     
    477477       */
    478478      string_type hours_str;
    479479      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);
    481481        boost::algorithm::replace_all(format, unrestricted_hours_format, hours_str);
    482482      }
    483483      // We still have to process restricted hours format specifier. In order to
     
    485485      // restrict the stringified hours length to 2 characters.
    486486      if (format.find(hours_format) != string_type::npos) {
    487487        if (hours_str.empty())
    488           hours_str = hours_as_string(a_time_dur);
     488          hours_str = hours_as_string(time_dur_arg);
    489489        BOOST_ASSERT(hours_str.length() <= 2);
    490490        boost::algorithm::replace_all(format, hours_format, hours_str);
    491491      }
     
    494494      if (format.find(seconds_with_fractional_seconds_format) != string_type::npos) {
    495495        // replace %s with %S.nnn
    496496        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();
    499499
    500500        string_type replace_string(seconds_format);
    501501        replace_string += sep;
     
    507507      if (format.find(fractional_seconds_format) != string_type::npos) {
    508508        // replace %f with nnnnnnn
    509509        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);
    511511        }
    512512        boost::algorithm::replace_all(format,
    513513                                      fractional_seconds_format,
     
    517517      if (format.find(fractional_seconds_or_none_format) != string_type::npos) {
    518518        // replace %F with nnnnnnn or nothing if fs == 0
    519519        frac_str =
    520           fractional_seconds_as_string(a_time_dur, true);
     520          fractional_seconds_as_string(time_dur_arg, true);
    521521        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();
    523523          string_type replace_string;
    524524          replace_string += sep;
    525525          replace_string += frac_str;
     
    533533        }
    534534      }
    535535
    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);
    538538    }
    539539
    540     OutItrT put(OutItrT next, std::ios_base& a_ios,
     540    OutItrT put(OutItrT next, std::ios_base& ios_arg,
    541541                char_type fill, const period_type& p) const
    542542    {
    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);
    544544    }
    545545
    546546
     
    548548
    549549    static
    550550    string_type
    551     fractional_seconds_as_string(const time_duration_type& a_time,
     551    fractional_seconds_as_string(const time_duration_type& time_arg,
    552552                                 bool null_when_zero)
    553553    {
    554554      typename time_duration_type::fractional_seconds_type frac_sec =
    555         a_time.fractional_seconds();
     555        time_arg.fractional_seconds();
    556556
    557557      if (null_when_zero && (frac_sec == 0)) {
    558558        return string_type();
     
    566566
    567567    static
    568568    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)
    570570    {
    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);
    572572    }
    573573
    574574    template< typename IntT >
     
    731731      static std::locale::id id;
    732732
    733733      //! 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),
    736736          m_time_duration_format(default_time_duration_format)
    737737      { }
    738738
     
    741741                                const special_values_parser_type& sv_parser,
    742742                                const period_parser_type& per_parser,
    743743                                const date_gen_parser_type& date_gen_parser,
    744                                 ::size_t a_ref = 0)
     744                                ::size_t ref_arg = 0)
    745745        : base_type(format,
    746746                    date_parser,
    747747                    sv_parser,
    748748                    per_parser,
    749749                    date_gen_parser,
    750                     a_ref),
     750                    ref_arg),
    751751          m_time_duration_format(default_time_duration_format)
    752752      {}
    753753
    754754      //! 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),
    757757          m_time_duration_format(default_time_duration_format)
    758758      { }
    759759
     
    772772
    773773      InItrT get(InItrT& sitr,
    774774                 InItrT& stream_end,
    775                  std::ios_base& a_ios,
     775                 std::ios_base& ios_arg,
    776776                 period_type& p) const
    777777      {
    778778        p = this->m_period_parser.get_period(sitr,
    779779                                             stream_end,
    780                                              a_ios,
     780                                             ios_arg,
    781781                                             p,
    782782                                             time_duration_type::unit(),
    783783                                             *this);
     
    789789
    790790      InItrT get(InItrT& sitr,
    791791                 InItrT& stream_end,
    792                  std::ios_base& a_ios,
     792                 std::ios_base& ios_arg,
    793793                 time_duration_type& td) const
    794794      {
    795795        // skip leading whitespace
     
    813813        typename time_duration_type::fractional_seconds_type frac(0);
    814814
    815815        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())) {
    817817          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);
    820820        }
    821821
    822822        const_itr itr(m_time_duration_format.begin());
     
    928928      //! Parses a time object from the input stream
    929929      InItrT get(InItrT& sitr,
    930930                 InItrT& stream_end,
    931                  std::ios_base& a_ios,
     931                 std::ios_base& ios_arg,
    932932                 time_type& t) const
    933933      {
    934934        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);
    936936      }
    937937      //! Expects a time_zone in the input stream
    938938      InItrT get_local_time(InItrT& sitr,
    939939                            InItrT& stream_end,
    940                             std::ios_base& a_ios,
     940                            std::ios_base& ios_arg,
    941941                            time_type& t,
    942942                            string_type& tz_str) const
    943943      {
    944         return get(sitr, stream_end, a_ios, t, tz_str, true);
     944        return get(sitr, stream_end, ios_arg, t, tz_str, true);
    945945      }
    946946
    947947    protected:
    948948
    949949      InItrT get(InItrT& sitr,
    950950                 InItrT& stream_end,
    951                  std::ios_base& a_ios,
     951                 std::ios_base& ios_arg,
    952952                 time_type& t,
    953953                 string_type& tz_str,
    954954                 bool time_is_local) const
     
    985985        day_type t_day(1);
    986986
    987987        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())) {
    989989          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);
    992992        }
    993993
    994994        const_itr itr(this->m_format.begin());