#include <wldcrd_mtchr.hpp>
Public Member Functions | |
wldcrd_mtchr (mem_pool &m, const ch_rng &mask) | |
const ch_rng | mask () const |
bool | match (const ch_rng &str) const |
Classes | |
struct | segm |
struct | word |
Definition at line 29 of file wldcrd_mtchr.hpp.
Definition at line 57 of file wldcrd_mtchr.cpp.
00057 : 00058 mp(m), len(0), sav_msk(nt(m, mask)), sav_sgs(stl_allocator<segm>(mp)) 00059 { 00060 for (char* ptr=sav_msk->begin(); ptr<sav_msk->end(); ptr++) { 00061 switch (*ptr) { 00062 case '*': { 00063 if (sgs.size()==0 || sgs.back()) sgs.push_back(0); 00064 break; 00065 } 00066 case '?': { 00067 if (sgs.size()==0 || !sgs.back()) add_sg(); 00068 sgs.back()->len++; 00069 00070 break; 00071 } 00072 default: { 00073 if (sgs.size()==0 || !sgs.back()) add_sg(); 00074 segm& bs=*sgs.back(); 00075 00076 if (*ptr=='\\' && ptr+1<sav_msk->end()) { 00077 ptr++; 00078 bs.wds.push_back(word(bs.len, ch_rng(ptr, ptr+1))); 00079 } 00080 else { 00081 if (bs.wds.size()==0 || bs.len!=bs.wds.back().off+ 00082 bs.wds.back().str.size()) 00083 bs.wds.push_back(word(bs.len, ch_rng(ptr, ptr+1))); 00084 else bs.wds.back().str.end++; 00085 } 00086 00087 bs.len++; 00088 } 00089 } 00090 } 00091 00092 for (int i=0, end=sgs.size(); i<end; i++) 00093 if (sgs[i]) len+=sgs[i]->len; 00094 }
const ch_rng ders::wldcrd_mtchr::mask | ( | ) | const [inline] |
bool ders::wldcrd_mtchr::match | ( | const ch_rng & | str | ) | const |
Definition at line 96 of file wldcrd_mtchr.cpp.
00097 { 00098 if (str.size()<len) return false; 00099 00100 int sgfr=0, sgbk=sgs.size()-1; 00101 if (sgfr>sgbk) return true; 00102 00103 ch_rng s=str; 00104 if (sgs[sgfr]) { 00105 if (!eq(s.beg, *sgs[sgfr])) return false; 00106 00107 s.beg+=sgs[sgfr]->len; 00108 sgfr++; 00109 } 00110 00111 if (sgfr<=sgbk && sgs[sgbk]) { 00112 if (!eq(s.end-sgs[sgbk]->len, *sgs[sgbk])) return false; 00113 00114 s.end-=sgs[sgbk]->len; 00115 sgbk--; 00116 } 00117 00118 if (sgfr>sgbk) return s.beg==s.end; 00119 00120 assert(!sgs[sgbk]); 00121 for (int i=sgfr; i<sgbk; i++) { 00122 if (sgs[i]) { 00123 s.beg=fnd(s, *sgs[i]); 00124 if (!s.beg) return false; 00125 00126 s.beg+=sgs[i]->len; 00127 } 00128 } 00129 00130 return true; 00131 }