diff --git a/apiCount.include.md b/apiCount.include.md index bfd17346..e81b5840 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -1 +1 @@ -**API count: 454** \ No newline at end of file +**API count: 455** \ No newline at end of file diff --git a/api_list.include.md b/api_list.include.md index b5093e02..f475a73d 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -89,6 +89,7 @@ * `int GetByteCount(Encoding, ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytecount#system-text-encoding-getbytecount(system-readonlyspan((system-char)))) * `int GetBytes(Encoding, ReadOnlySpan, Span)` [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)))) + * `int GetCharCount(Encoding, ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getcharcount#system-text-encoding-getcharcount(system-readonlyspan((system-byte)))) * `string GetString(Encoding, ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getstring#system-text-encoding-getstring(system-readonlyspan((system-byte)))) diff --git a/readme.md b/readme.md index df7ea4db..b70a79c3 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ The package targets `netstandard2.0` and is designed to support the following ru * `net5.0`, `net6.0`, `net7.0`, `net8.0`, `net9.0` -**API count: 454** +**API count: 455** **See [Milestones](../../milestones?state=closed) for release notes.** @@ -558,6 +558,7 @@ The class `Polyfill` includes the following extension methods: * `int GetByteCount(Encoding, ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytecount#system-text-encoding-getbytecount(system-readonlyspan((system-char)))) * `int GetBytes(Encoding, ReadOnlySpan, Span)` [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)))) + * `int GetCharCount(Encoding, ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getcharcount#system-text-encoding-getcharcount(system-readonlyspan((system-byte)))) * `string GetString(Encoding, ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getstring#system-text-encoding-getstring(system-readonlyspan((system-byte)))) diff --git a/src/Polyfill/Polyfill_Encoding_GetCharCount.cs b/src/Polyfill/Polyfill_Encoding_GetCharCount.cs new file mode 100644 index 00000000..164580b3 --- /dev/null +++ b/src/Polyfill/Polyfill_Encoding_GetCharCount.cs @@ -0,0 +1,35 @@ +// + +#pragma warning disable + +#if FeatureMemory + +namespace Polyfills; + +using System; +using System.Runtime.InteropServices; +using System.Text; + +static partial class Polyfill +{ +#if NETCOREAPP2_0 || NETFRAMEWORK || NETSTANDARD2_0 + /// + /// Calculates the number of characters produced by decoding the provided read-only byte span. + /// + /// A read-only byte span to decode. + /// The number of characters produced by decoding the byte span. + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getcharcount#system-text-encoding-getcharcount(system-readonlyspan((system-byte))) + public static int GetCharCount(this Encoding target, ReadOnlySpan bytes) + { + if (target is null) + { + throw new ArgumentNullException(nameof(target)); + } + + return target.GetCharCount(bytes.ToArray()); + } +#endif + +} + +#endif \ No newline at end of file