regexT.cc

Go to the documentation of this file.
00001 // regexT.C
00002 
00003 #include <iostream>
00004 
00005 using std::cerr ;
00006 using std::cout ;
00007 using std::endl ;
00008 
00009 #include "regexT.h"
00010 #include "BESRegex.h"
00011 #include "BESException.h"
00012 
00013 int regexT::
00014 run(void)
00015 {
00016     cout << endl << "*****************************************" << endl;
00017     cout << "Entered regexT::run" << endl;
00018     int retVal = 0;
00019 
00020     try
00021     {
00022         cout << endl << "*****************************************" << endl;
00023         cout << "Match reg ex 123456 against string 01234567" << endl;
00024         BESRegex reg_expr( "123456" ) ;
00025         string inQuestion = "01234567" ;
00026         int result = reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ;
00027         if( result == 6 )
00028         {
00029             cout << "Successfully matched characters" << endl ;
00030         }
00031         else
00032         {
00033             cerr << "Regular expression matched " << result
00034                  << " characets, should have matched 6" << endl ;
00035             return 1 ;
00036         }
00037     }
00038     catch( BESException &e )
00039     {
00040         cerr << "Failed to match, exception caught" << endl << e.get_message() << endl ;
00041         return 1 ;
00042     }
00043     catch( ... )
00044     {
00045         cerr << "Failed to match, unknown exception caught" << endl ;
00046         return 1 ;
00047     }
00048 
00049     try
00050     {
00051         cout << endl << "*****************************************" << endl;
00052         cout << "Match reg ex ^123456$ against string 01234567" << endl;
00053         BESRegex reg_expr( "^123456$" ) ;
00054         string inQuestion = "01234567" ;
00055         int result = reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ;
00056         if( result == -1 )
00057         {
00058             cout << "Does not match, good" << endl ;
00059         }
00060         else
00061         {
00062             cerr << "Regular expression matched " << result
00063                  << " characets, should have matched none" << endl ;
00064             return 1 ;
00065         }
00066     }
00067     catch( BESException &e )
00068     {
00069         cerr << "Failed to match, exception caught" << endl << e.get_message() << endl ;
00070         return 1 ;
00071     }
00072     catch( ... )
00073     {
00074         cerr << "Failed to match, unknown exception caught" << endl ;
00075         return 1 ;
00076     }
00077 
00078     try
00079     {
00080         cout << endl << "*****************************************" << endl;
00081         cout << "Match reg ex ^123456$ against string 123456" << endl;
00082     cout << "    besregtest include \"^123456$;\" 123456 matches all 6 of 6 characters" << endl ;
00083         BESRegex reg_expr( "^123456$" ) ;
00084         string inQuestion = "123456" ;
00085         int result = reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ;
00086         if( result == 6 )
00087         {
00088             cout << "Successfully matched characters" << endl ;
00089         }
00090         else
00091         {
00092             cerr << "Regular expression matched " << result
00093                  << " characets, should have matched 6" << endl ;
00094             return 1 ;
00095         }
00096     }
00097     catch( BESException &e )
00098     {
00099         cerr << "Failed to match, exception caught" << endl << e.get_message() << endl ;
00100         return 1 ;
00101     }
00102     catch( ... )
00103     {
00104         cerr << "Failed to match, unknown exception caught" << endl ;
00105         return 1 ;
00106     }
00107 
00108     try
00109     {
00110         cout << endl << "*****************************************" << endl;
00111         cout << "Match reg ex \".*\\.nc$;\" against string fnoc1.nc" << endl;
00112         BESRegex reg_expr( ".*\\.nc$" ) ;
00113         string inQuestion = "fnoc1.nc" ;
00114         int result = reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ;
00115         if( result == 8 )
00116         {
00117             cout << "Successfully matched characters" << endl ;
00118         }
00119         else
00120         {
00121             cerr << "Regular expression matched " << result
00122                  << " characets, should have matched 8" << endl ;
00123             return 1 ;
00124         }
00125     }
00126     catch( BESException &e )
00127     {
00128         cerr << "Failed to match, exception caught" << endl << e.get_message() << endl ;
00129         return 1 ;
00130     }
00131     catch( ... )
00132     {
00133         cerr << "Failed to match, unknown exception caught" << endl ;
00134         return 1 ;
00135     }
00136 
00137     try
00138     {
00139         cout << endl << "*****************************************" << endl;
00140         cout << "Match reg ex \".*\\.nc$;\" against string fnoc1.ncd" << endl;
00141         BESRegex reg_expr( ".*\\.nc$" ) ;
00142         string inQuestion = "fnoc1.ncd" ;
00143         int result = reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ;
00144         if( result == -1 )
00145         {
00146             cout << "Successfully did not match characters" << endl ;
00147         }
00148         else
00149         {
00150             cerr << "Regular expression matched " << result
00151                  << " characets, should have matched none" << endl ;
00152             return 1 ;
00153         }
00154     }
00155     catch( BESException &e )
00156     {
00157         cerr << "Failed to match, exception caught" << endl << e.get_message() << endl ;
00158         return 1 ;
00159     }
00160     catch( ... )
00161     {
00162         cerr << "Failed to match, unknown exception caught" << endl ;
00163         return 1 ;
00164     }
00165 
00166     try
00167     {
00168         cout << endl << "*****************************************" << endl;
00169         cout << "Match reg ex .*\\.(nc|NC)(\\.gz|\\.bz2|\\.Z)?$ against string fnoc1.nc" << endl;
00170         BESRegex reg_expr( ".*\\.(nc|NC)(\\.gz|\\.bz2|\\.Z)?$" ) ;
00171         string inQuestion = "fnoc1.nc" ;
00172         int result = reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ;
00173         if( result == 8 )
00174         {
00175             cout << "Successfully matched characters" << endl ;
00176         }
00177         else
00178         {
00179             cerr << "Regular expression matched " << result
00180                  << " characets, should have matched 8" << endl ;
00181             return 1 ;
00182         }
00183     }
00184     catch( BESException &e )
00185     {
00186         cerr << "Failed to match, exception caught" << endl << e.get_message() << endl ;
00187         return 1 ;
00188     }
00189     catch( ... )
00190     {
00191         cerr << "Failed to match, unknown exception caught" << endl ;
00192         return 1 ;
00193     }
00194 
00195     try
00196     {
00197         cout << endl << "*****************************************" << endl;
00198         cout << "Match reg ex .*\\.(nc|NC)(\\.gz|\\.bz2|\\.Z)?$ against string fnoc1.nc.gz" << endl;
00199         BESRegex reg_expr( ".*\\.(nc|NC)(\\.gz|\\.bz2|\\.Z)?$" ) ;
00200         string inQuestion = "fnoc1.nc.gz" ;
00201         int result = reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ;
00202         if( result == 11 )
00203         {
00204             cout << "Successfully matched characters" << endl ;
00205         }
00206         else
00207         {
00208             cerr << "Regular expression matched " << result
00209                  << " characets, should have matched 11" << endl ;
00210             return 1 ;
00211         }
00212     }
00213     catch( BESException &e )
00214     {
00215         cerr << "Failed to match, exception caught" << endl << e.get_message() << endl ;
00216         return 1 ;
00217     }
00218     catch( ... )
00219     {
00220         cerr << "Failed to match, unknown exception caught" << endl ;
00221         return 1 ;
00222     }
00223 
00224     cout << endl << "*****************************************" << endl;
00225     cout << "Returning from regexT::run" << endl;
00226 
00227     return retVal;
00228 }
00229 
00230 int
00231 main(int argC, char **argV) {
00232     Application *app = new regexT();
00233     return app->main(argC, argV);
00234 }
00235 

Generated on Sat Jan 19 04:05:37 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.4