Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:35

0001 #ifndef GREGORIAN_PARSERS_HPP___
0002 #define GREGORIAN_PARSERS_HPP___
0003 
0004 /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the 
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland, Bart Garst
0009  * $Date$
0010  */
0011 
0012 #include <boost/date_time/gregorian/gregorian_types.hpp>
0013 #include <boost/date_time/date_parsing.hpp>
0014 #include <boost/date_time/compiler_config.hpp>
0015 #include <boost/date_time/parse_format_base.hpp>
0016 #include <boost/date_time/special_defs.hpp>
0017 #include <boost/date_time/find_match.hpp>
0018 #include <string>
0019 #include <iterator>
0020 
0021 namespace boost {
0022 namespace gregorian {
0023 
0024   //! Return special_value from string argument
0025   /*! Return special_value from string argument. If argument is
0026    * not one of the special value names (defined in names.hpp),
0027    * return 'not_special' */
0028   inline
0029   date_time::special_values
0030   special_value_from_string(const std::string& s) {
0031     static const char* const special_value_names[date_time::NumSpecialValues]
0032       = {"not-a-date-time","-infinity","+infinity","min_date_time",
0033          "max_date_time","not_special"};
0034 
0035     short i = date_time::find_match(special_value_names,
0036                                     special_value_names,
0037                                     date_time::NumSpecialValues,
0038                                     s);
0039     if(i >= date_time::NumSpecialValues) { // match not found
0040       return date_time::not_special;
0041     }
0042     else {
0043       return static_cast<date_time::special_values>(i);
0044     }
0045   }
0046 
0047   //! Deprecated: Use from_simple_string
0048   inline date from_string(const std::string& s) {
0049     return date_time::parse_date<date>(s);
0050   }
0051 
0052   //! From delimited date string where with order year-month-day eg: 2002-1-25 or 2003-Jan-25 (full month name is also accepted)
0053   inline date from_simple_string(const std::string& s) {
0054     return date_time::parse_date<date>(s, date_time::ymd_order_iso);
0055   }
0056   
0057   //! From delimited date string where with order year-month-day eg: 1-25-2003 or Jan-25-2003 (full month name is also accepted)
0058   inline date from_us_string(const std::string& s) {
0059     return date_time::parse_date<date>(s, date_time::ymd_order_us);
0060   }
0061   
0062   //! From delimited date string where with order day-month-year eg: 25-1-2002 or 25-Jan-2003 (full month name is also accepted)
0063   inline date from_uk_string(const std::string& s) {
0064     return date_time::parse_date<date>(s, date_time::ymd_order_dmy);
0065   }
0066   
0067   //! From ISO 8601 type date string where with order year-month-day eg: 20020125
0068   inline date from_undelimited_string(const std::string& s) {
0069     return date_time::parse_undelimited_date<date>(s);
0070   }
0071 
0072   //! From ISO 8601 type date string where with order year-month-day eg: 20020125
0073   inline date date_from_iso_string(const std::string& s) {
0074     return date_time::parse_undelimited_date<date>(s);
0075   }
0076 
0077 #if !(defined(BOOST_NO_STD_ITERATOR_TRAITS))
0078   //! Stream should hold a date in the form of: 2002-1-25. Month number, abbrev, or name are accepted
0079   /* Arguments passed in by-value for convertability of char[] 
0080    * to iterator_type. Calls to from_stream_type are by-reference 
0081    * since conversion is already done */
0082   template<class iterator_type>
0083   inline date from_stream(iterator_type beg, iterator_type end) {
0084     if(beg == end)
0085     {
0086       return date(not_a_date_time);
0087     }
0088     typedef typename std::iterator_traits<iterator_type>::value_type value_type;
0089     return  date_time::from_stream_type<date>(beg, end, value_type());
0090   }
0091 #endif //BOOST_NO_STD_ITERATOR_TRAITS
0092   
0093 #if (defined(_MSC_VER) && (_MSC_VER < 1300))
0094     // This function cannot be compiled with MSVC 6.0 due to internal compiler shorcomings
0095 #else
0096   //! Function to parse a date_period from a string (eg: [2003-Oct-31/2003-Dec-25])
0097   inline date_period date_period_from_string(const std::string& s){
0098     return date_time::from_simple_string_type<date,char>(s);
0099   }
0100 #  if !defined(BOOST_NO_STD_WSTRING)
0101   //! Function to parse a date_period from a wstring (eg: [2003-Oct-31/2003-Dec-25])
0102   inline date_period date_period_from_wstring(const std::wstring& s){
0103     return date_time::from_simple_string_type<date,wchar_t>(s);
0104   }
0105 #  endif // BOOST_NO_STD_WSTRING
0106 #endif
0107 
0108 } } //namespace gregorian
0109 
0110 #endif