Skip to content

Commit cb84a6f

Browse files
authored
Add Encoding GetCharCount (#283)
* Add Encoding GetCharCount * Update Polyfill_Encoding_GetCharCount.cs
1 parent 271c9e5 commit cb84a6f

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

apiCount.include.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
**API count: 454**
1+
**API count: 455**

api_list.include.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090
* `int GetByteCount(Encoding, ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytecount#system-text-encoding-getbytecount(system-readonlyspan((system-char))))
9191
* `int GetBytes(Encoding, ReadOnlySpan<char>, Span<byte>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytes#system-text-encoding-getbytes(system-readonlyspan((system-char))-system-span((system-byte))))
92+
* `int GetCharCount(Encoding, ReadOnlySpan<byte>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getcharcount#system-text-encoding-getcharcount(system-readonlyspan((system-byte))))
9293
* `string GetString(Encoding, ReadOnlySpan<byte>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getstring#system-text-encoding-getstring(system-readonlyspan((system-byte))))
9394

9495

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
1212
* `net5.0`, `net6.0`, `net7.0`, `net8.0`, `net9.0`
1313

1414

15-
**API count: 454**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
15+
**API count: 455**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
1616

1717

1818
**See [Milestones](../../milestones?state=closed) for release notes.**
@@ -558,6 +558,7 @@ The class `Polyfill` includes the following extension methods:
558558

559559
* `int GetByteCount(Encoding, ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytecount#system-text-encoding-getbytecount(system-readonlyspan((system-char))))
560560
* `int GetBytes(Encoding, ReadOnlySpan<char>, Span<byte>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytes#system-text-encoding-getbytes(system-readonlyspan((system-char))-system-span((system-byte))))
561+
* `int GetCharCount(Encoding, ReadOnlySpan<byte>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getcharcount#system-text-encoding-getcharcount(system-readonlyspan((system-byte))))
561562
* `string GetString(Encoding, ReadOnlySpan<byte>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getstring#system-text-encoding-getstring(system-readonlyspan((system-byte))))
562563

563564

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// <auto-generated />
2+
3+
#pragma warning disable
4+
5+
#if FeatureMemory
6+
7+
namespace Polyfills;
8+
9+
using System;
10+
using System.Runtime.InteropServices;
11+
using System.Text;
12+
13+
static partial class Polyfill
14+
{
15+
#if NETCOREAPP2_0 || NETFRAMEWORK || NETSTANDARD2_0
16+
/// <summary>
17+
/// Calculates the number of characters produced by decoding the provided read-only byte span.
18+
/// </summary>
19+
/// <param name="chars">A read-only byte span to decode.</param>
20+
/// <returns>The number of characters produced by decoding the byte span.</returns>
21+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getcharcount#system-text-encoding-getcharcount(system-readonlyspan((system-byte)))
22+
public static int GetCharCount(this Encoding target, ReadOnlySpan<byte> bytes)
23+
{
24+
if (target is null)
25+
{
26+
throw new ArgumentNullException(nameof(target));
27+
}
28+
29+
return target.GetCharCount(bytes.ToArray());
30+
}
31+
#endif
32+
33+
}
34+
35+
#endif

0 commit comments

Comments
 (0)