00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "CeylanRegularExpression.h"
00028
00029 #include "CeylanStringUtils.h"
00030
00031
00032 #ifdef CEYLAN_USES_CONFIG_H
00033 #include "CeylanConfig.h"
00034 #endif // CEYLAN_USES_CONFIG_H
00035
00036
00037 extern "C"
00038 {
00039
00040 #ifdef CEYLAN_USES_REGEX_H
00041 #include <regex.h>
00042 #endif // CEYLAN_USES_REGEX_H
00043
00044 }
00045
00046
00047 #include <sstream>
00048 using std::stringstream ;
00049
00050 using std::string ;
00051
00052
00053 using namespace Ceylan ;
00054 using namespace Ceylan::Features ;
00055
00056
00057
00058 RegExp::RegExp( const string & toAnalyze ) :
00059 _toAnalyze( toAnalyze )
00060 {
00061
00062 #if CEYLAN_USES_REGEX
00063
00064
00065
00066 #else // CEYLAN_USES_REGEX
00067
00068 throw FeatureNotAvailableException( "RegExp constructor: "
00069 "regular expression support feature not available" ) ;
00070
00071 #endif // CEYLAN_USES_REGEX
00072
00073 }
00074
00075
00076
00077 RegExp::~RegExp() throw()
00078 {
00079
00080 }
00081
00082
00083
00084 bool RegExp::isXMLName() const
00085 {
00086
00087 return matches( "^([a-z]|[A-Z]|[_]|[:]{1,1})" ) ;
00088
00089 }
00090
00091
00092
00093 bool RegExp::matches( const string & pattern ) const
00094 {
00095
00096 #if CEYLAN_USES_REGEX
00097
00098 regex_t re ;
00099
00100 ::regcomp( & re, pattern.c_str(), REG_EXTENDED | REG_NOSUB ) ;
00101
00102 int status = ::regexec( & re, _toAnalyze.c_str(),
00103 static_cast<StringSize>( 0 ), 0, 0 ) ;
00104
00105 ::regfree( & re ) ;
00106
00107 return ( status == 0 ) ;
00108
00109 #else // CEYLAN_USES_REGEX
00110
00111 throw FeatureNotAvailableException( "RegExp::matches: "
00112 "regular expression support feature not available" ) ;
00113
00114 #endif // CEYLAN_USES_REGEX
00115
00116 }
00117