File indexing completed on 2025-01-30 09:35:24
0001
0002 #ifndef DATE_TIME_SPECIAL_VALUES_PARSER_HPP__
0003 #define DATE_TIME_SPECIAL_VALUES_PARSER_HPP__
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "boost/date_time/string_parse_tree.hpp"
0015 #include "boost/date_time/special_defs.hpp"
0016 #include <string>
0017 #include <vector>
0018
0019 namespace boost { namespace date_time {
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 template<class date_type, typename charT>
0033 class special_values_parser
0034 {
0035 public:
0036 typedef std::basic_string<charT> string_type;
0037 typedef std::basic_stringstream<charT> stringstream_type;
0038 typedef std::istreambuf_iterator<charT> stream_itr_type;
0039 typedef typename date_type::duration_type duration_type;
0040 typedef string_parse_tree<charT> parse_tree_type;
0041 typedef typename parse_tree_type::parse_match_result_type match_results;
0042 typedef std::vector<std::basic_string<charT> > collection_type;
0043
0044 typedef charT char_type;
0045 static const char_type nadt_string[16];
0046 static const char_type neg_inf_string[10];
0047 static const char_type pos_inf_string[10];
0048 static const char_type min_date_time_string[18];
0049 static const char_type max_date_time_string[18];
0050
0051
0052 special_values_parser()
0053 {
0054 sv_strings(string_type(nadt_string),
0055 string_type(neg_inf_string),
0056 string_type(pos_inf_string),
0057 string_type(min_date_time_string),
0058 string_type(max_date_time_string));
0059 }
0060
0061
0062 special_values_parser(const string_type& nadt_str,
0063 const string_type& neg_inf_str,
0064 const string_type& pos_inf_str,
0065 const string_type& min_dt_str,
0066 const string_type& max_dt_str)
0067 {
0068 sv_strings(nadt_str, neg_inf_str, pos_inf_str, min_dt_str, max_dt_str);
0069 }
0070
0071 special_values_parser(typename collection_type::iterator beg, typename collection_type::iterator end)
0072 {
0073 collection_type phrases;
0074 std::copy(beg, end, std::back_inserter(phrases));
0075 m_sv_strings = parse_tree_type(phrases, static_cast<int>(not_a_date_time));
0076 }
0077
0078
0079 void sv_strings(const string_type& nadt_str,
0080 const string_type& neg_inf_str,
0081 const string_type& pos_inf_str,
0082 const string_type& min_dt_str,
0083 const string_type& max_dt_str)
0084 {
0085 collection_type phrases;
0086 phrases.push_back(nadt_str);
0087 phrases.push_back(neg_inf_str);
0088 phrases.push_back(pos_inf_str);
0089 phrases.push_back(min_dt_str);
0090 phrases.push_back(max_dt_str);
0091 m_sv_strings = parse_tree_type(phrases, static_cast<int>(not_a_date_time));
0092 }
0093
0094
0095
0096
0097
0098
0099
0100 static bool should_call_match(const string_type& str)
0101 {
0102 if (!str.empty()) {
0103 switch (str[0]) {
0104
0105 case '+':
0106 case '-':
0107 case 'n':
0108 case 'm':
0109 return true;
0110
0111 default:
0112 break;
0113 }
0114 }
0115
0116 return false;
0117 }
0118
0119
0120
0121
0122
0123
0124
0125 bool match(stream_itr_type& sitr,
0126 stream_itr_type& str_end,
0127 match_results& mr) const
0128 {
0129 unsigned int level = 0;
0130 m_sv_strings.match(sitr, str_end, mr, level);
0131 return (mr.current_match != match_results::PARSE_ERROR);
0132 }
0133
0134 private:
0135 parse_tree_type m_sv_strings;
0136
0137 };
0138
0139 template<class date_type, class CharT>
0140 const typename special_values_parser<date_type, CharT>::char_type
0141 special_values_parser<date_type, CharT>::nadt_string[16] =
0142 {'n','o','t','-','a','-','d','a','t','e','-','t','i','m','e'};
0143 template<class date_type, class CharT>
0144 const typename special_values_parser<date_type, CharT>::char_type
0145 special_values_parser<date_type, CharT>::neg_inf_string[10] =
0146 {'-','i','n','f','i','n','i','t','y'};
0147 template<class date_type, class CharT>
0148 const typename special_values_parser<date_type, CharT>::char_type
0149 special_values_parser<date_type, CharT>::pos_inf_string[10] =
0150 {'+','i','n','f','i','n','i','t','y'};
0151 template<class date_type, class CharT>
0152 const typename special_values_parser<date_type, CharT>::char_type
0153 special_values_parser<date_type, CharT>::min_date_time_string[18] =
0154 {'m','i','n','i','m','u','m','-','d','a','t','e','-','t','i','m','e'};
0155 template<class date_type, class CharT>
0156 const typename special_values_parser<date_type, CharT>::char_type
0157 special_values_parser<date_type, CharT>::max_date_time_string[18] =
0158 {'m','a','x','i','m','u','m','-','d','a','t','e','-','t','i','m','e'};
0159
0160 } }
0161
0162 #endif
0163