DevSpatium.IO.TextReader 0.0.9-alpha

This is a prerelease version of DevSpatium.IO.TextReader.
dotnet add package DevSpatium.IO.TextReader --version 0.0.9-alpha                
NuGet\Install-Package DevSpatium.IO.TextReader -Version 0.0.9-alpha                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DevSpatium.IO.TextReader" Version="0.0.9-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DevSpatium.IO.TextReader --version 0.0.9-alpha                
#r "nuget: DevSpatium.IO.TextReader, 0.0.9-alpha"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DevSpatium.IO.TextReader as a Cake Addin
#addin nuget:?package=DevSpatium.IO.TextReader&version=0.0.9-alpha&prerelease

// Install DevSpatium.IO.TextReader as a Cake Tool
#tool nuget:?package=DevSpatium.IO.TextReader&version=0.0.9-alpha&prerelease                

TextReaderWrapper - Reads Text by Specified Pattern

A wrapper on top of the standard System.IO.TextReader, which supports sequential asynchronous reading according to a given pattern, and extracts the required pieces of text.

This reader can be useful for parsing texts of custom predefined formats, for automating manual time-consuming copy-paste tasks, or if you are going to implement some code that should have non-trivial reading logic.

Besides, the reader provides an API for extending its internal operations and the pattern syntax.

Getting Started

The pattern can essentially contain two commands: R and S (leaving all their varieties aside for now). R stands for a Read operation. Such an operation reads characters from the source text, converts them into a single string, and adds the string to the output collection. S, in its turn, stands for a Skip operation, which simply skips the required characters.

Example #1

Input

Hello World

Pattern

// R[5] - read 5 chars
// S.   - skip 1 char
// R>   - read remaining chars
const string pattern = @"R[5] S. R>";

Output

["Hello", "World"]

Example #2

Input

* Apple
* Lemon
* Pear
* Kiwi

Pattern

// S>     - skip line
// S+'* ' - skip * and space
// R>     - read remaining chars in the line
// {2}    - repeat twice
const string pattern = @"(S> S+'* ' R>){2}";

Output

["Lemon", "Kiwi"]

Example #3

Input

* 7:00  Wake-up
* 9:00  At work
* 10:00 Stand-up meeting
* 12:00 Lunch
* 16:00 Yet another meeting
...

Pattern

// S|/rgx/ - skip all characters up to the string that matches the specified regex
// {&R}    - and read the matched string
// S+/\s*/ - skip whitespace
// R>      - read remaining chars in the line
// *       - repeat till the end of the text
const string pattern = @"
(
    S| /\d{1,2}:\d{2}/ {&R}
    S+ /\s*/
    R>
)*
";

Output

[
    "7:00",
    "Wake-up",
    "9:00",
    "At work",
    "10:00",
    "Stand-up meeting",
    "12:00",
    "Lunch",
    "16:00",
    "Yet another meeting",
    ...
]

TextReaderWrapper

This is the "entry-point" class that wraps System.IO.TextReader using the following constructor:

public TextReaderWrapper(System.IO.TextReader underlyingReader)
ReadAsync()
// `pattern` - defines how to read the source text.
// `output` - contains the strings read from the source text.
public async Task ReadAsync(string pattern, ICollection<string> output, CancellationToken cancelToken = default)
const string pattern = @"(R.)*";
const string text = "Lorem ipsum";
var output = new List<string>();
var stringReader = new StringReader(text);
using (var textReaderWrapper = new TextReaderWrapper(stringReader))
{
    textReaderWrapper.ReadAsync(pattern, output).Wait();
}

// output: ["L", "o", "r", "e", "m", " ", "i", "p", "s", "u", "m"]

See more here!


Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.9-alpha 170 2/3/2022