Skip to content

Commit 7964459

Browse files
committed
split GetByteCount
1 parent 3b4617d commit 7964459

File tree

2 files changed

+54
-37
lines changed

2 files changed

+54
-37
lines changed

src/Polyfill/Polyfill_Encoding.cs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,17 @@
11
// <auto-generated />
22

3-
using System.Runtime.InteropServices;
4-
using System.Text;
5-
63
#pragma warning disable
74

85
#if FeatureMemory
96

107
namespace Polyfills;
118

129
using System;
10+
using System.Runtime.InteropServices;
11+
using System.Text;
1312

1413
static partial class Polyfill
1514
{
16-
#if NETCOREAPP2_0 || NETFRAMEWORK || NETSTANDARD2_0
17-
/// <summary>
18-
/// When overridden in a derived class, calculates the number of bytes produced by encoding the characters in the specified character span.
19-
/// </summary>
20-
/// <param name="encoding"></param>
21-
/// <param name="chars">The span of characters to encode.</param>
22-
/// <returns>The number of bytes produced by encoding the specified character span.</returns>
23-
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytecount#system-text-encoding-getbytecount(system-readonlyspan((system-char)))
24-
#if AllowUnsafeBlocks
25-
public unsafe static int GetByteCount(this Encoding target, ReadOnlySpan<char> chars)
26-
{
27-
if (target is null)
28-
{
29-
throw new ArgumentNullException(nameof(target));
30-
}
31-
32-
fixed (char* charsPtr = chars)
33-
{
34-
return target.GetByteCount(charsPtr, chars.Length);
35-
}
36-
}
37-
#else
38-
public static int GetByteCount(this Encoding target, ReadOnlySpan<char> chars)
39-
{
40-
if (target is null)
41-
{
42-
throw new ArgumentNullException(nameof(target));
43-
}
44-
45-
return target.GetByteCount(chars.ToArray());
46-
}
47-
#endif
48-
#endif
49-
5015
#if !NETCOREAPP2_1_OR_GREATER
5116
/// <summary>When overridden in a derived class, encodes into a span of bytes a set of characters from the specified read-only span.</summary>
5217
/// <param name="chars">The span containing the set of characters to encode.</param>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// <auto-generated />
2+
3+
#pragma warning disable
4+
5+
#if FeatureMemory
6+
7+
namespace Polyfills;
8+
9+
using System;
10+
11+
using System.Runtime.InteropServices;
12+
using System.Text;
13+
14+
static partial class Polyfill
15+
{
16+
#if NETCOREAPP2_0 || NETFRAMEWORK || NETSTANDARD2_0
17+
/// <summary>
18+
/// When overridden in a derived class, calculates the number of bytes produced by encoding the characters in the specified character span.
19+
/// </summary>
20+
/// <param name="encoding"></param>
21+
/// <param name="chars">The span of characters to encode.</param>
22+
/// <returns>The number of bytes produced by encoding the specified character span.</returns>
23+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytecount#system-text-encoding-getbytecount(system-readonlyspan((system-char)))
24+
#if AllowUnsafeBlocks
25+
public unsafe static int GetByteCount(this Encoding target, ReadOnlySpan<char> chars)
26+
{
27+
if (target is null)
28+
{
29+
throw new ArgumentNullException(nameof(target));
30+
}
31+
32+
fixed (char* charsPtr = chars)
33+
{
34+
return target.GetByteCount(charsPtr, chars.Length);
35+
}
36+
}
37+
#else
38+
public static int GetByteCount(this Encoding target, ReadOnlySpan<char> chars)
39+
{
40+
if (target is null)
41+
{
42+
throw new ArgumentNullException(nameof(target));
43+
}
44+
45+
return target.GetByteCount(chars.ToArray());
46+
}
47+
#endif
48+
#endif
49+
50+
}
51+
52+
#endif

0 commit comments

Comments
 (0)