53 cout <<
"Usage: " << prog <<
" include|exclude|type <regular_expression> <string_to_match>" << endl ;
54 cout <<
" samples:" << endl ;
55 cout <<
" besregtest include \"123456;\" 01234567 matches 6 of 8 characters" << endl ;
56 cout <<
" besregtest include \"^123456$;\" 01234567 does not match" << endl ;
57 cout <<
" besregtest include \"^123456$;\" 123456 matches all 6 of 6 characters" << endl ;
58 cout <<
" besregtest include \".*\\.nc$;\" fnoc1.nc matches" << endl ;
59 cout <<
" besregtest include \".*\\.nc$;\" fnoc1.ncd does not matche" << endl ;
60 cout <<
" besregtest type \"nc:.*\\.nc$;nc:.*\\.nc\\.gz$;ff:.*\\.dat$;ff:.*\\.dat\\.gz$;\" fnoc1.nc matches type nc" << endl ;
64 main(
int argc,
char **argv )
72 string what = argv[1] ;
73 if( what !=
"include" && what !=
"exclude" && what !=
"type" )
75 cout <<
"please specify either an Include or TypeMatch expression " 76 <<
"by using include or type respectively as first parameter" << endl ;
83 if( what ==
"include" || what ==
"exclude" )
95 string inQuestion( argv[3] ) ;
97 multimap<string,string>::const_iterator i = expressions.begin() ;
98 multimap<string,string>::const_iterator ie = expressions.end() ;
100 for( ; i != ie; i++ )
102 string reg = (*i).second ;
106 int result = reg_expr.
match( inQuestion.c_str(), inQuestion.length() ) ;
109 if( result == inQuestion.length() )
111 cout <<
"expression \"" << reg <<
"\" matches exactly" ;
115 cout <<
"expression \"" << reg <<
"\" matches " << result
116 <<
" characters out of " << inQuestion.length()
120 cout <<
", type = " << (*i).first ;
125 cout <<
"expression \"" << reg <<
"\" does not match" ;
127 cout <<
" for type " << (*i).first ;
133 string serr = (string)
"malformed regular expression \"" 135 cout << serr << endl ;
145 string::size_type str_begin = 0 ;
146 string::size_type str_end = listStr.length() ;
147 string::size_type semi = 0 ;
149 while( done ==
false )
151 semi = listStr.find(
";", str_begin ) ;
152 if( semi == string::npos )
154 err = (string)
"regular expression malformed, no semicolon" ;
159 string a_member = listStr.substr( str_begin, semi-str_begin ) ;
161 if( semi == str_end-1 )
167 expressions.insert( pair<string,string>(
"", a_member ) );
178 string::size_type str_begin = 0 ;
179 string::size_type str_end = listStr.length() ;
180 string::size_type semi = 0 ;
182 while( done ==
false )
184 semi = listStr.find(
";", str_begin ) ;
185 if( semi == string::npos )
187 err = (string)
"type match malformed, no semicolon, " 188 +
"looking for type:regexp;[type:regexp;]" ;
193 string a_pair = listStr.substr( str_begin, semi-str_begin ) ;
195 if( semi == str_end-1 )
200 string::size_type col = a_pair.find(
":" ) ;
201 if( col == string::npos )
203 err = (string)
"Catalog type match malformed, no colon, " 204 +
"looking for type:regexp;[type:regexp;]" ;
209 string a_type = a_pair.substr( 0, col ) ;
210 string a_reg = a_pair.substr( col+1, a_pair.length()-col ) ;
211 expressions.insert( pair<string,string>( a_type, a_reg ) ) ;
int main(int argc, char **argv)
int match(const char *s, int len, int pos=0)
Does the pattern match.
a C++ interface to POSIX regular expression functions.
virtual string get_message()
get the error message for this exception
void usage(const string &prog)
Abstract exception class for the BES with basic string message.
bool break_includes(const string &s, string &err)
multimap< string, string > expressions
bool break_types(const string &s, string &err)