Korero – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using System.Collections.Generic;
2 using System.Linq;
3  
4 namespace Korero.Serialization
5 {
6 public static class Extensions
7 {
8 #region Public Methods
9  
10 ///////////////////////////////////////////////////////////////////////////
11 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
12 ///////////////////////////////////////////////////////////////////////////
13  
14 /// <summary>
15 /// Converts successive comma-separated values to key-value pairs.
16 /// </summary>
17 /// <returns>key-value pairs of successive comma-separate values</returns>
18 public static IEnumerable<KeyValuePair<string, string>> ToKeyValue(this CSV csv)
19 {
20 foreach (var kvp in csv.Select((o, p) => new {o, p})
21 .GroupBy(q => q.p / 2, q => q.o))
22 {
23 var kv = kvp.ToArray();
24  
25 if (kv.Length != 2)
26 {
27 break;
28 }
29  
30 var k = kv[0];
31  
32 if (string.IsNullOrEmpty(k))
33 {
34 continue;
35 }
36  
37 var v = kv[1];
38  
39 yield return new KeyValuePair<string, string>(k, v);
40 }
41 }
42  
43 #endregion
44 }
45 }