Пример #1
0
		/// <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;
		}
Пример #2
0
        /// <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;
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
                    }
                }
            }
        }
Пример #5
0
		/// 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;
		}
Пример #6
0
		/// Default constructor that takes a <see cref="CharStream" />.
		public MappingCharFilter(NormalizeCharMap normMap, CharStream @in)
			: base(@in)
		{
			this.normMap = normMap;
		}
Пример #7
0
		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;
		}
Пример #8
0
 /// 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;
 }
Пример #9
0
 /// Default constructor that takes a <see cref="CharStream" />.
 public MappingCharFilter(NormalizeCharMap normMap, CharStream @in)
     : base(@in)
 {
     this.normMap = normMap;
 }