Extension methods for System.IO.TextReader.
Namespace: Cadenza.IO
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
See Also: Inherited members from object.
⊟ Public Methods
⊟ Lines Method
Creates an IEnumerable<string> which will return all lines of text from self while System.IO.TextReader.Closeing self.
public static IEnumerable<string> Lines (this System.IO.TextReader self)⊟ See Also
⊟ Parameters
- self
- A System.IO.TextReader to read lines from.
⊟ Returns
An IEnumerable<string> which will return all lines of text from self.⊟ Exceptions
Type Reason ArgumentNullException self is null. ⊟ Remarks
This method is implemented by using deferred execution.
self is disposed.
Note: A "line of text" is the same as that used by System.IO.TextReader.ReadLine.⊟ Requirements
Namespace: Cadenza.IO
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Lines Method
Creates an IEnumerable<string> which will return all lines of text from self while optionally System.IO.TextReader.Closeing self.
public static IEnumerable<string> Lines (this System.IO.TextReader self, TextReaderCodaOptions options)⊟ See Also
⊟ Parameters
- self
- A System.IO.TextReader to read lines from.
- options
- A Cadenza.IO.TextReaderCodaOptions controlling method execution.
⊟ Returns
An IEnumerable<string> which will return all lines of text from self.⊟ Exceptions
Type Reason ArgumentException options has an unsupported value. ArgumentNullException self is null. ⊟ Remarks
This method is implemented by using deferred execution.
If options contains TextReaderCodaOptions.CloseReader, then self will be System.IO.TextReader.Closeed once all lines have been returned; if TextReaderCodaOptions.CloseReader is not specified, then the System.IO.TextReader will not be disposed.
Note: A "line of text" is the same as that used by System.IO.TextReader.ReadLine.⊟ Requirements
Namespace: Cadenza.IO
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Tokens Method
Creates an IEnumerable<string> which will return all words from self while optionally System.IO.TextReader.Closeing self.
public static IEnumerable<string> Tokens (this System.IO.TextReader self, params Func<Nullable<System.Char>,System.Char,System.Boolean>[] categories)⊟ Parameters
- self
- A System.IO.TextReader to extract tokens from.
- categories
- A Func<Nullable<System.Char>,System.Char,System.Boolean> array containing the different categories of characters that determines what makes up a "token." If the Nullable<char> parameter is null, then the char is the first character within the token; otherwise, the Nullable<char> parameter contains the character preceding the char. The delegate should return true if the char is a supported character; otherwise, false should be returned.
⊟ Returns
An IEnumerable<string> which will return all tokens from self.⊟ Exceptions
Type Reason ArgumentException categories is empty. ArgumentNullException self is null, or categories is null. ⊟ Remarks
This method is implemented by using deferred execution.
If options contains TextReaderCodaOptions.CloseReader, then self will be System.IO.TextReader.Closeed once all lines have been returned.
Note:A "token" is determined by categories, and is any contiguous sequence of characters for which the same categories index returns true, starting from the first delegate. This allows a "some characters are more important than others" philosphy, allowing e.g. parenthesis to be returned separately from alphanumeric characters, even if no whitespace separates them.
C# Example var r = new MyStringReader ("(append 3.5 \"hello, world!\")"); var words = r.Tokens ( (p, c) => char.IsLetterOrDigit (c) || c == '.', (p, c) => !char.IsWhiteSpace (c)) .ToArray (); Assert.IsTrue (r.WasDisposed); Assert.IsTrue ( new[]{"(", "append", "3.5", "\"", "hello", ",", "world", "!\")"} .SequenceEqual (words)); r = new MyStringReader ("Hello, world!"); Assert.AreEqual (false, r.Tokens (TextReaderCodaOptions.None, (p, c) => false).Any ()); Assert.IsFalse (r.WasDisposed);⊟ Requirements
Namespace: Cadenza.IO
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Tokens Method
Creates an IEnumerable<string> which will return all words from self while optionally System.IO.TextReader.Closeing self.
public static IEnumerable<string> Tokens (this System.IO.TextReader self, TextReaderCodaOptions options, params Func<Nullable<System.Char>,System.Char,System.Boolean>[] categories)⊟ Parameters
- self
- A System.IO.TextReader to extract tokens from.
- options
- A Cadenza.IO.TextReaderCodaOptions controlling method execution.
- categories
- A Func<Nullable<System.Char>,System.Char,System.Boolean> array containing the different categories of characters that determines what makes up a "token." If the Nullable<char> parameter is null, then the char is the first character within the token; otherwise, the Nullable<char> parameter contains the character preceding the char. The delegate should return true if the char is a supported character; otherwise, false should be returned.
⊟ Returns
An IEnumerable<string> which will return all tokens from self.⊟ Exceptions
Type Reason ArgumentException options contains an invalid value, or categories is empty. ArgumentNullException self is null, or categories is null. ⊟ Remarks
This method is implemented by using deferred execution.
If options contains TextReaderCodaOptions.CloseReader, then self will be System.IO.TextReader.Closeed once all lines have been returned.
Note:A "token" is determined by categories, and is any contiguous sequence of characters for which the same categories index returns true, starting from the first delegate. This allows a "some characters are more important than others" philosphy, allowing e.g. parenthesis to be returned separately from alphanumeric characters, even if no whitespace separates them.
C# Example var r = new MyStringReader ("(append 3.5 \"hello, world!\")"); var words = r.Tokens ( (p, c) => char.IsLetterOrDigit (c) || c == '.', (p, c) => !char.IsWhiteSpace (c)) .ToArray (); Assert.IsTrue (r.WasDisposed); Assert.IsTrue ( new[]{"(", "append", "3.5", "\"", "hello", ",", "world", "!\")"} .SequenceEqual (words)); r = new MyStringReader ("Hello, world!"); Assert.AreEqual (false, r.Tokens (TextReaderCodaOptions.None, (p, c) => false).Any ()); Assert.IsFalse (r.WasDisposed);⊟ Requirements
Namespace: Cadenza.IO
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Words Method
Creates an IEnumerable<string> which will return all words from self while System.IO.TextReader.Closeing self.
public static IEnumerable<string> Words (this System.IO.TextReader self)⊟ See Also
⊟ Parameters
- self
- A System.IO.TextReader to extract words from.
⊟ Returns
An IEnumerable<string> which will return all words from self.⊟ Exceptions
Type Reason ArgumentNullException self is null, or categories is null. ⊟ Remarks
This method is implemented by using deferred execution.
self is disposed.
Note:A "word" is any contiguous sequence of characters for which char.IsWhiteSpace(char) returns false.
C# Example MyStringReader r = new MyStringReader (" (skip leading,\r\n\tand trailing\vwhitespace) "); string[] words = r.Words ().ToArray (); Assert.IsTrue (r.WasDisposed); Assert.AreEqual (5, words.Length); Assert.AreEqual ("(skip", words [0]); Assert.AreEqual ("leading,", words [1]); Assert.AreEqual ("and", words [2]); Assert.AreEqual ("trailing", words [3]); Assert.AreEqual ("whitespace)", words [4]); r = new MyStringReader ("notext"); words = r.Words (TextReaderCodaOptions.None).ToArray (); Assert.IsFalse (r.WasDisposed); Assert.AreEqual (1, words.Length); Assert.AreEqual ("notext", words [0]); r = new MyStringReader ("1 2 3 4"); Assert.AreEqual ("1", r.Words ().First ()); Assert.AreEqual ("2", r.Words ().First ()); Assert.AreEqual ("3", r.Words ().First ()); Assert.AreEqual ("4", r.Words ().First ());⊟ Requirements
Namespace: Cadenza.IO
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0
⊟ Words Method
Creates an IEnumerable<string> which will return all words from self while optionally System.IO.TextReader.Closeing self.
public static IEnumerable<string> Words (this System.IO.TextReader self, TextReaderCodaOptions options)⊟ See Also
⊟ Parameters
- self
- A System.IO.TextReader to extract words from.
- options
- A Cadenza.IO.TextReaderCodaOptions controlling method execution.
⊟ Returns
An IEnumerable<string> which will return all words from self.⊟ Exceptions
Type Reason ArgumentException options contains an invalid value. ArgumentNullException self is null. ⊟ Remarks
This method is implemented by using deferred execution.
If options contains TextReaderCodaOptions.CloseReader, then self will be System.IO.TextReader.Closeed once all lines have been returned; if TextReaderCodaOptions.CloseReader is not specified, then the System.IO.TextReader will not be disposed.
Note:A "word" is any contiguous sequence of characters for which char.IsWhiteSpace(char) returns false.
C# Example MyStringReader r = new MyStringReader (" (skip leading,\r\n\tand trailing\vwhitespace) "); string[] words = r.Words ().ToArray (); Assert.IsTrue (r.WasDisposed); Assert.AreEqual (5, words.Length); Assert.AreEqual ("(skip", words [0]); Assert.AreEqual ("leading,", words [1]); Assert.AreEqual ("and", words [2]); Assert.AreEqual ("trailing", words [3]); Assert.AreEqual ("whitespace)", words [4]); r = new MyStringReader ("notext"); words = r.Words (TextReaderCodaOptions.None).ToArray (); Assert.IsFalse (r.WasDisposed); Assert.AreEqual (1, words.Length); Assert.AreEqual ("notext", words [0]); r = new MyStringReader ("1 2 3 4"); Assert.AreEqual ("1", r.Words ().First ()); Assert.AreEqual ("2", r.Words ().First ()); Assert.AreEqual ("3", r.Words ().First ()); Assert.AreEqual ("4", r.Words ().First ());⊟ Requirements
Namespace: Cadenza.IO
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0