Go to the documentation of this file.00001 #ifndef ParameterSet_split_h
00002 #define ParameterSet_split_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <string>
00017
00018
00019
00020
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 }
00041
00042
00043
00044
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 }
00063
00064
00065
00066
00067
00068 template< class FwdIter >
00069 FwdIter
00070 edm::contextual_find_not(FwdIter b, FwdIter e
00071 , char , char sep, char )
00072 {
00073 for(; b != e; ++b) {
00074 if(*b != sep)
00075 return b;
00076 }
00077
00078 return e;
00079
00080 }
00081
00082
00083
00084
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
00103 for(str_c_iter
00104 boi = contextual_find_not(b, e, first, sep, last)
00105 , eoi
00106 ; boi != e
00107
00108 ; boi = contextual_find_not(eoi, e, first, sep, last))
00109 {
00110
00111
00112 eoi = contextual_find(boi, e, first, sep, last);
00113
00114
00115 *dest++ = std::string(boi, eoi);
00116 }
00117
00118 return true;
00119 }
00120
00121
00122
00123
00124
00125 #endif