Пример #1
0
        private NormalizeCharMap Match(NormalizeCharMap map)
        {
            NormalizeCharMap result = null;

            if (map.submap != null)
            {
                int chr = NextChar();
                if (chr != -1)
                {
                    NormalizeCharMap subMap = (NormalizeCharMap)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);
        }
Пример #2
0
        /// <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;
        }
Пример #3
0
		/// <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;
		}
Пример #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?(NormalizeCharMap)normMap.submap[CharacterCache.ValueOf((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 = GetLastCumulativeDiff();
                    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 {@link Reader}.
 public MappingCharFilter(NormalizeCharMap normMap, System.IO.TextReader in_Renamed) : base(CharReader.Get(in_Renamed))
 {
     this.normMap = normMap;
 }
Пример #6
0
 /// Default constructor that takes a {@link CharStream}.
 public MappingCharFilter(NormalizeCharMap normMap, CharStream in_Renamed) : base(in_Renamed)
 {
     this.normMap = normMap;
 }
Пример #7
0
		/// 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;
		}
Пример #8
0
		/// Default constructor that takes a {@link CharStream}.
		public MappingCharFilter(NormalizeCharMap normMap, CharStream in_Renamed):base(in_Renamed)
		{
			this.normMap = normMap;
		}
Пример #9
0
		private NormalizeCharMap Match(NormalizeCharMap map)
		{
			NormalizeCharMap result = null;
			if (map.submap != null)
			{
				int chr = NextChar();
				if (chr != - 1)
				{
					NormalizeCharMap subMap = (NormalizeCharMap) 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;
		}