parsers.hpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef GREGORIAN_PARSERS_HPP___
  2. #define GREGORIAN_PARSERS_HPP___
  3. /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
  4. * Use, modification and distribution is subject to the
  5. * Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. * Author: Jeff Garland, Bart Garst
  8. * $Date$
  9. */
  10. #include "boost/date_time/gregorian/gregorian_types.hpp"
  11. #include "boost/date_time/date_parsing.hpp"
  12. #include "boost/date_time/compiler_config.hpp"
  13. #include "boost/date_time/parse_format_base.hpp"
  14. #include <string>
  15. #include <sstream>
  16. namespace boost {
  17. namespace gregorian {
  18. //! Return special_value from string argument
  19. /*! Return special_value from string argument. If argument is
  20. * not one of the special value names (defined in src/gregorian/names.hpp),
  21. * return 'not_special' */
  22. BOOST_DATE_TIME_DECL special_values special_value_from_string(const std::string& s);
  23. //! Deprecated: Use from_simple_string
  24. inline date from_string(std::string s) {
  25. return date_time::parse_date<date>(s);
  26. }
  27. //! From delimited date string where with order year-month-day eg: 2002-1-25 or 2003-Jan-25 (full month name is also accepted)
  28. inline date from_simple_string(std::string s) {
  29. return date_time::parse_date<date>(s, date_time::ymd_order_iso);
  30. }
  31. //! From delimited date string where with order year-month-day eg: 1-25-2003 or Jan-25-2003 (full month name is also accepted)
  32. inline date from_us_string(std::string s) {
  33. return date_time::parse_date<date>(s, date_time::ymd_order_us);
  34. }
  35. //! From delimited date string where with order day-month-year eg: 25-1-2002 or 25-Jan-2003 (full month name is also accepted)
  36. inline date from_uk_string(std::string s) {
  37. return date_time::parse_date<date>(s, date_time::ymd_order_dmy);
  38. }
  39. //! From iso type date string where with order year-month-day eg: 20020125
  40. inline date from_undelimited_string(std::string s) {
  41. return date_time::parse_undelimited_date<date>(s);
  42. }
  43. //! From iso type date string where with order year-month-day eg: 20020125
  44. inline date date_from_iso_string(const std::string& s) {
  45. return date_time::parse_undelimited_date<date>(s);
  46. }
  47. #if !(defined(BOOST_NO_STD_ITERATOR_TRAITS))
  48. //! Stream should hold a date in the form of: 2002-1-25. Month number, abbrev, or name are accepted
  49. /* Arguments passed in by-value for convertability of char[]
  50. * to iterator_type. Calls to from_stream_type are by-reference
  51. * since conversion is already done */
  52. template<class iterator_type>
  53. inline date from_stream(iterator_type beg, iterator_type end) {
  54. if(beg == end)
  55. {
  56. return date(not_a_date_time);
  57. }
  58. typedef typename std::iterator_traits<iterator_type>::value_type value_type;
  59. return date_time::from_stream_type<date>(beg, end, value_type());
  60. }
  61. #endif //BOOST_NO_STD_ITERATOR_TRAITS
  62. #if (defined(_MSC_VER) && (_MSC_VER < 1300))
  63. // This function cannot be compiled with MSVC 6.0 due to internal compiler shorcomings
  64. #else
  65. //! Function to parse a date_period from a string (eg: [2003-Oct-31/2003-Dec-25])
  66. inline date_period date_period_from_string(const std::string& s){
  67. return date_time::from_simple_string_type<date,char>(s);
  68. }
  69. # if !defined(BOOST_NO_STD_WSTRING)
  70. //! Function to parse a date_period from a wstring (eg: [2003-Oct-31/2003-Dec-25])
  71. inline date_period date_period_from_wstring(const std::wstring& s){
  72. return date_time::from_simple_string_type<date,wchar_t>(s);
  73. }
  74. # endif // BOOST_NO_STD_WSTRING
  75. #endif
  76. } } //namespace gregorian
  77. #endif