wasSharp – Diff between revs 1 and 4
?pathlinks?
Rev 1 | Rev 4 | |||
---|---|---|---|---|
Line 23... | Line 23... | |||
23 | /// <returns>a commma-separated list of values</returns> |
23 | /// <returns>a commma-separated list of values</returns> |
|
24 | /// <remarks>compliant with RFC 4180</remarks> |
24 | /// <remarks>compliant with RFC 4180</remarks> |
|
25 | public static string wasEnumerableToCSV(IEnumerable<string> l) |
25 | public static string wasEnumerableToCSV(IEnumerable<string> l) |
|
26 | { |
26 | { |
|
27 | string[] csv = l.Select(o => o).ToArray(); |
27 | string[] csv = l.Select(o => o).ToArray(); |
|
- | 28 | char[] escapeCharacters = {'"', ' ', ',', '\r', '\n'}; |
||
28 | Parallel.ForEach(csv.Select((v, i) => new {i, v}), o => |
29 | Parallel.ForEach(csv.Select((v, i) => new {i, v}), o => |
|
29 | { |
30 | { |
|
30 | string cell = o.v.Replace("\"", "\"\""); |
31 | string cell = o.v.Replace("\"", "\"\""); |
|
Line 31... | Line 32... | |||
31 | |
32 | |
|
32 | switch (cell.IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'})) |
33 | switch (cell.IndexOfAny(escapeCharacters)) |
|
33 | { |
34 | { |
|
34 | case -1: |
35 | case -1: |
|
35 | csv[o.i] = cell; |
36 | csv[o.i] = cell; |
|
36 | break; |
37 | break; |