find_match.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef _BOOST_DATE_TIME_FIND_MATCH_HPP___
  2. #define _BOOST_DATE_TIME_FIND_MATCH_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 <string>
  11. namespace boost {
  12. namespace date_time {
  13. //! Find index of a string in either of 2 arrays
  14. /*! find_match searches both arrays for a match to 's'. Both arrays
  15. * must contain 'size' elements. The index of the match is returned.
  16. * If no match is found, 'size' is returned.
  17. * Ex. "Jan" returns 0, "Dec" returns 11, "Tue" returns 2.
  18. * 'size' can be sent in with: (greg_month::max)() (which 12),
  19. * (greg_weekday::max)() + 1 (which is 7) or date_time::NumSpecialValues */
  20. template<class charT>
  21. short find_match(const charT* const* short_names,
  22. const charT* const* long_names,
  23. short size,
  24. const std::basic_string<charT>& s) {
  25. for(short i = 0; i < size; ++i){
  26. if(short_names[i] == s || long_names[i] == s){
  27. return i;
  28. }
  29. }
  30. return size; // not-found, return a value out of range
  31. }
  32. } } //namespace date_time
  33. #endif