[sgen] Don't consider managed write barriers to be critical methods.
[mono-project.git] / docs / HtmlAgilityPack / NameValuePairList.cs
blobf4776e9c758cbf5b3155b3dc498aede2c22ba7e2
1 // HtmlAgilityPack V1.0 - Simon Mourier <simon underscore mourier at hotmail dot com>
2 using System;
3 using System.Collections;
5 namespace HtmlAgilityPack
7 internal class NameValuePairList
9 #region Fields
11 internal readonly string Text;
12 private ArrayList _allPairs;
13 private Hashtable _pairsWithName;
15 #endregion
17 #region Constructors
19 internal NameValuePairList() :
20 this(null)
24 internal NameValuePairList(string text)
26 Text = text;
27 _allPairs = new ArrayList();
28 _pairsWithName = new Hashtable();
30 Parse(text);
33 #endregion
35 #region Internal Methods
37 internal static string GetNameValuePairsValue(string text, string name)
39 NameValuePairList l = new NameValuePairList(text);
40 return l.GetNameValuePairValue(name);
43 internal ArrayList GetNameValuePairs(string name)
45 if (name == null)
46 return _allPairs;
47 return _pairsWithName[name] as ArrayList;
50 internal string GetNameValuePairValue(string name)
52 if (name == null)
53 throw new ArgumentNullException();
54 ArrayList al = GetNameValuePairs(name);
55 if (al == null)
56 return null;
58 // return first item
59 NameValuePair nvp = al[0] as NameValuePair;
60 return nvp != null ? nvp.Value : string.Empty;
63 #endregion
65 #region Private Methods
67 private void Parse(string text)
69 _allPairs.Clear();
70 _pairsWithName.Clear();
71 if (text == null)
72 return;
74 string[] p = text.Split(';');
75 foreach (string pv in p)
77 if (pv.Length == 0)
78 continue;
79 string[] onep = pv.Split(new char[] {'='}, 2);
80 if (onep.Length==0)
81 continue;
82 NameValuePair nvp = new NameValuePair(onep[0].Trim().ToLower());
84 nvp.Value = onep.Length < 2 ? "" : onep[1];
86 _allPairs.Add(nvp);
88 // index by name
89 ArrayList al = _pairsWithName[nvp.Name] as ArrayList;
90 if (al == null)
92 al = new ArrayList();
93 _pairsWithName[nvp.Name] = al;
95 al.Add(nvp);
99 #endregion