diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
| commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
| tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/experimental/regexengine.h | |
| parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
| download | libbu++-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/regexengine.h')
| -rw-r--r-- | src/experimental/regexengine.h | 260 |
1 files changed, 130 insertions, 130 deletions
diff --git a/src/experimental/regexengine.h b/src/experimental/regexengine.h index ec181c1..133d418 100644 --- a/src/experimental/regexengine.h +++ b/src/experimental/regexengine.h | |||
| @@ -7,136 +7,136 @@ | |||
| 7 | 7 | ||
| 8 | namespace Bu | 8 | namespace Bu |
| 9 | { | 9 | { |
| 10 | template<typename chr> class RegExEngine; | 10 | template<typename chr> class RegExEngine; |
| 11 | 11 | ||
| 12 | template<typename chr> | 12 | template<typename chr> |
| 13 | class RegExEngineCore | 13 | class RegExEngineCore |
| 14 | { | 14 | { |
| 15 | friend class RegExEngine<chr>; | 15 | friend class RegExEngine<chr>; |
| 16 | friend class SharedCore<RegExEngine<chr>, RegExEngineCore<chr> >; | 16 | friend class SharedCore<RegExEngine<chr>, RegExEngineCore<chr> >; |
| 17 | private: | 17 | private: |
| 18 | RegExEngineCore() | 18 | RegExEngineCore() |
| 19 | { | 19 | { |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | virtual ~RegExEngineCore() | 22 | virtual ~RegExEngineCore() |
| 23 | { | 23 | { |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | class Range | 26 | class Range |
| 27 | { | 27 | { |
| 28 | public: | 28 | public: |
| 29 | Range( chr cLower, chr cUpper, int iTrgState ) : | 29 | Range( chr cLower, chr cUpper, int iTrgState ) : |
| 30 | cLower( cLower ), cUpper( cUpper ), iTrgState( iTrgState ) | 30 | cLower( cLower ), cUpper( cUpper ), iTrgState( iTrgState ) |
| 31 | { | 31 | { |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | chr cLower; | 34 | chr cLower; |
| 35 | chr cUpper; | 35 | chr cUpper; |
| 36 | int iTrgState; | 36 | int iTrgState; |
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | class State | 39 | class State |
| 40 | { | 40 | { |
| 41 | public: | 41 | public: |
| 42 | Bu::Array<Range> aRange; | 42 | Bu::Array<Range> aRange; |
| 43 | }; | 43 | }; |
| 44 | 44 | ||
| 45 | int addState() | 45 | int addState() |
| 46 | { | 46 | { |
| 47 | aState.append( State() ); | 47 | aState.append( State() ); |
| 48 | return aState.getSize()-1; | 48 | return aState.getSize()-1; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | void addCompletion( int iState, chr cLower, chr cUpper, int iTrgState ) | 51 | void addCompletion( int iState, chr cLower, chr cUpper, int iTrgState ) |
| 52 | { | 52 | { |
| 53 | aState[iState].aRange.append( Range( cLower, cUpper, iTrgState ) ); | 53 | aState[iState].aRange.append( Range( cLower, cUpper, iTrgState ) ); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | template<typename str> | 56 | template<typename str> |
| 57 | bool match( const str &sIn, int &iSize, int &iCompletion ) | 57 | bool match( const str &sIn, int &iSize, int &iCompletion ) |
| 58 | { | 58 | { |
| 59 | bool bMatch; | 59 | bool bMatch; |
| 60 | int iState = 0; | 60 | int iState = 0; |
| 61 | iSize = 0; | 61 | iSize = 0; |
| 62 | for( typename str::const_iterator i = sIn.begin(); i; i++ ) | 62 | for( typename str::const_iterator i = sIn.begin(); i; i++ ) |
| 63 | { | 63 | { |
| 64 | Bu::sio << "Finding char " << *i << " in state " << iState | 64 | Bu::sio << "Finding char " << *i << " in state " << iState |
| 65 | << ":" << Bu::sio.nl; | 65 | << ":" << Bu::sio.nl; |
| 66 | bMatch = false; | 66 | bMatch = false; |
| 67 | for( typename Bu::Array<Range>::iterator j = | 67 | for( typename Bu::Array<Range>::iterator j = |
| 68 | aState[iState].aRange.begin(); j; j++ ) | 68 | aState[iState].aRange.begin(); j; j++ ) |
| 69 | { | 69 | { |
| 70 | Bu::sio << " Testing range " << (*j).cLower << " - " << (*j).cUpper << Bu::sio.nl; | 70 | Bu::sio << " Testing range " << (*j).cLower << " - " << (*j).cUpper << Bu::sio.nl; |
| 71 | if( *i >= (*j).cLower && *i <= (*j).cUpper ) | 71 | if( *i >= (*j).cLower && *i <= (*j).cUpper ) |
| 72 | { | 72 | { |
| 73 | iState = (*j).iTrgState; | 73 | iState = (*j).iTrgState; |
| 74 | bMatch = true; | 74 | bMatch = true; |
| 75 | iSize++; | 75 | iSize++; |
| 76 | if( iState < 0 ) | 76 | if( iState < 0 ) |
| 77 | { | 77 | { |
| 78 | iCompletion = iState; | 78 | iCompletion = iState; |
| 79 | return true; | 79 | return true; |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| 83 | if( bMatch == false ) | 83 | if( bMatch == false ) |
| 84 | { | 84 | { |
| 85 | return false; | 85 | return false; |
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | iCompletion = 0; | 89 | iCompletion = 0; |
| 90 | return true; | 90 | return true; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | typedef Bu::Array<State> StateArray; | 93 | typedef Bu::Array<State> StateArray; |
| 94 | StateArray aState; | 94 | StateArray aState; |
| 95 | }; | 95 | }; |
| 96 | 96 | ||
| 97 | template<typename chr> | 97 | template<typename chr> |
| 98 | class RegExEngine : public SharedCore<RegExEngine<chr>, | 98 | class RegExEngine : public SharedCore<RegExEngine<chr>, |
| 99 | RegExEngineCore<chr> > | 99 | RegExEngineCore<chr> > |
| 100 | { | 100 | { |
| 101 | private: | 101 | private: |
| 102 | typedef class RegExEngine<chr> MyType; | 102 | typedef class RegExEngine<chr> MyType; |
| 103 | typedef class RegExEngineCore<chr> Core; | 103 | typedef class RegExEngineCore<chr> Core; |
| 104 | typedef class Core::Range Range; | 104 | typedef class Core::Range Range; |
| 105 | typedef class Core::State State; | 105 | typedef class Core::State State; |
| 106 | 106 | ||
| 107 | protected: | 107 | protected: |
| 108 | using SharedCore<MyType, Core>::core; | 108 | using SharedCore<MyType, Core>::core; |
| 109 | using SharedCore<MyType, Core>::_hardCopy; | 109 | using SharedCore<MyType, Core>::_hardCopy; |
| 110 | using SharedCore<MyType, Core>::_resetCore; | 110 | using SharedCore<MyType, Core>::_resetCore; |
| 111 | using SharedCore<MyType, Core>::_allocateCore; | 111 | using SharedCore<MyType, Core>::_allocateCore; |
| 112 | 112 | ||
| 113 | public: | 113 | public: |
| 114 | RegExEngine() | 114 | RegExEngine() |
| 115 | { | 115 | { |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | virtual ~RegExEngine() | 118 | virtual ~RegExEngine() |
| 119 | { | 119 | { |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | int addState() | 122 | int addState() |
| 123 | { | 123 | { |
| 124 | return core->addState(); | 124 | return core->addState(); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | void addCompletion( int iState, chr cLower, chr cUpper, int iTrgState ) | 127 | void addCompletion( int iState, chr cLower, chr cUpper, int iTrgState ) |
| 128 | { | 128 | { |
| 129 | core->addCompletion( iState, cLower, cUpper, iTrgState ); | 129 | core->addCompletion( iState, cLower, cUpper, iTrgState ); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | template<typename str> | 132 | template<typename str> |
| 133 | bool match( const str &sIn, int &iSize, int &iCompletion ) | 133 | bool match( const str &sIn, int &iSize, int &iCompletion ) |
| 134 | { | 134 | { |
| 135 | return core->match( sIn, iSize, iCompletion ); | 135 | return core->match( sIn, iSize, iCompletion ); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | private: | 138 | private: |
| 139 | }; | 139 | }; |
| 140 | }; | 140 | }; |
| 141 | 141 | ||
| 142 | #endif | 142 | #endif |
