EscapeRoute 0.0.1

JackWFinlay.EscapeRoute

Convert strings and files into JSON friendly strings.

Install-Package EscapeRoute -Version 0.0.1
dotnet add package EscapeRoute --version 0.0.1
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 '' (\&#39;):
    • Escape
  • Double quotes "" (\&quot;):
    • 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.

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 '' (\&#39;):
    • Escape
  • Double quotes "" (\&quot;):
    • 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.

Release Notes

Initial version

  • .NETStandard 2.0

    • No dependencies.

Version History

Version Downloads Last updated
0.0.1 925 12/24/2017