CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/ParameterSet/interface/split.h

Go to the documentation of this file.
00001 #ifndef ParameterSet_split_h
00002 #define ParameterSet_split_h
00003 
00004 // ----------------------------------------------------------------------
00005 // definition of split() and related templates
00006 // ----------------------------------------------------------------------
00007 
00008 
00009 // ----------------------------------------------------------------------
00010 // prolog
00011 
00012 
00013 // ----------------------------------------------------------------------
00014 // prerequisite source files and headers
00015 
00016 #include <string>
00017 
00018 
00019 // ----------------------------------------------------------------------
00020 // contents
00021 
00022 namespace edm  {
00023 
00024   template< class FwdIter >
00025   FwdIter
00026     contextual_find(FwdIter b, FwdIter e
00027                    , char first, char sep, char last);
00028 
00029   template< class FwdIter >
00030   FwdIter
00031     contextual_find_not(FwdIter b, FwdIter e
00032                        , char first, char sep, char last);
00033 
00034   template< class OutIter >
00035   bool
00036     split(OutIter result
00037          , std::string const& string_to_split
00038          , char first, char sep, char last);
00039 
00040 }  // namespace edm
00041 
00042 
00043 // ----------------------------------------------------------------------
00044 // contextual_find
00045 
00046 template< class FwdIter >
00047 FwdIter
00048   edm::contextual_find(FwdIter b, FwdIter e
00049                       , char first, char sep, char last)
00050 {
00051   for(int  nested = 0;  b != e;  ++b)  {
00052     if(*b == first)
00053       ++nested;
00054     else if(*b == last)
00055       --nested;
00056     else if(*b == sep  &&  nested == 0)
00057       return b;
00058   }
00059 
00060   return e;
00061 
00062 }  // contextual_find()
00063 
00064 
00065 // ----------------------------------------------------------------------
00066 // contextual_find_not
00067 
00068 template< class FwdIter >
00069 FwdIter
00070   edm::contextual_find_not(FwdIter b, FwdIter e
00071                           , char /* first */ , char sep, char /* last */)
00072 {
00073   for(;  b != e;  ++b)  {
00074     if(*b != sep)
00075       return b;
00076   }
00077 
00078   return e;
00079 
00080 }  // contextual_find_not()
00081 
00082 
00083 // ----------------------------------------------------------------------
00084 // split()
00085 
00086 template< class OutIter >
00087 bool
00088   edm::split(OutIter dest, std::string const& s
00089             , char first, char sep, char last)
00090 {
00091   typedef  std::string::const_iterator  str_c_iter;
00092   str_c_iter  b = s.begin()
00093            ,  e = s.end();
00094 
00095   if(static_cast<unsigned int>(e - b) < 2u)  return false;
00096 
00097   if(*b == first)  ++b;
00098   else               return false;
00099 
00100   if(*--e != last)  return false;
00101 
00102   // invariant:  we've found all items in [b..boi)
00103   for(str_c_iter  //boi = std::find_if(b, e, is_not_a(sep))
00104                    boi = contextual_find_not(b, e, first, sep, last)
00105                 ,  eoi
00106      ; boi != e
00107      //; boi = std::find_if(eoi, e, is_not_a(sep))
00108      ; boi = contextual_find_not(eoi, e, first, sep, last))
00109   {
00110     // find end of current item:
00111     //eoi = std::find_if(boi, e, is_a(sep));
00112     eoi = contextual_find(boi, e, first, sep, last);
00113 
00114     // copy the item formed from characters in [boi..eoi):
00115     *dest++ = std::string(boi, eoi);
00116   }  // for
00117 
00118   return true;
00119 }  // split< >()
00120 
00121 
00122 // ----------------------------------------------------------------------
00123 // epilog
00124 
00125 #endif