Skip to content

Commit

Permalink
Made char.IsAscii public (dotnet#41396)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoidl committed Aug 31, 2020
1 parent 96e64eb commit 4921dbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libraries/System.Private.CoreLib/src/System/Char.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ namespace System
};

// Return true for all characters below or equal U+00ff, which is ASCII + Latin-1 Supplement.
private static bool IsLatin1(char ch) => (uint)ch < (uint)Latin1CharInfo.Length;
private static bool IsLatin1(char c) => (uint)c < (uint)Latin1CharInfo.Length;

// Return true for all characters below or equal U+007f, which is ASCII.
private static bool IsAscii(char ch) => (uint)ch <= '\x007f';
public static bool IsAscii(char c) => (uint)c <= '\x007f';

// Return the Unicode category for Unicode character <= 0x00ff.
private static UnicodeCategory GetLatin1UnicodeCategory(char ch)
private static UnicodeCategory GetLatin1UnicodeCategory(char c)
{
Debug.Assert(IsLatin1(ch), "char.GetLatin1UnicodeCategory(): ch should be <= 00ff");
return (UnicodeCategory)(Latin1CharInfo[ch] & UnicodeCategoryMask);
Debug.Assert(IsLatin1(c), "char.GetLatin1UnicodeCategory(): c should be <= 00ff");
return (UnicodeCategory)(Latin1CharInfo[c] & UnicodeCategoryMask);
}

//
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 @@ -728,6 +728,7 @@ public CannotUnloadAppDomainException(string? message, System.Exception? innerEx
private readonly char _dummyPrimitive;
public const char MaxValue = '\uFFFF';
public const char MinValue = '\0';
public static bool IsAscii(System.Char c) { throw null; }
public int CompareTo(System.Char value) { throw null; }
public int CompareTo(object? value) { throw null; }
public static string ConvertFromUtf32(int utf32) { throw null; }
Expand Down
9 changes: 9 additions & 0 deletions src/libraries/System.Runtime/tests/System/CharTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ public void GetTypeCode_Invoke_ReturnsBoolean()
Assert.Equal(TypeCode.Char, 'a'.GetTypeCode());
}

[Fact]
public static void IsAscii_Char()
{
Assert.True(char.IsAscii(char.MinValue));
Assert.True(char.IsAscii('\x007f'));
Assert.False(char.IsAscii('\x0080'));
Assert.False(char.IsAscii(char.MaxValue));
}

[Fact]
public static void IsControl_Char()
{
Expand Down

0 comments on commit 4921dbb

Please sign in to comment.