From 51e21a316be6e052251b3dfc7d671061ebd67cee Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 21 Dec 2009 18:03:28 +0000 Subject: Removed the old trunk contents. About to load up m3 --- src/regexp.cpp | 78 ---------------------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 src/regexp.cpp (limited to 'src/regexp.cpp') diff --git a/src/regexp.cpp b/src/regexp.cpp deleted file mode 100644 index 4370667..0000000 --- a/src/regexp.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "regexp.h" -#include "build.h" // For BuildException -#include "bu/fstring.h" - -RegExp::RegExp() : - bCompiled( false ), - aSubStr( NULL ) -{ -} - -RegExp::RegExp( const char *sSrc ) : - bCompiled( false ), - aSubStr( NULL ) -{ - compile( sSrc ); -} - -RegExp::~RegExp() -{ - if( bCompiled ) - { - regfree( &re ); - delete[] aSubStr; - } -} - -void RegExp::compile( const char *sSrc ) -{ - if( bCompiled ) - { - regfree( &re ); - delete[] aSubStr; - bCompiled = false; - } - - int nErr = regcomp( &re, sSrc, REG_EXTENDED|REG_NEWLINE ); - if( nErr ) - { - size_t length = regerror( nErr, &re, NULL, 0 ); - char *buffer = new char[length]; - (void) regerror( nErr, &re, buffer, length ); - Bu::FString s( buffer ); - delete[] buffer; - throw BuildException( s.getStr() ); - } - bCompiled = true; - this->sSrc = sSrc; - - nSubStr = re.re_nsub+1; - aSubStr = new regmatch_t[nSubStr]; -} - -int RegExp::getNumSubStrings() -{ - return nSubStr; -} - -bool RegExp::execute( const char *sSrc ) -{ - sTest = sSrc; - if( regexec( &re, sSrc, nSubStr, aSubStr, 0 ) ) - return false; - return true; -} - -std::pair RegExp::getSubStringRange( int nIndex ) -{ - return std::pair( aSubStr[nIndex].rm_so, aSubStr[nIndex].rm_eo ); -} - -std::string RegExp::getSubString( int nIndex ) -{ - return std::string( - sTest.getStr()+aSubStr[nIndex].rm_so, - aSubStr[nIndex].rm_eo - aSubStr[nIndex].rm_so - ); -} - -- cgit v1.2.3