EscapeRoute 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package EscapeRoute --version 0.0.1
NuGet\Install-Package EscapeRoute -Version 0.0.1
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="EscapeRoute" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EscapeRoute --version 0.0.1
#r "nuget: EscapeRoute, 0.0.1"
#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 EscapeRoute as a Cake Addin
#addin nuget:?package=EscapeRoute&version=0.0.1

// Install EscapeRoute as a Cake Tool
#tool nuget:?package=EscapeRoute&version=0.0.1

EscapeRoute

Build Status NuGet

Selectively trim and escape text files into JSON friendly strings. Supports all JSON escape characters and Unicode characters that can be represented in the form \u(4 digit hex).

Currently suports the following behaviours/special characters (Default):

  • Tab (\t):
    • Strip
    • Escape
  • New line (\n):
    • Strip
    • Escape
  • Carriage return (\r):
    • Strip
    • Escape
  • Backspace (\b):
    • Strip
    • Escape
  • Form feed (\f):
    • Strip
    • Escape
  • Backslash (\\):
    • Strip
    • Escape
  • Unicode (\uXXXX):
    • Strip
    • Escape
  • Single quotes '' (\'):
    • Escape
  • Double quotes "" (\"):
    • Escape
  • Trim
    • None
    • Start
    • End
    • Both

Usage

Use the namespace JackWFinlay.EscapeRoute:

using JackWFinlay.EscapeRoute;

EscapeRoute allows the use of Files or Strings to load in the data to be escaped and trimmed. These can be called synchronously or asynchronously.

E.g. ParseFile and ParseStringAsync

test file: test1.txt

using JackWFinlay.EscapeRoute;

namespace Example
{
    public class ExampleProgram
    {
        public void TestDefaultBehaviourFromFile()
        {
            String fileLocation = $"{workspaceFolder}/test-files/test1.txt";
            IEscapeRoute escapeRoute = new EscapeRoute();
            String expected = "The quick brown fox jumps over the lazy dog.";
            String result = escapeRoute.ParseFile(fileLocation);
            
            String areEqual = expected.Equals(result) ? "" : " not";
            Console.WriteLine($"The strings are{areEqual} equal"); 
            // "The strings are equal"
        }
    }
}

EscapeRoute allows configuration using a EscapeRouteConfiguration object, which is passed to the EscapeRoute constructor:

namespace Example
{
    public class ExampleProgram
    {
        internal readonly static String inputString1 = 
            "The quick \r\n\t\bbrown fox jumps \r\n\t\bover the lazy dog.";

        public async void TestEscapeAllBehaviourFromStringAsync()
        {
            EscapeRouteConfiguration config = new EscapeRouteConfiguration
            {
                TabBehaviour = TabBehaviour.Escape,
                NewLineBehaviour = NewLineBehaviour.Escape,
                CarriageReturnBehaviour = CarriageReturnBehaviour.Escape,
                BackspaceBehaviour = BackspaceBehaviour.Escape,
                TrimBehaviour = TrimBehaviour.None
            };
            IEscapeRoute escapeRoute = new EscapeRoute(config);
            String expected = @"The quick \r\n\t\bbrown fox jumps \r\n\t\bover the lazy dog.";
            String result = await escapeRoute.ParseStringAsync(inputString1);

            Console.WriteLine(result); 
            // "The quick \r\n\t\bbrown fox jumps \r\n\t\bover the lazy dog."
            
            String areEqual = expected.Equals(result) ? "" : " not";
            Console.WriteLine($"The strings are{areEqual} equal"); 
            // "The strings are equal"
        }
    }
}

Unicode

EscapeRoute supports the translation of Unicode characters to the JSON escape form \u(4 hex digits)

E.g. ʖ = \u0296

namespace Example
{
    public class ExampleUnicodeProgram
    {
        internal readonly static String unicodeString1 = "( ͡° ͜ʖ ͡°)";

        public async void TestEscapeUnicodeFromStringAsync()
        {
            // Escape is default behaviour for Unicode characters,
            // no configuration required.
            IEscapeRoute escapeRoute = new EscapeRoute();
            String expected = @"( \u0361\u00b0 \u035c\u0296 \u0361\u00b0)";
            String result = await escapeRoute.ParseStringAsync(unicodeString1);
            
            Console.WriteLine(result); 
            // "( \u0361\u00b0 \u035c\u0296 \u0361\u00b0)"
            
            String areEqual = expected.Equals(result) ? "" : " not";
            Console.WriteLine($"The strings are{areEqual} equal"); 
            // "The strings are equal"
        }
    }
}

License

MIT

See license.md for details.

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 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.
  • .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.3 1,946 6/8/2021
0.0.2 6,570 9/12/2020
0.0.1 13,658 12/24/2017

Initial version