Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NameTable.cs « System.Xml « System.XML « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c85332180409133b9560fca8b5a35a23017f8877 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// System.Xml.NameTable.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// (C) Ximian, Inc.
//

using System;
using System.Collections;

namespace System.Xml
{
	public class NameTable : XmlNameTable
	{
		// Fields
		Hashtable table;
		
		// Constructor
		public NameTable ()
			: base ()
		{
			table = new Hashtable ();
		}
	  
		// Method
		public override string Add (string key)
		{
			if (table.Contains (key))
				return (string) table [key];
			else {
				table.Add (key, key);
				return key;
			}
		}

		public override string Add (char[] key, int start, int len)
		{
			if (((0 > start) && (start >= key.Length))
			    || ((0 > len) && (len >= key.Length - len)))
				throw new IndexOutOfRangeException ("The Index is out of range.");
					
			if (len == 0)
				return String.Empty;

			string item = new string (key, start, len);

			return Add (item);
		}

		public override string Get (string key)
		{
			if (! (table.Contains (key)))
				return null;
		        else
				return (string) table [key];

		}
	  
		public override string Get (char[] array, int offset, int length)
		{
			if (((0 > offset) && (offset >= array.Length))
			    || ((0 > length) && (length >= array.Length - offset)))
				throw new IndexOutOfRangeException ("The Index is out of range.");

			if (length == 0)
				return String.Empty;

			string key = new string (array, offset, length);

			return Get (key);
		}
	}
}