wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 26  →  ?path2? @ 27
/CSV.cs
@@ -25,7 +25,7 @@
return string.Join(",",
input
.Select(o => o.Replace("\"", "\"\""))
.Select(o => o.IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'}).Equals(-1) ? o : "\"" + o + "\""));
.Select(o => o.IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' }).Equals(-1) ? o : "\"" + o + "\""));
}
 
///////////////////////////////////////////////////////////////////////////
@@ -41,10 +41,10 @@
return string.Join(",", input.Keys.Select(o => o.ToString()).Zip(input.Values.Select(o => o.ToString()),
(o, p) =>
string.Join(",",
o.Replace("\"", "\"\"").IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'}).Equals(-1)
o.Replace("\"", "\"\"").IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' }).Equals(-1)
? o
: "\"" + o + "\"",
p.Replace("\"", "\"\"").IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'}).Equals(-1)
p.Replace("\"", "\"\"").IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' }).Equals(-1)
? p
: "\"" + p + "\"")));
}
@@ -58,10 +58,10 @@
/// <returns>key-value pairs of successive comma-separate values</returns>
public static IEnumerable<KeyValuePair<string, string>> ToKeyValue(string input)
{
return ToEnumerable(input).AsParallel().Select((o, p) => new {o, p})
.GroupBy(q => q.p/2, q => q.o)
return ToEnumerable(input).AsParallel().Select((o, p) => new { o, p })
.GroupBy(q => q.p / 2, q => q.o)
.Select(o => o.ToArray())
.TakeWhile(o => o.Length%2 == 0)
.TakeWhile(o => o.Length % 2 == 0)
.Where(o => !string.IsNullOrEmpty(o[0]) || !string.IsNullOrEmpty(o[1]))
.ToDictionary(o => o[0], p => p[1]).Select(o => o);
}
@@ -80,11 +80,11 @@
var value = input.Value.ToString();
 
return string.Join(",", key
.Replace("\"", "\"\"").IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'}).Equals(-1)
.Replace("\"", "\"\"").IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' }).Equals(-1)
? key
: "\"" + key + "\"", value
.Replace("\"", "\"\"")
.IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'})
.IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' })
.Equals(-1)
? value
: "\"" + value + "\"");
@@ -137,4 +137,4 @@
yield return m.ToString();
}
}
}
}