/// <summary>Records a replacement to be applied to the inputs /// stream. Whenever <c>singleMatch</c> occurs in /// the input, it will be replaced with /// <c>replacement</c>. /// /// </summary> /// <param name="singleMatch">input String to be replaced /// </param> /// <param name="replacement">output String /// </param> public virtual void Add(System.String singleMatch, System.String replacement) { NormalizeCharMap currMap = this; for (var i = 0; i < singleMatch.Length; i++) { char c = singleMatch[i]; if (currMap.submap == null) { currMap.submap = new HashMap<char, NormalizeCharMap>(1); } var map = currMap.submap[c]; if (map == null) { map = new NormalizeCharMap(); currMap.submap[c] = map; } currMap = map; } if (currMap.normStr != null) { throw new System.SystemException("MappingCharFilter: there is already a mapping for " + singleMatch); } currMap.normStr = replacement; currMap.diff = singleMatch.Length - replacement.Length; }
/// <summary>Records a replacement to be applied to the inputs /// stream. Whenever <code>singleMatch</code> occurs in /// the input, it will be replaced with /// <code>replacement</code>. /// /// </summary> /// <param name="singleMatch">input String to be replaced /// </param> /// <param name="replacement">output String /// </param> public virtual void Add(System.String singleMatch, System.String replacement) { NormalizeCharMap currMap = this; for (int i = 0; i < singleMatch.Length; i++) { char c = singleMatch[i]; if (currMap.submap == null) { currMap.submap = new System.Collections.Hashtable(1); } NormalizeCharMap map = (NormalizeCharMap)currMap.submap[CharacterCache.ValueOf(c)]; if (map == null) { map = new NormalizeCharMap(); currMap.submap[c] = map; } currMap = map; } if (currMap.normStr != null) { throw new System.SystemException("MappingCharFilter: there is already a mapping for " + singleMatch); } currMap.normStr = replacement; currMap.diff = singleMatch.Length - replacement.Length; }
/// <summary>Records a replacement to be applied to the inputs /// stream. Whenever <c>singleMatch</c> occurs in /// the input, it will be replaced with /// <c>replacement</c>. /// /// </summary> /// <param name="singleMatch">input String to be replaced /// </param> /// <param name="replacement">output String /// </param> public virtual void Add(System.String singleMatch, System.String replacement) { NormalizeCharMap currMap = this; for (var i = 0; i < singleMatch.Length; i++) { char c = singleMatch[i]; if (currMap.submap == null) { currMap.submap = new HashMap <char, NormalizeCharMap>(1); } var map = currMap.submap[c]; if (map == null) { map = new NormalizeCharMap(); currMap.submap[c] = map; } currMap = map; } if (currMap.normStr != null) { throw new System.SystemException("MappingCharFilter: there is already a mapping for " + singleMatch); } currMap.normStr = replacement; currMap.diff = singleMatch.Length - replacement.Length; }
private NormalizeCharMap Match(NormalizeCharMap map) { NormalizeCharMap result = null; if (map.submap != null) { int chr = NextChar(); if (chr != -1) { NormalizeCharMap subMap = map.submap[CharacterCache.ValueOf((char)chr)]; if (subMap != null) { result = Match(subMap); } if (result == null) { PushChar(chr); } } } if (result == null && map.normStr != null) { result = map; } return(result); }
/// <summary>Records a replacement to be applied to the inputs /// stream. Whenever <code>singleMatch</code> occurs in /// the input, it will be replaced with /// <code>replacement</code>. /// /// </summary> /// <param name="singleMatch">input String to be replaced /// </param> /// <param name="replacement">output String /// </param> public virtual void Add(System.String singleMatch, System.String replacement) { NormalizeCharMap currMap = this; for (int i = 0; i < singleMatch.Length; i++) { char c = singleMatch[i]; if (currMap.submap == null) { currMap.submap = new Support.Dictionary<char, NormalizeCharMap>(1); } NormalizeCharMap map = currMap.submap[CharacterCache.ValueOf(c)]; if (map == null) { map = new NormalizeCharMap(); currMap.submap[c] = map; } currMap = map; } if (currMap.normStr != null) { throw new System.SystemException("MappingCharFilter: there is already a mapping for " + singleMatch); } currMap.normStr = replacement; currMap.diff = singleMatch.Length - replacement.Length; }
public override void SetUp() { base.SetUp(); normMap = new NormalizeCharMap(); normMap.Add("aa", "a"); normMap.Add("bbb", "b"); normMap.Add("cccc", "cc"); normMap.Add("h", "i"); normMap.Add("j", "jj"); normMap.Add("k", "kkk"); normMap.Add("ll", "llll"); normMap.Add("empty", ""); }
public override void SetUp() { base.SetUp(); normMap = new NormalizeCharMap(); normMap.Add("aa", "a"); normMap.Add("bbb", "b"); normMap.Add("cccc", "cc"); normMap.Add("h", "i"); normMap.Add("j", "jj"); normMap.Add("k", "kkk"); normMap.Add("ll", "llll"); normMap.Add("empty", ""); }
public override int Read() { while (true) { if (replacement != null && charPointer < replacement.Length) { return(replacement[charPointer++]); } int firstChar = NextChar(); if (firstChar == -1) { return(-1); } NormalizeCharMap nm = normMap.submap != null ? normMap.submap[(char)firstChar] : null; if (nm == null) { return(firstChar); } NormalizeCharMap result = Match(nm); if (result == null) { return(firstChar); } replacement = result.normStr; charPointer = 0; if (result.diff != 0) { int prevCumulativeDiff = LastCumulativeDiff; if (result.diff < 0) { for (int i = 0; i < -result.diff; i++) { AddOffCorrectMap(nextCharCounter + i - prevCumulativeDiff, prevCumulativeDiff - 1 - i); } } else { AddOffCorrectMap(nextCharCounter - result.diff - prevCumulativeDiff, prevCumulativeDiff + result.diff); } } } }
/// Default constructor that takes a {@link CharStream}. public MappingCharFilter(NormalizeCharMap normMap, CharStream in_Renamed) : base(in_Renamed) { this.normMap = normMap; }
/// Easy-use constructor that takes a <see cref="System.IO.TextReader" />. public MappingCharFilter(NormalizeCharMap normMap, System.IO.TextReader @in) : base(CharReader.Get(@in)) { this.normMap = normMap; }
/// Default constructor that takes a <see cref="CharStream" />. public MappingCharFilter(NormalizeCharMap normMap, CharStream @in) : base(@in) { this.normMap = normMap; }
private NormalizeCharMap Match(NormalizeCharMap map) { NormalizeCharMap result = null; if (map.submap != null) { int chr = NextChar(); if (chr != - 1) { NormalizeCharMap subMap = map.submap[(char)chr]; if (subMap != null) { result = Match(subMap); } if (result == null) { PushChar(chr); } } } if (result == null && map.normStr != null) { result = map; } return result; }
/// Easy-use constructor that takes a <see cref="System.IO.TextReader" />. public MappingCharFilter(NormalizeCharMap normMap, System.IO.TextReader @in) : base(CharReader.Get(@in)) { this.normMap = normMap; }
/// Default constructor that takes a <see cref="CharStream" />. public MappingCharFilter(NormalizeCharMap normMap, CharStream in_Renamed) : base(in_Renamed) { this.normMap = normMap; }
/// Easy-use constructor that takes a {@link Reader}. public MappingCharFilter(NormalizeCharMap normMap, System.IO.TextReader in_Renamed) : base(CharReader.Get(in_Renamed)) { this.normMap = normMap; }
/// Default constructor that takes a <see cref="CharStream" />. public MappingCharFilter(NormalizeCharMap normMap, CharStream @in) : base(@in) { this.normMap = normMap; }
/// Easy-use constructor that takes a <see cref="System.IO.TextReader" />. public MappingCharFilter(NormalizeCharMap normMap, System.IO.TextReader in_Renamed) : base(CharReader.Get(in_Renamed)) { this.normMap = normMap; }