2002-02-26 Duncan Mak <duncan@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml / NameTable.cs
1 //
2 // System.Xml.NameTable.cs
3 //
4 // Author: Duncan Mak (duncan@ximian.com)
5 //
6 // (C) Ximian, Inc.
7 //
8
9 using System;
10 using System.Collections;
11
12 namespace System.Xml
13 {
14         public class NameTable : XmlNameTable
15         {
16                 // Fields
17                 Hashtable table;
18                 
19                 // Constructor
20                 public NameTable ()
21                         : base ()
22                 {
23                         table = new Hashtable ();
24                 }
25           
26                 // Method
27                 public override string Add (string key)
28                 {
29                         if (table.ContainsKey (key))
30                                 return (string) table [key];
31                         else 
32                                 return table.Add (key.GetHashCode (), key);
33                 }
34
35                 public override string Add (char[] key, int start, int len)
36                 {
37                         if (((0 > start) && (start >= key.Length))
38                             || ((0 > len) && (len >= key.Length - len)))
39                                 throw new IndexOutOfRangeException ("The Index is out of range.");
40                                         
41                         if (len == 0)
42                                 return String.Empty;
43
44                         string item = new string (key, start, len);
45
46                         return Add (item);
47                 }
48
49                 public override string Get (string key)
50                 {
51                         if (!(table.ContainsKey (key)))
52                                 return null;
53                         else
54                                 return (string) table [key];
55
56                 }
57           
58                 public override string Get (char[] array, int offset, int length)
59                 {
60                         if (((0 > offset) && (offset >= array.Length))
61                             || ((0 > length) && (length >= array.Length - offset)))
62                                 throw new IndexOutOfRangeException ("The Index is out of range.");
63
64                         if (length == 0)
65                                 return String.Empty;
66
67                         string item = new string (array, offset, length);
68
69                         return Get (item);
70                 }
71         }
72 }