Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / tools / monkeydoc / Lucene.Net / Lucene.Net / Analysis / NormalizeCharMap.cs
1 /* 
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  * 
9  * http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 using System;
19
20 namespace Mono.Lucene.Net.Analysis
21 {
22         
23         /// <summary> Holds a map of String input to String output, to be used
24         /// with {@link MappingCharFilter}.
25         /// </summary>
26         public class NormalizeCharMap
27         {
28                 
29                 //Map<Character, NormalizeMap> submap;
30                 internal System.Collections.IDictionary submap;
31                 internal System.String normStr;
32                 internal int diff;
33                 
34                 /// <summary>Records a replacement to be applied to the inputs
35                 /// stream.  Whenever <code>singleMatch</code> occurs in
36                 /// the input, it will be replaced with
37                 /// <code>replacement</code>.
38                 /// 
39                 /// </summary>
40                 /// <param name="singleMatch">input String to be replaced
41                 /// </param>
42                 /// <param name="replacement">output String
43                 /// </param>
44                 public virtual void  Add(System.String singleMatch, System.String replacement)
45                 {
46                         NormalizeCharMap currMap = this;
47                         for (int i = 0; i < singleMatch.Length; i++)
48                         {
49                                 char c = singleMatch[i];
50                                 if (currMap.submap == null)
51                                 {
52                                         currMap.submap = new System.Collections.Hashtable(1);
53                                 }
54                                 NormalizeCharMap map = (NormalizeCharMap) currMap.submap[CharacterCache.ValueOf(c)];
55                                 if (map == null)
56                                 {
57                                         map = new NormalizeCharMap();
58                                         currMap.submap[c] = map;
59                                 }
60                                 currMap = map;
61                         }
62                         if (currMap.normStr != null)
63                         {
64                                 throw new System.SystemException("MappingCharFilter: there is already a mapping for " + singleMatch);
65                         }
66                         currMap.normStr = replacement;
67                         currMap.diff = singleMatch.Length - replacement.Length;
68                 }
69         }
70 }