using System.Collections.Generic;
internal class WordParser
private readonly HashSet<char> _delimiters;
private readonly HashSet<char> _quotes;
internal WordParser(string delimiters, string quotes)
: this(delimiters.ToCharArray(), quotes.ToCharArray())
private WordParser(IEnumerable<char> delimiters, IEnumerable<char> quotes)
_delimiters = new HashSet<char>(delimiters);
_quotes = new HashSet<char>(quotes);
internal string[] Parse(string line)
var result = new List<string>();
for (int i = 0; i < len; i++)
if (_quotes.Contains(current))
for (int j = i + 1; j < len; j++)
if (j == len - 1 || _delimiters.Contains(line[j + 1]))
string chunk = line.Substring(i + 1, j - i - 1);
if (_delimiters.Contains(current))
for (int j = i; j < len; j++)
if (_delimiters.Contains(line[j]))
result.Add(line.Substring(i, j - i));
result.Add(line.Substring(i));
public static void Main()
var parser = new WordParser(" .,!'\t\n", "\"");
Parse(parser, @"god faith");
Parse(parser, @"""god, faith""! man!");
Console.WriteLine("Hello World");
private static void Parse(WordParser parser, string query)
string[] words = parser.Parse(query);
Console.WriteLine($"Parsing `{query}`");
foreach(var word in words)
Console.WriteLine($"* {word}");