Gapotchenko.FX.Text 2024.1.3

Prefix Reserved
dotnet add package Gapotchenko.FX.Text --version 2024.1.3                
NuGet\Install-Package Gapotchenko.FX.Text -Version 2024.1.3                
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="Gapotchenko.FX.Text" Version="2024.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gapotchenko.FX.Text --version 2024.1.3                
#r "nuget: Gapotchenko.FX.Text, 2024.1.3"                
#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 Gapotchenko.FX.Text as a Cake Addin
#addin nuget:?package=Gapotchenko.FX.Text&version=2024.1.3

// Install Gapotchenko.FX.Text as a Cake Tool
#tool nuget:?package=Gapotchenko.FX.Text&version=2024.1.3                

Overview

The module provides primitives for string and text manipulation.

StringEditor

StringEditor class provided by Gapotchenko.FX.Text module allows you to perform an iterative random-access editing of a string.

It is primarily designed to work in conjunction with Regex class from System.Text.RegularExpressions namespace to efficiently handle an advanced set of tasks when functionality provided by conventional methods like Regex.Replace is just not enough.

More on StringEditor class

Regular Expression Trampolines

Regex trampolines are special functions that allow to gradually convert the conventional string manipulation code into one that uses regex semantics.

Let's take a look on example:

if (name.Equals("[mscorlib]System.Object", StringComparison.Ordinal))
    Console.WriteLine("The name represents a system object.");

The given code is later changed in order to cover the new requirements:

if (name.Equals("[mscorlib]System.Object", StringComparison.Ordinal) ||
    name.Equals("[netstandard]System.Object", StringComparison.Ordinal) ||
    name.Equals("[System.Runtime]System.Object", StringComparison.Ordinal))
{
    Console.WriteLine("The name represents a system object.");
}

It does the job but such mechanical changes may put a toll on code maintainability when they accumulate. You can also spot some amount of code duplication here.

Another approach would be to use Regex class which is readily available in .NET. But that might destroy the expressiveness of string manipulation functions like Equals. If a string function takes a StringComparison parameter then it may become a significant challenge to reliably refactor it to Regex implementation.

That's why Gapotchenko.FX.Text module provides a set of so called regex trampoline functions. They look exactly like Equals, StartsWith, EndsWith, IndexOf but work with regex patterns instead of raw strings. They also end with Regex suffix in their names, so Equals becomes EqualsRegex, StartsWith correspondingly becomes StartsWithRegex, and so on.

And this is how a regex trampoline can be used for the given sample in order to meet the new requirements by a single line change:

using Gapotchenko.FX.Text.RegularExpressions;

if (name.EqualsRegex(@"\[(mscorlib|netstandard|System\.Runtime)]System\.Object", StringComparison.Ordinal))
    Console.WriteLine("The name represents a system object.");

An immediate improvement in expressiveness without duplication.

StringBuilder Polyfills

AppendJoin

StringBuilder.AppendJoin is a method that appeared in later versions of .NET platform. Gapochenko.FX provides a corresponding polyfill that can be used in code targeting older .NET versions.

The benefit of this method is that it combines string.Join and StringBuilder.Append operations in one method, while using the underlying efficiency of the StringBuilder.

Commonly Used Types

  • Gapotchenko.FX.Text.StringEditor

Other Modules

Let's continue with a look at some other modules provided by Gapotchenko.FX:

Or look at the full list of modules.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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.  net9.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 is compatible.  net472 is compatible.  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.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Gapotchenko.FX.Text:

Package Downloads
Gapotchenko.FX.Diagnostics.CommandLine

Provides primitives for command line manipulation.

Gapotchenko.FX.IO

Provides commonly demanded input/output functionality that is missing in conventional .NET platform.

Gapotchenko.FX.Profiles.Core

Represents the Core profile of Gapotchenko.FX.

Gapotchenko.FX.Console

Provides virtual terminal functionality, console traits, and other useful primitives for .NET console apps.

Gapotchenko.FX.Data.Encoding

Provides a quasi-universal framework for data encodings. Supports both synchronous and asynchronous data processing models, including the iterative transcoding.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2024.1.3 591 11/10/2024
2022.2.7 41,332 5/1/2022
2022.2.5 2,784 5/1/2022
2022.1.4 2,225 4/6/2022
2021.2.21 2,311 1/21/2022
2021.2.20 2,254 1/17/2022
2021.1.5 1,587 7/6/2021
2020.2.2-beta 1,136 11/21/2020
2020.1.15 1,846 11/5/2020
2020.1.9-beta 1,244 7/14/2020
2020.1.8-beta 1,191 7/14/2020
2020.1.7-beta 1,211 7/14/2020
2020.1.1-beta 1,331 2/11/2020
2019.3.7 1,700 11/4/2019
2019.2.20 1,676 8/13/2019
2019.1.151 1,863 3/30/2019