replaysMike / Text.UTF8.Legacy

A legacy replacement for .Net Core 3.0+ UTF8 string encoding/decoding implementation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Text.UTF8.Legacy

nuget nuget Build status Codacy Badge Codacy Badge

A package replacement for .Net Core 3.0+ UTF8 string encoding/decoding and windows-1252 codepage implementation to match .Net Framework behavior.

Description

As of .Net Core 3.0+ a bug was fixed in Microsoft's UTF8 implementation that changes the behavior of UTF8 string encoding and decoding. This package offers the legacy behavior that is still present in .Net Framework today for maximum compatibility when using .Net Core 3.0+. Also included is Windows-1252 codepage support which was made an optional package for .Net Core and no longer included.

Installation

Install Text.UTF8.Legacy from the Package Manager Console:

PM> Install-Package Text.UTF8.Legacy

Usage

UTF8 String decoding

using Text.UTF8.Legacy;

var bytes = // byte representation of a UTF8 string
var utf8String = Text.UTF8.Legacy.Encoding.UTF8.GetString(bytes);

UTF8 String encoding

using Text.UTF8.Legacy;

var string = "A test string";
var bytes = Text.UTF8.Legacy.Encoding.UTF8.GetBytes(string);

Encoding using Windows-1252 codepage encoding:

var string = "A test string";
var codepage1252Encoder = CodePagesEncodingProvider.Instance.GetEncoding(1252);
var bytes = codepage1252Encoder.GetBytes(string);

Compatibility

See .NET Core 3.0 follows Unicode best practices when replacing ill-formed UTF-8 byte sequences Issue Report

About

A legacy replacement for .Net Core 3.0+ UTF8 string encoding/decoding implementation.

License:MIT License


Languages

Language:C# 100.0%