1 #ifndef _BOOST_DATE_TIME_FIND_MATCH_HPP___ 2 #define _BOOST_DATE_TIME_FIND_MATCH_HPP___ 3 4 /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. 5 * Use, modification and distribution is subject to the 6 * Boost Software License, Version 1.0. (See accompanying 7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 * Author: Jeff Garland, Bart Garst 9 * $Date$ 10 */ 11 12 #include <string> 13 14 namespace boost { 15 namespace date_time { 16 17 18 //! Find index of a string in either of 2 arrays 19 /*! find_match searches both arrays for a match to 's'. Both arrays 20 * must contain 'size' elements. The index of the match is returned. 21 * If no match is found, 'size' is returned. 22 * Ex. "Jan" returns 0, "Dec" returns 11, "Tue" returns 2. 23 * 'size' can be sent in with: (greg_month::max)() (which 12), 24 * (greg_weekday::max)() + 1 (which is 7) or date_time::NumSpecialValues */ 25 template<class charT> find_match(const charT * const * short_names,const charT * const * long_names,short size,const std::basic_string<charT> & s)26 short find_match(const charT* const* short_names, 27 const charT* const* long_names, 28 short size, 29 const std::basic_string<charT>& s) { 30 for(short i = 0; i < size; ++i){ 31 if(short_names[i] == s || long_names[i] == s){ 32 return i; 33 } 34 } 35 return size; // not-found, return a value out of range 36 } 37 38 39 } } //namespace date_time 40 41 42 #endif 43