summaryrefslogtreecommitdiff
path: root/src/experimental/regex.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/experimental/regex.cpp
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/experimental/regex.cpp')
-rw-r--r--src/experimental/regex.cpp94
1 files changed, 47 insertions, 47 deletions
diff --git a/src/experimental/regex.cpp b/src/experimental/regex.cpp
index de24935..dbe0e85 100644
--- a/src/experimental/regex.cpp
+++ b/src/experimental/regex.cpp
@@ -13,83 +13,83 @@
13#define aSubStr ((regmatch_t *)paSubStr) 13#define aSubStr ((regmatch_t *)paSubStr)
14 14
15Bu::RegEx::RegEx() : 15Bu::RegEx::RegEx() :
16 pRegEx( NULL ), 16 pRegEx( NULL ),
17 bCompiled( false ), 17 bCompiled( false ),
18 paSubStr( NULL ) 18 paSubStr( NULL )
19{ 19{
20} 20}
21 21
22Bu::RegEx::RegEx( const Bu::String &sSrc ) : 22Bu::RegEx::RegEx( const Bu::String &sSrc ) :
23 pRegEx( NULL ), 23 pRegEx( NULL ),
24 bCompiled( false ), 24 bCompiled( false ),
25 paSubStr( NULL ) 25 paSubStr( NULL )
26{ 26{
27 compile( sSrc ); 27 compile( sSrc );
28} 28}
29 29
30Bu::RegEx::~RegEx() 30Bu::RegEx::~RegEx()
31{ 31{
32 if( bCompiled ) 32 if( bCompiled )
33 { 33 {
34 regfree( re ); 34 regfree( re );
35 delete re; 35 delete re;
36 delete[] aSubStr; 36 delete[] aSubStr;
37 } 37 }
38} 38}
39 39
40void Bu::RegEx::compile( const Bu::String &sSrc ) 40void Bu::RegEx::compile( const Bu::String &sSrc )
41{ 41{
42 if( bCompiled ) 42 if( bCompiled )
43 { 43 {
44 regfree( re ); 44 regfree( re );
45 delete re; 45 delete re;
46 delete[] aSubStr; 46 delete[] aSubStr;
47 bCompiled = false; 47 bCompiled = false;
48 } 48 }
49 pRegEx = (void *)(new regex_t); 49 pRegEx = (void *)(new regex_t);
50 50
51 int nErr = regcomp( re, sSrc.getStr(), REG_EXTENDED|REG_NEWLINE ); 51 int nErr = regcomp( re, sSrc.getStr(), REG_EXTENDED|REG_NEWLINE );
52 if( nErr ) 52 if( nErr )
53 { 53 {
54 size_t length = regerror( nErr, re, NULL, 0 ); 54 size_t length = regerror( nErr, re, NULL, 0 );
55 char *buffer = new char[length]; 55 char *buffer = new char[length];
56 (void) regerror( nErr, re, buffer, length ); 56 (void) regerror( nErr, re, buffer, length );
57 Bu::String s( buffer ); 57 Bu::String s( buffer );
58 delete[] buffer; 58 delete[] buffer;
59 throw "???"; // BuildException( s.getStr() ); 59 throw "???"; // BuildException( s.getStr() );
60 } 60 }
61 bCompiled = true; 61 bCompiled = true;
62 this->sSrc = sSrc; 62 this->sSrc = sSrc;
63 63
64 nSubStr = re->re_nsub+1; 64 nSubStr = re->re_nsub+1;
65 paSubStr = (void *)(new regmatch_t[nSubStr]); 65 paSubStr = (void *)(new regmatch_t[nSubStr]);
66} 66}
67 67
68int Bu::RegEx::getNumSubStrings() 68int Bu::RegEx::getNumSubStrings()
69{ 69{
70 return nSubStr; 70 return nSubStr;
71} 71}
72 72
73bool Bu::RegEx::execute( const Bu::String &sSrc ) 73bool Bu::RegEx::execute( const Bu::String &sSrc )
74{ 74{
75 sTest = sSrc; 75 sTest = sSrc;
76 if( regexec( re, sSrc.getStr(), nSubStr, aSubStr, 0 ) ) 76 if( regexec( re, sSrc.getStr(), nSubStr, aSubStr, 0 ) )
77 return false; 77 return false;
78 return true; 78 return true;
79} 79}
80 80
81void Bu::RegEx::getSubStringRange( int nIndex, int &iStart, int &iEnd ) 81void Bu::RegEx::getSubStringRange( int nIndex, int &iStart, int &iEnd )
82{ 82{
83 iStart = aSubStr[nIndex].rm_so; 83 iStart = aSubStr[nIndex].rm_so;
84 iEnd = aSubStr[nIndex].rm_eo; 84 iEnd = aSubStr[nIndex].rm_eo;
85} 85}
86 86
87Bu::String Bu::RegEx::getSubString( int nIndex ) 87Bu::String Bu::RegEx::getSubString( int nIndex )
88{ 88{
89// regmatch_t *Subs = aSubStr; 89// regmatch_t *Subs = aSubStr;
90 return Bu::String( 90 return Bu::String(
91 sTest.getStr()+aSubStr[nIndex].rm_so, 91 sTest.getStr()+aSubStr[nIndex].rm_so,
92 aSubStr[nIndex].rm_eo - aSubStr[nIndex].rm_so 92 aSubStr[nIndex].rm_eo - aSubStr[nIndex].rm_so
93 ); 93 );
94} 94}
95 95