Updates to Utilities

This commit is contained in:
Tal Aloni 2016-12-27 10:08:22 +02:00
parent 6cb61ca63e
commit 5508c749ce
13 changed files with 417 additions and 13 deletions

View file

@ -96,18 +96,30 @@ namespace Utilities
}
public static List<string> SplitIgnoreQuotedSeparators(string str, char separator)
{
return SplitIgnoreQuotedSeparators(str, separator, StringSplitOptions.None);
}
public static List<string> SplitIgnoreQuotedSeparators(string str, char separator, StringSplitOptions options)
{
List<string> result = new List<string>();
int nextEntryIndex = 0;
int separatorIndex = IndexOfUnquotedChar(str, separator);
while (separatorIndex >= nextEntryIndex)
{
result.Add(str.Substring(nextEntryIndex, separatorIndex - nextEntryIndex));
string entry = str.Substring(nextEntryIndex, separatorIndex - nextEntryIndex);
if (options != StringSplitOptions.RemoveEmptyEntries || entry != String.Empty)
{
result.Add(entry);
}
nextEntryIndex = separatorIndex + 1;
separatorIndex = IndexOfUnquotedChar(str, separator, nextEntryIndex);
}
result.Add(str.Substring(nextEntryIndex));
string lastEntry = str.Substring(nextEntryIndex);
if (options != StringSplitOptions.RemoveEmptyEntries || lastEntry != String.Empty)
{
result.Add(lastEntry);
}
return result;
}
}