public static bool TryReadUntilAny(this ICharReader reader, out string result, ISet <char> charset) { while (true) { if (!reader.HasNext()) { result = string.Empty; return(false); } var next = reader.PeekNext(); if (!charset.Contains(next)) { break; } reader.ReadNext(); } var builder = new StringBuilder(); while (reader.HasNext()) { var next = reader.ReadNext(); if (charset.Contains(next)) { break; } builder.Append(next); } result = builder.ToString(); return(true); }
public static string ReadUntilAny(this ICharReader reader, ISet <char> charset) { while (true) { if (!reader.HasNext()) { return(null); } var next = reader.PeekNext(); if (!charset.Contains(next)) { break; } reader.ReadNext(); } var result = new StringBuilder(); while (reader.HasNext()) { var next = reader.ReadNext(); if (charset.Contains(next)) { break; } result.Append(next); } return(result.ToString()); }