Universal Bible API 1.0.2011.1274
|
00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Text; 00005 00006 namespace UniversalBibleAPI 00007 { 00011 public class RegExFilterChain : FilterDecorator 00012 { 00013 private RegExFilter _myregexfilter = new RegExFilter(new NullFilter()); 00014 00015 private List<string> _myregexfilterdef; 00016 00021 public List<string> MyRegExFilterDefinitions 00022 { 00023 get { return this._myregexfilterdef; } 00024 00025 set 00026 { 00027 this._myregexfilterdef = value; 00028 this._myregexfilter = CreateRegexChain(this._myregexfilterdef); 00029 00030 } 00031 00032 } 00038 private RegExFilter CreateRegexChain(List<string> _myregexfilterdef) 00039 { 00040 00041 try 00042 { 00043 if (_myregexfilterdef.Count == 0) 00044 { 00045 00046 return this._myregexfilter; 00047 00048 } 00049 else 00050 { 00051 00052 string[] parts = this._myregexfilterdef.Last().Split(':'); 00053 this._myregexfilter = new RegExFilter(this._myregexfilter); 00054 this._myregexfilter.Pattern = parts[0]; 00055 this._myregexfilter.Replacement = parts[1]; 00056 this._myregexfilterdef.RemoveAt(this._myregexfilterdef.Count() - 1); 00057 return CreateRegexChain(this._myregexfilterdef); 00058 00059 } 00060 } 00061 catch (Exception) 00062 { 00063 00064 throw; 00065 } 00066 } 00067 00068 public RegExFilterChain(IFilter otherFilter) : base(otherFilter) { } 00069 00070 public override string PerformFilter(string TextToFilter) 00071 { 00072 return base.PerformFilter(this._myregexfilter.PerformFilter(TextToFilter)); 00073 } 00074 00075 } 00076 }