wasSharp – Diff between revs 55 and 56

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 55 Rev 56
Line 4... Line 4...
4 // rights of fair usage, the disclaimer and warranty conditions. // 4 // rights of fair usage, the disclaimer and warranty conditions. //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
Line 6... Line 6...
6   6  
7 using System; 7 using System;
-   8 using System.Collections.Generic;
8 using System.Collections.Generic; 9 using System.IO;
-   10 using System.Linq;
-   11 using System.Text;
Line 9... Line 12...
9 using System.Linq; 12 using System.Threading.Tasks;
10   13  
11 namespace wasSharp.Languages 14 namespace wasSharp.Languages
12 { 15 {
13 public static class KeyValue 16 public static class KeyValue
14 { 17 {
15 /////////////////////////////////////////////////////////////////////////// 18 ///////////////////////////////////////////////////////////////////////////
16 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 19 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
17 /////////////////////////////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////////////////////////////
18 /// <summary> 21 /// <summary>
19 /// Returns the value of a key from a key-value data string. 22 /// Returns the value of a key from a key-value data string.
20 /// </summary> 23 /// </summary>
21 /// <returns>true if the key was found in data</returns> 24 /// <returns>true if the key was found in data</returns>
22 public static string Get(string key, string data) 25 public static string Get(string key, string data)
Line 31... Line 34...
31   34  
32 /////////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////////
33 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 36 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
34 /////////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////////
35 /// <summary> 38 /// <summary>
36 /// Returns a key-value data string with a key set to a given value. 39 /// Returns a key-value data string with a key set to a given value.
37 /// </summary> 40 /// </summary>
38 /// <returns> 41 /// <returns>
39 /// a key-value data string or the empty string if either key or 42 /// a key-value data string or the empty string if either key or
40 /// value are empty 43 /// value are empty
41 /// </returns> 44 /// </returns>
42 public static string Set(string key, string value, string data) 45 public static string Set(string key, string value, string data)
43 { 46 {
44 return string.Join("&", string.Join("&", data.Split('&') 47 return string.Join("&", string.Join("&", data.Split('&')
Line 50... Line 53...
50   53  
51 /////////////////////////////////////////////////////////////////////////// 54 ///////////////////////////////////////////////////////////////////////////
52 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 55 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
53 /////////////////////////////////////////////////////////////////////////// 56 ///////////////////////////////////////////////////////////////////////////
54 /// <summary> 57 /// <summary>
55 /// Deletes a key-value pair from a string referenced by a key. 58 /// Deletes a key-value pair from a string referenced by a key.
56 /// </summary> 59 /// </summary>
57 /// <returns>a key-value pair string</returns> 60 /// <returns>a key-value pair string</returns>
58 public static string Delete(string key, string data) 61 public static string Delete(string key, string data)
59 { 62 {
Line 66... Line 69...
66   69  
67 /////////////////////////////////////////////////////////////////////////// 70 ///////////////////////////////////////////////////////////////////////////
68 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 71 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
69 /////////////////////////////////////////////////////////////////////////// 72 ///////////////////////////////////////////////////////////////////////////
70 /// <summary> 73 /// <summary>
71 /// Decodes key-value pair data to a dictionary. 74 /// Decodes key-value pair data to a dictionary.
72 /// </summary> 75 /// </summary>
73 /// <returns>a dictionary containing the keys and values</returns> 76 /// <returns>a dictionary containing the keys and values</returns>
74 public static Dictionary<string, string> Decode(string data) 77 public static Dictionary<string, string> Decode(string data)
75 { 78 {
Line 88... Line 91...
88   91  
89 /////////////////////////////////////////////////////////////////////////// 92 ///////////////////////////////////////////////////////////////////////////
90 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 93 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
91 /////////////////////////////////////////////////////////////////////////// 94 ///////////////////////////////////////////////////////////////////////////
92 /// <summary> 95 /// <summary>
93 /// Serialises a dictionary to key-value data. 96 /// Serialises a dictionary to key-value data.
94 /// </summary> 97 /// </summary>
95 /// <returns>a key-value data encoded string</returns> 98 /// <returns>a key-value data encoded string</returns>
96 public static string Encode(Dictionary<string, string> data) 99 public static string Encode(Dictionary<string, string> data)
97 { 100 {
Line 100... Line 103...
100   103  
101 /////////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////////
102 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 105 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
103 /////////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////////
104 /// <summary> 107 /// <summary>
105 /// Serialises a dictionary to key-value data. 108 /// Serializes a dictionary to key-value data.
-   109 /// </summary>
106 /// </summary> 110 /// <param name="data">an input string</param>
107 /// <returns>a key-value data encoded string</returns> 111 /// <returns>a key-value data encoded string</returns>
108 public static string Encode(IEnumerable<KeyValuePair<string, string>> data) 112 public static string Encode(IEnumerable<KeyValuePair<string, string>> data)
109 { 113 {
110 return string.Join("&", data.AsParallel().Select(o => string.Join("=", o.Key, o.Value))); 114 return string.Join("&", data.AsParallel().Select(o => string.Join("=", o.Key, o.Value)));
Line 111... Line 115...
111 } 115 }
-   116  
-   117 ///////////////////////////////////////////////////////////////////////////
-   118 // Copyright (C) 2018 Wizardry and Steamworks - License: GNU GPLv3 //
-   119 ///////////////////////////////////////////////////////////////////////////
-   120 /// <summary>
-   121 /// Asynchronously serializes a dictionary to key-value data.
-   122 /// </summary>
-   123 /// <param name="data">an input string</param>
-   124 /// <returns>a key-value data encoded string</returns>
-   125 public static string Encode(IEnumerable<KeyValuePair<Task<string>, Task<string>>> data)
-   126 {
-   127 return string.Join("&", data.AsParallel().Select(o => string.Join("=", o.Key.Result, o.Value.Result)));
-   128 }
112   129  
113 /////////////////////////////////////////////////////////////////////////// 130 ///////////////////////////////////////////////////////////////////////////
114 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 131 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
115 /////////////////////////////////////////////////////////////////////////// 132 ///////////////////////////////////////////////////////////////////////////
116 /// <summary> 133 /// <summary>
117 /// Escapes a dictionary's keys and values for sending as POST data. 134 /// Escapes a dictionary's keys and values for sending as POST data.
118 /// </summary> 135 /// </summary>
119 public static IEnumerable<KeyValuePair<string, string>> Escape(IEnumerable<KeyValuePair<string, string>> data, 136 public static IEnumerable<KeyValuePair<string, string>> Escape(IEnumerable<KeyValuePair<string, string>> data,
120 Func<string, string> func) 137 Func<string, string> func)
121 { 138 {
-   139 return data.AsParallel().ToDictionary(o => func(o.Key), p => func(p.Value));
-   140 }
-   141  
-   142 ///////////////////////////////////////////////////////////////////////////
-   143 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
-   144 ///////////////////////////////////////////////////////////////////////////
-   145 /// <summary>
-   146 /// Escapes a dictionary's keys and values for sending as POST data.
-   147 /// </summary>
-   148 public static IEnumerable<KeyValuePair<Task<string>, Task<string>>> EscapeAsync(IEnumerable<KeyValuePair<string, string>> data,
-   149 Func<string, Task<string>> func)
-   150 {
122 return data.AsParallel().ToDictionary(o => func(o.Key), p => func(p.Value)); 151 return data.AsParallel().ToDictionary(async o => await func(o.Key), async p => await func(p.Value));
123 } 152 }