Skip to content

Add polyfills for char.IsBetween(...) and char.IsAscii*(...) - #129

Merged
Tyrrrz merged 4 commits into
primefrom
copilot/add-polyfill-char-methods
Jul 10, 2026
Merged

Tyrrrz merged 4 commits into
primefrom
copilot/add-polyfill-char-methods

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Polyfills for the char static methods introduced in .NET 7, making them available on older targets (netstandard, netframework, pre-NET7 netcoreapp).

New polyfills — Net70/Char.cs

Method Notes
char.IsBetween(c, min, max) unsigned subtraction trick
char.IsAscii(c) (uint)c <= 0x7f
char.IsAsciiDigit(c) '0'–'9'
char.IsAsciiLetter(c) upper or lower
char.IsAsciiLetterUpper(c) 'A'–'Z'
char.IsAsciiLetterLower(c) 'a'–'z'
char.IsAsciiLetterOrDigit(c) letter or digit
char.IsAsciiHexDigit(c) upper or lower hex
char.IsAsciiHexDigitUpper(c) 'A'–'F' or digit
char.IsAsciiHexDigitLower(c) 'a'–'f' or digit
// Available on netstandard / netframework / pre-.NET 7
char.IsAscii('A');                        // true
char.IsAsciiDigit('9');                   // true
char.IsAsciiHexDigit('f');                // true
char.IsBetween('m', 'a', 'z');           // true
char.IsAsciiLetterOrDigit('!');          // false

@Tyrrrz Tyrrrz added the enhancement New feature or request label Jul 10, 2026
@Tyrrrz
Tyrrrz marked this pull request as ready for review July 10, 2026 20:37
Copilot AI review requested due to automatic review settings July 10, 2026 20:37
@codecov

codecov Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.15%. Comparing base (3bf818d) to head (41d9ccc).

Additional details and impacted files
@@            Coverage Diff             @@
##            prime     #129      +/-   ##
==========================================
+ Coverage   99.14%   99.15%   +0.01%     
==========================================
  Files         143      145       +2     
  Lines        3727     3798      +71     
  Branches       87       87              
==========================================
+ Hits         3695     3766      +71     
  Misses         13       13              
  Partials       19       19              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds .NET 7 char static API polyfills (ASCII classification helpers and IsBetween) so consumers targeting older TFMs (netstandard, netframework, pre-.NET 7 netcoreapp) can call the newer char.* methods with the same surface area.

Changes:

  • Introduces Net70/Char.cs polyfills for char.IsBetween and the char.IsAscii* family.
  • Adds PolyShim.Tests/Net70/CharTests.cs to validate the new polyfilled APIs across the test TFMs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
PolyShim/Net70/Char.cs Adds .NET 7 char polyfill members (IsBetween / IsAscii / IsAscii*) behind appropriate TFM guards.
PolyShim.Tests/Net70/CharTests.cs Adds unit tests covering the new char polyfills’ expected true/false cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Tyrrrz

Tyrrrz commented Jul 10, 2026

Copy link
Copy Markdown
Owner

@copilot some methods were introduced in .NET 6

Copilot AI commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@copilot some methods were introduced in .NET 6

Moved char.IsAscii to a new Net60/Char.cs (guarded by !NET6_0_OR_GREATER) since it was introduced in .NET 6. The remaining methods (IsBetween, IsAsciiDigit, IsAsciiLetter*, IsAsciiHexDigit*) stay in Net70/Char.cs as they were all introduced in .NET 7. The test was moved to Net60/CharTests.cs accordingly. (commit $(git rev-parse --short HEAD 2>/dev/null || echo "latest"))

@copilot some methods were introduced in .NET 6

Moved char.IsAscii to a new Net60/Char.cs (guarded by !NET6_0_OR_GREATER) since it was introduced in .NET 6. The remaining methods (IsBetween, IsAsciiDigit, IsAsciiLetter*, IsAsciiHexDigit*) stay in Net70/Char.cs as they were all introduced in .NET 7. The corresponding test was moved to Net60/CharTests.cs as well.

Copilot AI requested a review from Tyrrrz July 10, 2026 21:25
@Tyrrrz Tyrrrz changed the title Add char polyfills for .NET 7 (IsBetween, IsAscii, IsAscii*) Add polyfills for char.IsBetween(...) and char.IsAscii*(...) Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants