wasSharp – Diff between revs 1 and 5

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 1 Rev 5
Line 19... Line 19...
19 /// Returns the value of a key from a key-value data string. 19 /// Returns the value of a key from a key-value data string.
20 /// </summary> 20 /// </summary>
21 /// <param name="key">the key of the value</param> 21 /// <param name="key">the key of the value</param>
22 /// <param name="data">the key-value data segment</param> 22 /// <param name="data">the key-value data segment</param>
23 /// <returns>true if the key was found in data</returns> 23 /// <returns>true if the key was found in data</returns>
24 public static string wasKeyValueGet(string key, string data) 24 public static string Get(string key, string data)
25 { 25 {
26 return data.Split('&') 26 return data.Split('&')
27 .AsParallel() 27 .AsParallel()
28 .Select(o => o.Split('=').ToList()) 28 .Select(o => o.Split('=').ToList())
29 .Where(o => o.Count.Equals(2)) 29 .Where(o => o.Count.Equals(2))
Line 48... Line 48...
48 /// <param name="data">the key-value data segment</param> 48 /// <param name="data">the key-value data segment</param>
49 /// <returns> 49 /// <returns>
50 /// a key-value data string or the empty string if either key or 50 /// a key-value data string or the empty string if either key or
51 /// value are empty 51 /// value are empty
52 /// </returns> 52 /// </returns>
53 public static string wasKeyValueSet(string key, string value, string data) 53 public static string Set(string key, string value, string data)
54 { 54 {
55 HashSet<string> output = new HashSet<string>(data.Split('&') 55 HashSet<string> output = new HashSet<string>(data.Split('&')
56 .AsParallel() 56 .AsParallel()
57 .Select(o => o.Split('=').ToList()) 57 .Select(o => o.Split('=').ToList())
58 .Where(o => o.Count.Equals(2)) 58 .Where(o => o.Count.Equals(2))
Line 76... Line 76...
76 /// Deletes a key-value pair from a string referenced by a key. 76 /// Deletes a key-value pair from a string referenced by a key.
77 /// </summary> 77 /// </summary>
78 /// <param name="key">the key to search for</param> 78 /// <param name="key">the key to search for</param>
79 /// <param name="data">the key-value data segment</param> 79 /// <param name="data">the key-value data segment</param>
80 /// <returns>a key-value pair string</returns> 80 /// <returns>a key-value pair string</returns>
81 public static string wasKeyValueDelete(string key, string data) 81 public static string Delete(string key, string data)
82 { 82 {
83 return string.Join("&", data.Split('&') 83 return string.Join("&", data.Split('&')
84 .AsParallel() 84 .AsParallel()
85 .Select(o => o.Split('=').ToList()) 85 .Select(o => o.Split('=').ToList())
86 .Where(o => o.Count.Equals(2)) 86 .Where(o => o.Count.Equals(2))
Line 100... Line 100...
100 /// <summary> 100 /// <summary>
101 /// Decodes key-value pair data to a dictionary. 101 /// Decodes key-value pair data to a dictionary.
102 /// </summary> 102 /// </summary>
103 /// <param name="data">the key-value pair data</param> 103 /// <param name="data">the key-value pair data</param>
104 /// <returns>a dictionary containing the keys and values</returns> 104 /// <returns>a dictionary containing the keys and values</returns>
105 public static Dictionary<string, string> wasKeyValueDecode(string data) 105 public static Dictionary<string, string> Decode(string data)
106 { 106 {
107 return data.Split('&') 107 return data.Split('&')
108 .AsParallel() 108 .AsParallel()
109 .Select(o => o.Split('=').ToList()) 109 .Select(o => o.Split('=').ToList())
110 .Where(o => o.Count.Equals(2)) 110 .Where(o => o.Count.Equals(2))
Line 123... Line 123...
123 /// <summary> 123 /// <summary>
124 /// Serialises a dictionary to key-value data. 124 /// Serialises a dictionary to key-value data.
125 /// </summary> 125 /// </summary>
126 /// <param name="data">a dictionary</param> 126 /// <param name="data">a dictionary</param>
127 /// <returns>a key-value data encoded string</returns> 127 /// <returns>a key-value data encoded string</returns>
128 public static string wasKeyValueEncode(Dictionary<string, string> data) 128 public static string Encode(Dictionary<string, string> data)
129 { 129 {
130 return string.Join("&", data.AsParallel().Select(o => string.Join("=", o.Key, o.Value))); 130 return string.Join("&", data.AsParallel().Select(o => string.Join("=", o.Key, o.Value)));
131 } 131 }
Line 132... Line 132...
132   132  
133 /////////////////////////////////////////////////////////////////////////// 133 ///////////////////////////////////////////////////////////////////////////
134 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 134 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
135 /////////////////////////////////////////////////////////////////////////// 135 ///////////////////////////////////////////////////////////////////////////
136 /// <summary>Escapes a dictionary's keys and values for sending as POST data.</summary> 136 /// <summary>Escapes a dictionary's keys and values for sending as POST data.</summary>
137 /// <param name="data">A dictionary containing keys and values to be escaped</param> 137 /// <param name="data">A dictionary containing keys and values to be escaped</param>
138 /// <param name="func">The function to use to escape the keys and values in the dictionary.</param> 138 /// <param name="func">The function to use to escape the keys and values in the dictionary.</param>
139 public static Dictionary<string, string> wasKeyValueEscape(Dictionary<string, string> data, 139 public static Dictionary<string, string> Escape(Dictionary<string, string> data,
140 Func<string, string> func) 140 Func<string, string> func)
141 { 141 {
142 return data.AsParallel().ToDictionary(o => func(o.Key), p => func(p.Value)); 142 return data.AsParallel().ToDictionary(o => func(o.Key), p => func(p.Value));
143 } 143 }