public static IEnumerable<string> Lines(this TextReader self, TextReaderRocksOptions options) { Check.Self (self); CheckOptions (options); return CreateLineIterator (self, options); }
private static void CheckOptions(TextReaderRocksOptions options) { if (options != TextReaderRocksOptions.None && options != TextReaderRocksOptions.CloseReader) { throw new ArgumentException("options", "Invalid `options' value."); } }
public static IEnumerable <string> Lines(this TextReader self, TextReaderRocksOptions options) { Check.Self(self); CheckOptions(options); return(CreateLineIterator(self, options)); }
public static IEnumerable <string> Words(this TextReader self, TextReaderRocksOptions options) { Check.Self(self); CheckOptions(options); return(Tokens(self, options, (p, c) => !char.IsWhiteSpace(c))); }
private static IEnumerable <string> CreateTokensIterator(TextReader self, TextReaderRocksOptions options, Func <char?, char, bool>[] categories) { try { var cats = categories.Select( c => Lambda.F((StringBuilder buf, char ch) => c(buf.Length == 0 ? ((char?)null) : (char?)buf [buf.Length - 1], ch))); foreach (var t in Chars(self).Tokens( new StringBuilder(), (buf, c) => buf.Append(c), buf => { var r = buf.ToString(); buf.Length = 0; return(Tuple.Create(r, buf)); }, cats.ToArray())) { yield return(t); } } finally { if ((options & TextReaderRocksOptions.CloseReader) != 0) { self.Close(); self.Dispose(); } } }
public static IEnumerable<string> Tokens(this TextReader self, TextReaderRocksOptions options, params Func<char?, char, bool>[] categories) { Check.Self (self); CheckOptions (options); Check.Categories (categories); if (categories.Length == 0) throw new ArgumentException ("categories", "Must provide at least one catagory"); return CreateTokensIterator (self, options, categories); }
public static IEnumerable <string> Tokens(this TextReader self, TextReaderRocksOptions options, params Func <char?, char, bool>[] categories) { Check.Self(self); CheckOptions(options); Check.Categories(categories); if (categories.Length == 0) { throw new ArgumentException("categories", "Must provide at least one catagory"); } return(CreateTokensIterator(self, options, categories)); }
private static IEnumerable <string> CreateLineIterator(TextReader self, TextReaderRocksOptions options) { try { string line; while ((line = self.ReadLine()) != null) { yield return(line); } } finally { if ((options & TextReaderRocksOptions.CloseReader) != 0) { self.Close(); self.Dispose(); } } }
public static IEnumerable<string> Words(this TextReader self, TextReaderRocksOptions options) { Check.Self (self); CheckOptions (options); return Tokens (self, options, (p, c) => !char.IsWhiteSpace (c)); }
private static IEnumerable<string> CreateTokensIterator(TextReader self, TextReaderRocksOptions options, Func<char?, char, bool>[] categories) { try { var cats = categories.Select ( c => Lambda.F ((StringBuilder buf, char ch) => c (buf.Length == 0 ? ((char?) null) : (char?) buf [buf.Length-1], ch))); foreach (var t in Chars (self).Tokens ( new StringBuilder (), (buf, c) => buf.Append (c), buf => { var r = buf.ToString (); buf.Length = 0; return Tuple.Create (r, buf); }, cats.ToArray ())) yield return t; } finally { if ((options & TextReaderRocksOptions.CloseReader) != 0) { self.Close (); self.Dispose (); } } }
private static IEnumerable<string> CreateLineIterator(TextReader self, TextReaderRocksOptions options) { try { string line; while ((line = self.ReadLine ()) != null) yield return line; } finally { if ((options & TextReaderRocksOptions.CloseReader) != 0) { self.Close (); self.Dispose (); } } }
private static void CheckOptions(TextReaderRocksOptions options) { if (options != TextReaderRocksOptions.None && options != TextReaderRocksOptions.CloseReader) throw new ArgumentException ("options", "Invalid `options' value."); }