1 // HtmlAgilityPack V1.0 - Simon Mourier <simon underscore mourier at hotmail dot com>
3 using System
.Collections
;
5 namespace HtmlAgilityPack
7 internal class NameValuePairList
11 internal readonly string Text
;
12 private ArrayList _allPairs
;
13 private Hashtable _pairsWithName
;
19 internal NameValuePairList() :
24 internal NameValuePairList(string text
)
27 _allPairs
= new ArrayList();
28 _pairsWithName
= new Hashtable();
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
)
47 return _pairsWithName
[name
] as ArrayList
;
50 internal string GetNameValuePairValue(string name
)
53 throw new ArgumentNullException();
54 ArrayList al
= GetNameValuePairs(name
);
59 NameValuePair nvp
= al
[0] as NameValuePair
;
60 return nvp
!= null ? nvp
.Value
: string.Empty
;
65 #region Private Methods
67 private void Parse(string text
)
70 _pairsWithName
.Clear();
74 string[] p
= text
.Split(';');
75 foreach (string pv
in p
)
79 string[] onep
= pv
.Split(new char[] {'='}
, 2);
82 NameValuePair nvp
= new NameValuePair(onep
[0].Trim().ToLower());
84 nvp
.Value
= onep
.Length
< 2 ? "" : onep
[1];
89 ArrayList al
= _pairsWithName
[nvp
.Name
] as ArrayList
;
93 _pairsWithName
[nvp
.Name
] = al
;