Chris@16: #ifndef _DATE_TIME_DATE_FACET__HPP___ Chris@16: #define _DATE_TIME_DATE_FACET__HPP___ Chris@16: Chris@16: /* Copyright (c) 2004-2005 CrystalClear Software, Inc. Chris@16: * Use, modification and distribution is subject to the Chris@16: * Boost Software License, Version 1.0. (See accompanying Chris@16: * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Author: Martin Andrian, Jeff Garland, Bart Garst Chris@101: * $Date$ Chris@16: */ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include // ostreambuf_iterator Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace date_time { Chris@16: Chris@16: Chris@16: /*! Class that provides format based I/O facet for date types. Chris@16: * Chris@16: * This class allows the formatting of dates by using format string. Chris@16: * Format strings are: Chris@16: * Chris@16: * - %A => long_weekday_format - Full name Ex: Tuesday Chris@16: * - %a => short_weekday_format - Three letter abbreviation Ex: Tue Chris@16: * - %B => long_month_format - Full name Ex: October Chris@16: * - %b => short_month_format - Three letter abbreviation Ex: Oct Chris@16: * - %x => standard_format_specifier - defined by the locale Chris@16: * - %Y-%b-%d => default_date_format - YYYY-Mon-dd Chris@16: * Chris@16: * Default month format == %b Chris@16: * Default weekday format == %a Chris@16: */ Chris@16: template > > Chris@16: class date_facet : public std::locale::facet { Chris@16: public: Chris@16: typedef typename date_type::duration_type duration_type; Chris@16: // greg_weekday is gregorian_calendar::day_of_week_type Chris@16: typedef typename date_type::day_of_week_type day_of_week_type; Chris@16: typedef typename date_type::day_type day_type; Chris@16: typedef typename date_type::month_type month_type; Chris@16: typedef boost::date_time::period period_type; Chris@16: typedef std::basic_string string_type; Chris@16: typedef CharT char_type; Chris@16: typedef boost::date_time::period_formatter period_formatter_type; Chris@16: typedef boost::date_time::special_values_formatter special_values_formatter_type; Chris@16: typedef std::vector > input_collection_type; Chris@16: // used for the output of the date_generators Chris@16: typedef date_generator_formatter date_gen_formatter_type; Chris@16: typedef partial_date partial_date_type; Chris@16: typedef nth_kday_of_month nth_kday_type; Chris@16: typedef first_kday_of_month first_kday_type; Chris@16: typedef last_kday_of_month last_kday_type; Chris@16: typedef first_kday_after kday_after_type; Chris@16: typedef first_kday_before kday_before_type; Chris@16: static const char_type long_weekday_format[3]; Chris@16: static const char_type short_weekday_format[3]; Chris@16: static const char_type long_month_format[3]; Chris@16: static const char_type short_month_format[3]; Chris@16: static const char_type default_period_separator[4]; Chris@16: static const char_type standard_format_specifier[3]; Chris@16: static const char_type iso_format_specifier[7]; Chris@16: static const char_type iso_format_extended_specifier[9]; Chris@16: static const char_type default_date_format[9]; // YYYY-Mon-DD Chris@16: static std::locale::id id; Chris@16: Chris@16: #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) Chris@16: std::locale::id& __get_id (void) const { return id; } Chris@16: #endif Chris@16: Chris@16: explicit date_facet(::size_t a_ref = 0) Chris@16: : std::locale::facet(a_ref), Chris@16: //m_format(standard_format_specifier) Chris@16: m_format(default_date_format), Chris@16: m_month_format(short_month_format), Chris@16: m_weekday_format(short_weekday_format) Chris@16: {} Chris@16: Chris@16: explicit date_facet(const char_type* format_str, Chris@16: const input_collection_type& short_names, Chris@16: ::size_t ref_count = 0) Chris@16: : std::locale::facet(ref_count), Chris@16: m_format(format_str), Chris@16: m_month_format(short_month_format), Chris@16: m_weekday_format(short_weekday_format), Chris@16: m_month_short_names(short_names) Chris@16: {} Chris@16: Chris@16: Chris@16: explicit date_facet(const char_type* format_str, Chris@16: period_formatter_type per_formatter = period_formatter_type(), Chris@16: special_values_formatter_type sv_formatter = special_values_formatter_type(), Chris@16: date_gen_formatter_type dg_formatter = date_gen_formatter_type(), Chris@16: ::size_t ref_count = 0) Chris@16: : std::locale::facet(ref_count), Chris@16: m_format(format_str), Chris@16: m_month_format(short_month_format), Chris@16: m_weekday_format(short_weekday_format), Chris@16: m_period_formatter(per_formatter), Chris@16: m_date_gen_formatter(dg_formatter), Chris@16: m_special_values_formatter(sv_formatter) Chris@16: {} Chris@16: void format(const char_type* const format_str) { Chris@16: m_format = format_str; Chris@16: } Chris@16: virtual void set_iso_format() Chris@16: { Chris@16: m_format = iso_format_specifier; Chris@16: } Chris@16: virtual void set_iso_extended_format() Chris@16: { Chris@16: m_format = iso_format_extended_specifier; Chris@16: } Chris@16: void month_format(const char_type* const format_str) { Chris@16: m_month_format = format_str; Chris@16: } Chris@16: void weekday_format(const char_type* const format_str) { Chris@16: m_weekday_format = format_str; Chris@16: } Chris@16: Chris@16: void period_formatter(period_formatter_type per_formatter) { Chris@16: m_period_formatter= per_formatter; Chris@16: } Chris@16: void special_values_formatter(const special_values_formatter_type& svf) Chris@16: { Chris@16: m_special_values_formatter = svf; Chris@16: } Chris@16: void short_weekday_names(const input_collection_type& short_names) Chris@16: { Chris@16: m_weekday_short_names = short_names; Chris@16: } Chris@16: void long_weekday_names(const input_collection_type& long_names) Chris@16: { Chris@16: m_weekday_long_names = long_names; Chris@16: } Chris@16: Chris@16: void short_month_names(const input_collection_type& short_names) Chris@16: { Chris@16: m_month_short_names = short_names; Chris@16: } Chris@16: Chris@16: void long_month_names(const input_collection_type& long_names) Chris@16: { Chris@16: m_month_long_names = long_names; Chris@16: } Chris@16: Chris@16: void date_gen_phrase_strings(const input_collection_type& new_strings, Chris@16: typename date_gen_formatter_type::phrase_elements beg_pos=date_gen_formatter_type::first) Chris@16: { Chris@16: m_date_gen_formatter.elements(new_strings, beg_pos); Chris@16: } Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const date_type& d) const Chris@16: { Chris@16: if (d.is_special()) { Chris@16: return do_put_special(next, a_ios, fill_char, d.as_special()); Chris@16: } Chris@16: //The following line of code required the date to support a to_tm function Chris@16: return do_put_tm(next, a_ios, fill_char, to_tm(d), m_format); Chris@16: } Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const duration_type& dd) const Chris@16: { Chris@16: if (dd.is_special()) { Chris@16: return do_put_special(next, a_ios, fill_char, dd.get_rep().as_special()); Chris@16: } Chris@16: Chris@16: typedef std::num_put num_put; Chris@16: if (std::has_facet(a_ios.getloc())) { Chris@16: return std::use_facet(a_ios.getloc()).put(next, a_ios, fill_char, dd.get_rep().as_number()); Chris@16: } Chris@16: else { Chris@16: num_put* f = new num_put(); Chris@16: std::locale l = std::locale(a_ios.getloc(), f); Chris@16: a_ios.imbue(l); Chris@16: return f->put(next, a_ios, fill_char, dd.get_rep().as_number()); Chris@16: } Chris@16: Chris@16: } Chris@16: Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const month_type& m) const Chris@16: { Chris@16: //if (d.is_special()) { Chris@16: // return do_put_special(next, a_ios, fill_char, d.as_special()); Chris@16: //} Chris@16: //The following line of code required the date to support a to_tm function Chris@16: std::tm dtm; Chris@16: std::memset(&dtm, 0, sizeof(dtm)); Chris@16: dtm.tm_mon = m - 1; Chris@16: return do_put_tm(next, a_ios, fill_char, dtm, m_month_format); Chris@16: } Chris@16: Chris@16: //! puts the day of month Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const day_type& day) const Chris@16: { Chris@16: std::tm dtm; Chris@16: std::memset(&dtm, 0, sizeof(dtm)); Chris@16: dtm.tm_mday = day.as_number(); Chris@16: char_type tmp[3] = {'%','d'}; Chris@16: string_type temp_format(tmp); Chris@16: return do_put_tm(next, a_ios, fill_char, dtm, temp_format); Chris@16: } Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const day_of_week_type& dow) const Chris@16: { Chris@16: //if (d.is_special()) { Chris@16: // return do_put_special(next, a_ios, fill_char, d.as_special()); Chris@16: //} Chris@16: //The following line of code required the date to support a to_tm function Chris@16: std::tm dtm; Chris@16: std::memset(&dtm, 0, sizeof(dtm)); Chris@16: dtm.tm_wday = dow; Chris@16: return do_put_tm(next, a_ios, fill_char, dtm, m_weekday_format); Chris@16: } Chris@16: Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const period_type& p) const Chris@16: { Chris@16: return m_period_formatter.put_period(next, a_ios, fill_char, p, *this); Chris@16: } Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const partial_date_type& pd) const Chris@16: { Chris@16: return m_date_gen_formatter.put_partial_date(next, a_ios, fill_char, pd, *this); Chris@16: } Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const nth_kday_type& nkd) const Chris@16: { Chris@16: return m_date_gen_formatter.put_nth_kday(next, a_ios, fill_char, nkd, *this); Chris@16: } Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const first_kday_type& fkd) const Chris@16: { Chris@16: return m_date_gen_formatter.put_first_kday(next, a_ios, fill_char, fkd, *this); Chris@16: } Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const last_kday_type& lkd) const Chris@16: { Chris@16: return m_date_gen_formatter.put_last_kday(next, a_ios, fill_char, lkd, *this); Chris@16: } Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const kday_before_type& fkb) const Chris@16: { Chris@16: return m_date_gen_formatter.put_kday_before(next, a_ios, fill_char, fkb, *this); Chris@16: } Chris@16: Chris@16: OutItrT put(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const kday_after_type& fka) const Chris@16: { Chris@16: return m_date_gen_formatter.put_kday_after(next, a_ios, fill_char, fka, *this); Chris@16: } Chris@16: Chris@16: protected: Chris@16: virtual OutItrT do_put_special(OutItrT next, Chris@16: std::ios_base& /*a_ios*/, Chris@16: char_type /*fill_char*/, Chris@16: const boost::date_time::special_values sv) const Chris@16: { Chris@16: m_special_values_formatter.put_special(next, sv); Chris@16: return next; Chris@16: } Chris@16: virtual OutItrT do_put_tm(OutItrT next, Chris@16: std::ios_base& a_ios, Chris@16: char_type fill_char, Chris@16: const tm& tm_value, Chris@16: string_type a_format) const Chris@16: { Chris@16: // update format string with custom names Chris@16: if (m_weekday_long_names.size()) { Chris@16: boost::algorithm::replace_all(a_format, Chris@16: long_weekday_format, Chris@16: m_weekday_long_names[tm_value.tm_wday]); Chris@16: } Chris@16: if (m_weekday_short_names.size()) { Chris@16: boost::algorithm::replace_all(a_format, Chris@16: short_weekday_format, Chris@16: m_weekday_short_names[tm_value.tm_wday]); Chris@16: Chris@16: } Chris@16: if (m_month_long_names.size()) { Chris@16: boost::algorithm::replace_all(a_format, Chris@16: long_month_format, Chris@16: m_month_long_names[tm_value.tm_mon]); Chris@16: } Chris@16: if (m_month_short_names.size()) { Chris@16: boost::algorithm::replace_all(a_format, Chris@16: short_month_format, Chris@16: m_month_short_names[tm_value.tm_mon]); Chris@16: } Chris@16: // use time_put facet to create final string Chris@16: const char_type* p_format = a_format.c_str(); Chris@16: return std::use_facet >(a_ios.getloc()).put(next, a_ios, Chris@16: fill_char, Chris@16: &tm_value, Chris@16: p_format, Chris@16: p_format + a_format.size()); Chris@16: } Chris@16: protected: Chris@16: string_type m_format; Chris@16: string_type m_month_format; Chris@16: string_type m_weekday_format; Chris@16: period_formatter_type m_period_formatter; Chris@16: date_gen_formatter_type m_date_gen_formatter; Chris@16: special_values_formatter_type m_special_values_formatter; Chris@16: input_collection_type m_month_short_names; Chris@16: input_collection_type m_month_long_names; Chris@16: input_collection_type m_weekday_short_names; Chris@16: input_collection_type m_weekday_long_names; Chris@16: private: Chris@16: }; Chris@16: Chris@16: template Chris@16: std::locale::id date_facet::id; Chris@16: Chris@16: template Chris@16: const typename date_facet::char_type Chris@16: date_facet::long_weekday_format[3] = {'%','A'}; Chris@16: Chris@16: template Chris@16: const typename date_facet::char_type Chris@16: date_facet::short_weekday_format[3] = {'%','a'}; Chris@16: Chris@16: template Chris@16: const typename date_facet::char_type Chris@16: date_facet::long_month_format[3] = {'%','B'}; Chris@16: Chris@16: template Chris@16: const typename date_facet::char_type Chris@16: date_facet::short_month_format[3] = {'%','b'}; Chris@16: Chris@16: template Chris@16: const typename date_facet::char_type Chris@16: date_facet::default_period_separator[4] = { ' ', '/', ' '}; Chris@16: Chris@16: template Chris@16: const typename date_facet::char_type Chris@16: date_facet::standard_format_specifier[3] = Chris@16: {'%', 'x' }; Chris@16: Chris@16: template Chris@16: const typename date_facet::char_type Chris@16: date_facet::iso_format_specifier[7] = Chris@16: {'%', 'Y', '%', 'm', '%', 'd' }; Chris@16: Chris@16: template Chris@16: const typename date_facet::char_type Chris@16: date_facet::iso_format_extended_specifier[9] = Chris@16: {'%', 'Y', '-', '%', 'm', '-', '%', 'd' }; Chris@16: Chris@16: template Chris@16: const typename date_facet::char_type Chris@16: date_facet::default_date_format[9] = Chris@16: {'%','Y','-','%','b','-','%','d'}; Chris@16: Chris@16: Chris@16: Chris@16: //! Input facet Chris@16: template > > Chris@16: class date_input_facet : public std::locale::facet { Chris@16: public: Chris@16: typedef typename date_type::duration_type duration_type; Chris@16: // greg_weekday is gregorian_calendar::day_of_week_type Chris@16: typedef typename date_type::day_of_week_type day_of_week_type; Chris@16: typedef typename date_type::day_type day_type; Chris@16: typedef typename date_type::month_type month_type; Chris@16: typedef typename date_type::year_type year_type; Chris@16: typedef boost::date_time::period period_type; Chris@16: typedef std::basic_string string_type; Chris@16: typedef CharT char_type; Chris@16: typedef boost::date_time::period_parser period_parser_type; Chris@16: typedef boost::date_time::special_values_parser special_values_parser_type; Chris@16: typedef std::vector > input_collection_type; Chris@16: typedef format_date_parser format_date_parser_type; Chris@16: // date_generators stuff goes here Chris@16: typedef date_generator_parser date_gen_parser_type; Chris@16: typedef partial_date partial_date_type; Chris@16: typedef nth_kday_of_month nth_kday_type; Chris@16: typedef first_kday_of_month first_kday_type; Chris@16: typedef last_kday_of_month last_kday_type; Chris@16: typedef first_kday_after kday_after_type; Chris@16: typedef first_kday_before kday_before_type; Chris@16: Chris@16: static const char_type long_weekday_format[3]; Chris@16: static const char_type short_weekday_format[3]; Chris@16: static const char_type long_month_format[3]; Chris@16: static const char_type short_month_format[3]; Chris@16: static const char_type four_digit_year_format[3]; Chris@16: static const char_type two_digit_year_format[3]; Chris@16: static const char_type default_period_separator[4]; Chris@16: static const char_type standard_format_specifier[3]; Chris@16: static const char_type iso_format_specifier[7]; Chris@16: static const char_type iso_format_extended_specifier[9]; Chris@16: static const char_type default_date_format[9]; // YYYY-Mon-DD Chris@16: static std::locale::id id; Chris@16: Chris@16: explicit date_input_facet(::size_t a_ref = 0) Chris@16: : std::locale::facet(a_ref), Chris@16: m_format(default_date_format), Chris@16: m_month_format(short_month_format), Chris@16: m_weekday_format(short_weekday_format), Chris@16: m_year_format(four_digit_year_format), Chris@16: m_parser(m_format, std::locale::classic()) Chris@16: // default period_parser & special_values_parser used Chris@16: {} Chris@16: Chris@16: explicit date_input_facet(const string_type& format_str, Chris@16: ::size_t a_ref = 0) Chris@16: : std::locale::facet(a_ref), Chris@16: m_format(format_str), Chris@16: m_month_format(short_month_format), Chris@16: m_weekday_format(short_weekday_format), Chris@16: m_year_format(four_digit_year_format), Chris@16: m_parser(m_format, std::locale::classic()) Chris@16: // default period_parser & special_values_parser used Chris@16: {} Chris@16: Chris@16: explicit date_input_facet(const string_type& format_str, Chris@16: const format_date_parser_type& date_parser, Chris@16: const special_values_parser_type& sv_parser, Chris@16: const period_parser_type& per_parser, Chris@16: const date_gen_parser_type& date_gen_parser, Chris@16: ::size_t ref_count = 0) Chris@16: : std::locale::facet(ref_count), Chris@16: m_format(format_str), Chris@16: m_month_format(short_month_format), Chris@16: m_weekday_format(short_weekday_format), Chris@16: m_year_format(four_digit_year_format), Chris@16: m_parser(date_parser), Chris@16: m_date_gen_parser(date_gen_parser), Chris@16: m_period_parser(per_parser), Chris@16: m_sv_parser(sv_parser) Chris@16: {} Chris@16: Chris@16: Chris@16: void format(const char_type* const format_str) { Chris@16: m_format = format_str; Chris@16: } Chris@16: virtual void set_iso_format() Chris@16: { Chris@16: m_format = iso_format_specifier; Chris@16: } Chris@16: virtual void set_iso_extended_format() Chris@16: { Chris@16: m_format = iso_format_extended_specifier; Chris@16: } Chris@16: void month_format(const char_type* const format_str) { Chris@16: m_month_format = format_str; Chris@16: } Chris@16: void weekday_format(const char_type* const format_str) { Chris@16: m_weekday_format = format_str; Chris@16: } Chris@16: void year_format(const char_type* const format_str) { Chris@16: m_year_format = format_str; Chris@16: } Chris@16: Chris@16: void period_parser(period_parser_type per_parser) { Chris@16: m_period_parser = per_parser; Chris@16: } Chris@16: void short_weekday_names(const input_collection_type& weekday_names) Chris@16: { Chris@16: m_parser.short_weekday_names(weekday_names); Chris@16: } Chris@16: void long_weekday_names(const input_collection_type& weekday_names) Chris@16: { Chris@16: m_parser.long_weekday_names(weekday_names); Chris@16: } Chris@16: Chris@16: void short_month_names(const input_collection_type& month_names) Chris@16: { Chris@16: m_parser.short_month_names(month_names); Chris@16: } Chris@16: Chris@16: void long_month_names(const input_collection_type& month_names) Chris@16: { Chris@16: m_parser.long_month_names(month_names); Chris@16: } Chris@16: Chris@16: void date_gen_element_strings(const input_collection_type& col) Chris@16: { Chris@16: m_date_gen_parser.element_strings(col); Chris@16: } Chris@16: void date_gen_element_strings(const string_type& first, Chris@16: const string_type& second, Chris@16: const string_type& third, Chris@16: const string_type& fourth, Chris@16: const string_type& fifth, Chris@16: const string_type& last, Chris@16: const string_type& before, Chris@16: const string_type& after, Chris@16: const string_type& of) Chris@16: Chris@16: { Chris@16: m_date_gen_parser.element_strings(first,second,third,fourth,fifth,last,before,after,of); Chris@16: } Chris@16: Chris@16: void special_values_parser(special_values_parser_type sv_parser) Chris@16: { Chris@16: m_sv_parser = sv_parser; Chris@16: } Chris@16: Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& /*a_ios*/, Chris@16: date_type& d) const Chris@16: { Chris@16: d = m_parser.parse_date(from, to, m_format, m_sv_parser); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& /*a_ios*/, Chris@16: month_type& m) const Chris@16: { Chris@16: m = m_parser.parse_month(from, to, m_month_format); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& /*a_ios*/, Chris@16: day_of_week_type& wd) const Chris@16: { Chris@16: wd = m_parser.parse_weekday(from, to, m_weekday_format); Chris@16: return from; Chris@16: } Chris@16: //! Expects 1 or 2 digit day range: 1-31 Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& /*a_ios*/, Chris@16: day_type& d) const Chris@16: { Chris@16: d = m_parser.parse_var_day_of_month(from, to); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& /*a_ios*/, Chris@16: year_type& y) const Chris@16: { Chris@16: y = m_parser.parse_year(from, to, m_year_format); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& a_ios, Chris@16: duration_type& dd) const Chris@16: { Chris@16: // skip leading whitespace Chris@16: while(std::isspace(*from) && from != to) { ++from; } Chris@16: Chris@16: /* num_get.get() will always consume the first character if it Chris@16: * is a sign indicator (+/-). Special value strings may begin Chris@16: * with one of these signs so we'll need a copy of it Chris@16: * in case num_get.get() fails. */ Chris@16: char_type c = '\0'; Chris@16: // TODO Are these characters somewhere in the locale? Chris@16: if(*from == '-' || *from == '+') { Chris@16: c = *from; Chris@16: } Chris@16: typedef std::num_get num_get; Chris@16: typename duration_type::duration_rep_type val = 0; Chris@16: std::ios_base::iostate err = std::ios_base::goodbit; Chris@16: Chris@16: if (std::has_facet(a_ios.getloc())) { Chris@16: from = std::use_facet(a_ios.getloc()).get(from, to, a_ios, err, val); Chris@16: } Chris@16: else { Chris@16: num_get* ng = new num_get(); Chris@16: std::locale l = std::locale(a_ios.getloc(), ng); Chris@16: a_ios.imbue(l); Chris@16: from = ng->get(from, to, a_ios, err, val); Chris@16: } Chris@16: if(err & std::ios_base::failbit){ Chris@16: typedef typename special_values_parser_type::match_results match_results; Chris@16: match_results mr; Chris@16: if(c == '-' || c == '+') { // was the first character consumed? Chris@16: mr.cache += c; Chris@16: } Chris@16: m_sv_parser.match(from, to, mr); Chris@16: if(mr.current_match == match_results::PARSE_ERROR) { Chris@16: boost::throw_exception(std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'")); Chris@16: BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return from); // should never reach Chris@16: } Chris@16: dd = duration_type(static_cast(mr.current_match)); Chris@16: } Chris@16: else { Chris@16: dd = duration_type(val); Chris@16: } Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& a_ios, Chris@16: period_type& p) const Chris@16: { Chris@16: p = m_period_parser.get_period(from, to, a_ios, p, duration_type::unit(), *this); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& a_ios, Chris@16: nth_kday_type& nkd) const Chris@16: { Chris@16: nkd = m_date_gen_parser.get_nth_kday_type(from, to, a_ios, *this); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& a_ios, Chris@16: partial_date_type& pd) const Chris@16: { Chris@16: Chris@16: pd = m_date_gen_parser.get_partial_date_type(from, to, a_ios, *this); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& a_ios, Chris@16: first_kday_type& fkd) const Chris@16: { Chris@16: fkd = m_date_gen_parser.get_first_kday_type(from, to, a_ios, *this); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& a_ios, Chris@16: last_kday_type& lkd) const Chris@16: { Chris@16: lkd = m_date_gen_parser.get_last_kday_type(from, to, a_ios, *this); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& a_ios, Chris@16: kday_before_type& fkb) const Chris@16: { Chris@16: fkb = m_date_gen_parser.get_kday_before_type(from, to, a_ios, *this); Chris@16: return from; Chris@16: } Chris@16: InItrT get(InItrT& from, Chris@16: InItrT& to, Chris@16: std::ios_base& a_ios, Chris@16: kday_after_type& fka) const Chris@16: { Chris@16: fka = m_date_gen_parser.get_kday_after_type(from, to, a_ios, *this); Chris@16: return from; Chris@16: } Chris@16: Chris@16: protected: Chris@16: string_type m_format; Chris@16: string_type m_month_format; Chris@16: string_type m_weekday_format; Chris@16: string_type m_year_format; Chris@16: format_date_parser_type m_parser; Chris@16: date_gen_parser_type m_date_gen_parser; Chris@16: period_parser_type m_period_parser; Chris@16: special_values_parser_type m_sv_parser; Chris@16: private: Chris@16: }; Chris@16: Chris@16: Chris@16: template Chris@16: std::locale::id date_input_facet::id; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::long_weekday_format[3] = {'%','A'}; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::short_weekday_format[3] = {'%','a'}; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::long_month_format[3] = {'%','B'}; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::short_month_format[3] = {'%','b'}; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::four_digit_year_format[3] = {'%','Y'}; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::two_digit_year_format[3] = {'%','y'}; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::default_period_separator[4] = { ' ', '/', ' '}; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::standard_format_specifier[3] = Chris@16: {'%', 'x' }; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::iso_format_specifier[7] = Chris@16: {'%', 'Y', '%', 'm', '%', 'd' }; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::iso_format_extended_specifier[9] = Chris@16: {'%', 'Y', '-', '%', 'm', '-', '%', 'd' }; Chris@16: Chris@16: template Chris@16: const typename date_input_facet::char_type Chris@16: date_input_facet::default_date_format[9] = Chris@16: {'%','Y','-','%','b','-','%','d'}; Chris@16: Chris@16: } } // namespaces Chris@16: Chris@16: Chris@16: #endif