File indexing completed on 2025-01-30 09:35:24
0001 #ifndef DATE_TIME_STRINGS_FROM_FACET__HPP___
0002 #define DATE_TIME_STRINGS_FROM_FACET__HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <cstring>
0013 #include <sstream>
0014 #include <string>
0015 #include <vector>
0016 #include <locale>
0017 #include <iterator>
0018
0019 namespace boost { namespace date_time {
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 template<typename charT>
0035 std::vector<std::basic_string<charT> >
0036 gather_month_strings(const std::locale& locale, bool short_strings=true)
0037 {
0038 typedef std::basic_string<charT> string_type;
0039 typedef std::vector<string_type> collection_type;
0040 typedef std::ostreambuf_iterator<charT> ostream_iter_type;
0041 typedef std::basic_ostringstream<charT> stringstream_type;
0042 typedef std::time_put<charT> time_put_facet_type;
0043 charT short_fmt[3] = { '%', 'b' };
0044 charT long_fmt[3] = { '%', 'B' };
0045 collection_type months;
0046 string_type outfmt(short_fmt);
0047 if (!short_strings) {
0048 outfmt = long_fmt;
0049 }
0050 {
0051
0052
0053 const charT* p_outfmt = outfmt.c_str(), *p_outfmt_end = p_outfmt + outfmt.size();
0054 tm tm_value;
0055 std::memset(&tm_value, 0, sizeof(tm_value));
0056 for (int m=0; m < 12; m++) {
0057 tm_value.tm_mon = m;
0058 stringstream_type ss;
0059 ostream_iter_type oitr(ss);
0060 std::use_facet<time_put_facet_type>(locale).put(oitr, ss, ss.fill(),
0061 &tm_value,
0062 p_outfmt,
0063 p_outfmt_end);
0064 months.push_back(ss.str());
0065 }
0066 }
0067 return months;
0068 }
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 template<typename charT>
0085 std::vector<std::basic_string<charT> >
0086 gather_weekday_strings(const std::locale& locale, bool short_strings=true)
0087 {
0088 typedef std::basic_string<charT> string_type;
0089 typedef std::vector<string_type> collection_type;
0090 typedef std::ostreambuf_iterator<charT> ostream_iter_type;
0091 typedef std::basic_ostringstream<charT> stringstream_type;
0092 typedef std::time_put<charT> time_put_facet_type;
0093 charT short_fmt[3] = { '%', 'a' };
0094 charT long_fmt[3] = { '%', 'A' };
0095
0096 collection_type weekdays;
0097
0098
0099 string_type outfmt(short_fmt);
0100 if (!short_strings) {
0101 outfmt = long_fmt;
0102 }
0103 {
0104
0105
0106 const charT* p_outfmt = outfmt.c_str(), *p_outfmt_end = p_outfmt + outfmt.size();
0107 tm tm_value;
0108 std::memset(&tm_value, 0, sizeof(tm_value));
0109 for (int i=0; i < 7; i++) {
0110 tm_value.tm_wday = i;
0111 stringstream_type ss;
0112 ostream_iter_type oitr(ss);
0113 std::use_facet<time_put_facet_type>(locale).put(oitr, ss, ss.fill(),
0114 &tm_value,
0115 p_outfmt,
0116 p_outfmt_end);
0117
0118 weekdays.push_back(ss.str());
0119 }
0120 }
0121 return weekdays;
0122 }
0123
0124 } }
0125
0126
0127 #endif