コード例 #1
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;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public virtual void  TestValueOf()
 {
     for (int i = 0; i < 256; i++)
     {
         System.Char valueOf = CharacterCache.ValueOf((char)i);
         Assert.AreEqual((char)i, valueOf);
     }
 }
コード例 #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[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);
                    }
                }
            }
        }