Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public fields | Public static fields | Public Member Functions | List of all members
Loyc.WTF8Encoding Class Reference

An Encoding for WTF-8: UTF-8 extended so that unpaired UTF-16 surrogates are encoded as themselves (3 bytes, ED A0-BF 80-BF) instead of being replaced with U+FFFD. This makes every .NET string round-trippable, which Encoding.UTF8 does not guarantee. See https://simonsapin.github.io/wtf-8/ More...


Source file:
Inheritance diagram for Loyc.WTF8Encoding:

Remarks

An Encoding for WTF-8: UTF-8 extended so that unpaired UTF-16 surrogates are encoded as themselves (3 bytes, ED A0-BF 80-BF) instead of being replaced with U+FFFD. This makes every .NET string round-trippable, which Encoding.UTF8 does not guarantee. See https://simonsapin.github.io/wtf-8/

Well-formed UTF-8 input/output is unchanged, so this is a drop-in replacement for UTF-8 without byte order marks. Decoding treats surrogate sequences as valid; other malformed bytes become U+FFFD as usual. Encoding is delegated to Encoding.UTF8 for surrogate-free spans, so speed is close to UTF-8 except on strings that actually contain surrogates.

Public fields

override string EncodingName => "WTF-8"
 
override string WebName => "wtf-8"
 

Public static fields

static readonly WTF8Encoding Instance = new WTF8Encoding()
 

Public Member Functions

override int GetMaxByteCount (int charCount)
 
override int GetMaxCharCount (int byteCount)
 
override int GetByteCount (char[] chars, int index, int count)
 
override int GetBytes (char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
 
override int GetCharCount (byte[] bytes, int index, int count)
 
override int GetChars (byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
 
override int GetByteCount (ReadOnlySpan< char > chars)
 
override int GetBytes (ReadOnlySpan< char > chars, Span< byte > bytes)
 
override int GetCharCount (ReadOnlySpan< byte > bytes)
 
override int GetChars (ReadOnlySpan< byte > bytes, Span< char > chars)
 
new string GetString (ReadOnlySpan< byte > bytes)