Skip to content

Commit

Permalink
Expose Encoding.Latin1 (#37550)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Jun 7, 2020
1 parent 4b339d8 commit e8964cc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ internal static class HttpRuleParser
internal const int MaxInt64Digits = 19;
internal const int MaxInt32Digits = 10;

// iso-8859-1, Western European (ISO)
internal static readonly Encoding DefaultHttpEncoding = Encoding.GetEncoding(28591);
internal static Encoding DefaultHttpEncoding => Encoding.Latin1;

private static bool[] CreateTokenChars()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,8 @@ public bool IsReadOnly

public static Encoding ASCII => ASCIIEncoding.s_default;

// Returns an encoding for the Latin1 character set. The returned encoding
// will be an instance of the Latin1Encoding class.
//
// This is for our optimizations
private static Encoding Latin1 => Latin1Encoding.s_default;
/// <summary>Gets an encoding for the Latin1 character set (ISO-8859-1).</summary>
public static Encoding Latin1 => Latin1Encoding.s_default;

// Returns the number of bytes required to encode the given character
// array.
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10201,6 +10201,7 @@ protected Encoding(int codePage, System.Text.EncoderFallback? encoderFallback, S
public virtual bool IsMailNewsSave { get { throw null; } }
public bool IsReadOnly { get { throw null; } }
public virtual bool IsSingleByte { get { throw null; } }
public static System.Text.Encoding Latin1 { get { throw null; } }
public virtual System.ReadOnlySpan<byte> Preamble { get { throw null; } }
public static System.Text.Encoding Unicode { get { throw null; } }
public static System.Text.Encoding UTF32 { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ namespace System.Text.Tests
{
public class Latin1EncodingTests
{
[Fact]
public void Encoding_Latin1_ExpectedObject()
{
Assert.NotNull(Encoding.Latin1);
Assert.Same(Encoding.Latin1, Encoding.Latin1);
Assert.Same(Encoding.GetEncoding("iso-8859-1"), Encoding.Latin1);
}

[Fact]
public void Ctor()
{
Expand All @@ -21,6 +29,7 @@ public void Ctor()

public static IEnumerable<object[]> Encodings_TestData()
{
yield return new object[] { Encoding.Latin1 };
yield return new object[] { Encoding.GetEncoding("latin1") };
yield return new object[] { Encoding.GetEncoding("iso-8859-1") };
}
Expand Down Expand Up @@ -64,6 +73,7 @@ public void Clone(Encoding encoding)

public static IEnumerable<object[]> Equals_TestData()
{
yield return new object[] { Encoding.GetEncoding("latin1"), Encoding.Latin1, true };
yield return new object[] { Encoding.GetEncoding("latin1"), Encoding.GetEncoding("latin1"), true };
yield return new object[] { Encoding.GetEncoding("latin1"), Encoding.GetEncoding("iso-8859-1"), true };

Expand Down

0 comments on commit e8964cc

Please sign in to comment.