aboutsummaryrefslogtreecommitdiff
path: root/src/regexp.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-18 17:21:02 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-18 17:21:02 +0000
commitdf5286fe3bca619beb4771da1ffa8ace9613e9e5 (patch)
tree0ad268267325c586527b8d36461ab0040e9ae8ec /src/regexp.cpp
parent4f94dfde7cbe043dfeb11a8712636bac348d3177 (diff)
downloadbuild-df5286fe3bca619beb4771da1ffa8ace9613e9e5.tar.gz
build-df5286fe3bca619beb4771da1ffa8ace9613e9e5.tar.bz2
build-df5286fe3bca619beb4771da1ffa8ace9613e9e5.tar.xz
build-df5286fe3bca619beb4771da1ffa8ace9613e9e5.zip
Gutted, deleted almost all the source, too many changes to keep it around, we'll
see what happens next.
Diffstat (limited to 'src/regexp.cpp')
-rw-r--r--src/regexp.cpp78
1 files changed, 0 insertions, 78 deletions
diff --git a/src/regexp.cpp b/src/regexp.cpp
deleted file mode 100644
index e5a3535..0000000
--- a/src/regexp.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
1#include "regexp.h"
2#include "builder.h" // For BuildException
3#include "staticstring.h"
4
5RegExp::RegExp() :
6 bCompiled( false ),
7 aSubStr( NULL )
8{
9}
10
11RegExp::RegExp( const char *sSrc ) :
12 bCompiled( false ),
13 aSubStr( NULL )
14{
15 compile( sSrc );
16}
17
18RegExp::~RegExp()
19{
20 if( bCompiled )
21 {
22 regfree( &re );
23 delete[] aSubStr;
24 }
25}
26
27void RegExp::compile( const char *sSrc )
28{
29 if( bCompiled )
30 {
31 regfree( &re );
32 delete[] aSubStr;
33 bCompiled = false;
34 }
35
36 int nErr = regcomp( &re, sSrc, REG_EXTENDED|REG_NEWLINE );
37 if( nErr )
38 {
39 size_t length = regerror( nErr, &re, NULL, 0 );
40 char *buffer = new char[length];
41 (void) regerror( nErr, &re, buffer, length );
42 StaticString s( buffer );
43 delete[] buffer;
44 throw BuildException( s.getString() );
45 }
46 bCompiled = true;
47 this->sSrc = sSrc;
48
49 nSubStr = re.re_nsub+1;
50 aSubStr = new regmatch_t[nSubStr];
51}
52
53int RegExp::getNumSubStrings()
54{
55 return nSubStr;
56}
57
58bool RegExp::execute( const char *sSrc )
59{
60 sTest = sSrc;
61 if( regexec( &re, sSrc, nSubStr, aSubStr, 0 ) )
62 return false;
63 return true;
64}
65
66std::pair<int,int> RegExp::getSubStringRange( int nIndex )
67{
68 return std::pair<int,int>( aSubStr[nIndex].rm_so, aSubStr[nIndex].rm_eo );
69}
70
71std::string RegExp::getSubString( int nIndex )
72{
73 return std::string(
74 sTest.getString()+aSubStr[nIndex].rm_so,
75 aSubStr[nIndex].rm_eo - aSubStr[nIndex].rm_so
76 );
77}
78