1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 02:45:41 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Oliver Booth
b89e0df36f
Merge 74f957f0c2 into 5ff7b68b37 2023-08-27 03:33:48 +00:00
10 changed files with 20 additions and 392 deletions

View File

@ -44,11 +44,6 @@ jobs:
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Install dotCover
shell: powershell
run: |
dotnet tool install --global JetBrains.dotCover.GlobalTool
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any

View File

@ -26,7 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- X10D: Added `string.ConcatIf`.
- X10D: Added `string.MDBold`, `string.MDCode`, `string.MDCodeBlock([string])`, `string.MDHeading(int)`,
`string.MDItalic`, `string.MDLink`, `string.MDStrikeOut`, and `string.MDUnderline` for Markdown formatting.
- X10D: Added Span overloads which complement `char.Repeat` and `string.Repeat`.
- X10D.Unity: Added `RaycastHit.GetComponent` and `RaycastHit.TryGetComponent`.
- X10D.Unity: Added `DebugUtility.DrawFunction`, and `DebugUtility.DrawUnjoinedPolyhedron` on which it relies.
@ -42,7 +41,6 @@ BigEndian/LittleEndian methods.
- X10D: `Stream.GetHash<>` and `Stream.TryWriteHash<>` now throw ArgumentException in lieu of
TypeInitializationException.
- X10D: `char.IsEmoji` no longer allocates for .NET 7.
- X10D: `string.Repeat` is now more efficient.
### Removed

View File

@ -21,7 +21,7 @@
<PackageIconUrl/>
<PackageTags>dotnet extension-methods</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>See CHANGELOG.md for a full list of changes.</PackageReleaseNotes>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(SolutionDir)/CHANGELOG.md"))</PackageReleaseNotes>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
</PropertyGroup>

View File

@ -60,60 +60,4 @@ internal class CharSpanTests
Assert.That(string.Empty.AsSpan().CountSubstring('\0'), Is.Zero);
Assert.That(string.Empty.AsSpan().CountSubstring(string.Empty.AsSpan(), StringComparison.OrdinalIgnoreCase), Is.Zero);
}
[Test]
public void Repeat_ShouldNotManipulateSpan_GivenCount0()
{
Span<char> destination = new char[11];
"Hello world".AsSpan().CopyTo(destination);
"a".AsSpan().Repeat(0, destination);
Assert.That(destination.ToString(), Is.EqualTo("Hello world"));
}
[Test]
public void Repeat_ShouldReturnItself_GivenCount1()
{
string repeated = "a".AsSpan().Repeat(1);
Assert.That(repeated, Has.Length.EqualTo(1));
Assert.That(repeated, Is.EqualTo("a"));
}
[Test]
public void Repeat_ShouldPopulateSpan_GivenValidSpan()
{
const string expected = "aaaaaaaaaa";
Span<char> destination = new char[10];
"a".AsSpan().Repeat(10, destination);
Assert.That(destination.ToString(), Is.EqualTo(expected));
}
[Test]
public void Repeat_ShouldReturnEmptyString_GivenCount0()
{
Assert.That("a".AsSpan().Repeat(0), Is.EqualTo(string.Empty));
}
[Test]
public void Repeat_ShouldReturnRepeatedString_GivenSpan()
{
const string expected = "aaaaaaaaaa";
string actual = "a".AsSpan().Repeat(10);
Assert.That(actual, Is.EqualTo(expected));
}
[Test]
public void Repeat_ShouldThrowArgumentException_GivenSmallSpan()
{
Assert.Throws<ArgumentException>(() => "a".AsSpan().Repeat(10, Span<char>.Empty));
}
[Test]
public void Repeat_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount()
{
Assert.Throws<ArgumentOutOfRangeException>(() => _ = "a".AsSpan().Repeat(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => "a".AsSpan().Repeat(-1, Span<char>.Empty));
}
}

View File

@ -28,25 +28,6 @@ internal class CharTests
}
}
[Test]
public void Repeat_ShouldPopulateSpanWithRepeatedCharacter_GivenValidCount()
{
const string expected = "aaaaaaaaaa";
Span<char> destination = new char[10];
'a'.Repeat(10, destination);
Assert.That(destination.ToString(), Is.EqualTo(expected));
}
[Test]
public void Repeat_ShouldOnlyWriteOneCharToSpan_GivenCount1()
{
Span<char> destination = new char[10];
'a'.Repeat(1, destination);
Assert.That(destination.ToString(), Is.EqualTo("a\0\0\0\0\0\0\0\0\0"));
}
[Test]
public void Repeat_ShouldReturnRepeatedCharacter_GivenValidCount()
{
@ -70,34 +51,9 @@ internal class CharTests
Assert.That('a'.Repeat(0), Is.EqualTo(string.Empty));
}
[Test]
public void Repeat_ShouldNotManipulateSpan_GivenCount0()
{
Span<char> destination = new char[10];
destination.Fill(' ');
'a'.Repeat(0, destination);
const string expected = " ";
Assert.That(destination.ToString(), Is.EqualTo(expected));
}
[Test]
public void Repeat_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount()
{
Assert.Multiple(() =>
{
Assert.Throws<ArgumentOutOfRangeException>(() => _ = 'a'.Repeat(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => 'a'.Repeat(-1, Span<char>.Empty));
});
}
[Test]
public void Repeat_ShouldThrowArgumentException_GivenSmallSpan()
{
Assert.Throws<ArgumentException>(() =>
{
var destination = Span<char>.Empty;
'a'.Repeat(1, destination);
});
Assert.Throws<ArgumentOutOfRangeException>(() => _ = 'a'.Repeat(-1));
}
}

View File

@ -105,46 +105,6 @@ internal class MarkdownTests
Assert.That("Hello, world!".MDItalic(true), Is.EqualTo("_Hello, world!_"));
}
[Test]
public void MDLink_ShouldThrowArgumentNullException_GivenNullUrl()
{
Assert.Multiple(() =>
{
Assert.Throws<ArgumentNullException>(() => "".MDLink((string)null!));
Assert.Throws<ArgumentNullException>(() => "".MDLink((Uri)null!));
Assert.Throws<ArgumentNullException>(() => ((Uri)null!).MDLink("Hello, world!"));
});
}
[Test]
public void MDLink_ShouldReturnUrlOnly_GivenNullOrEmptyLabel()
{
const string url = "https://example.com/";
Assert.Multiple(() =>
{
Assert.That(((string)null!).MDLink(url), Is.EqualTo(url));
Assert.That(string.Empty.MDLink(url), Is.EqualTo(url));
Assert.That(new Uri(url).MDLink(null), Is.EqualTo(url));
Assert.That(new Uri(url).MDLink(string.Empty), Is.EqualTo(url));
});
}
[Test]
public void MDLink_ShouldReturnFormattedLink_GivenValidLabelAndUrl()
{
const string url = "https://example.com/";
const string label = "Hello, world!";
Assert.Multiple(() =>
{
Assert.That(label.MDLink(url), Is.EqualTo($"[{label}]({url})"));
Assert.That(label.MDLink(new Uri(url)), Is.EqualTo($"[{label}]({url})"));
Assert.That(new Uri(url).MDLink(label), Is.EqualTo($"[{label}]({url})"));
});
}
[Test]
public void MDStrikeOut_ShouldThrowArgumentNullException_GivenNull()
{

View File

@ -164,9 +164,7 @@ internal class StringTests
Assert.Multiple(() =>
{
Assert.That("Hello World".CountSubstring('E'), Is.Zero);
#pragma warning disable CA1307
Assert.That("Hello World".CountSubstring("E"), Is.Zero);
#pragma warning restore CA1307
Assert.That("Hello World".CountSubstring("E", StringComparison.OrdinalIgnoreCase), Is.EqualTo(1));
});
}
@ -177,9 +175,7 @@ internal class StringTests
Assert.Multiple(() =>
{
Assert.That("Hello World".CountSubstring('z'), Is.Zero);
#pragma warning disable CA1307
Assert.That("Hello World".CountSubstring("z"), Is.Zero);
#pragma warning restore CA1307
Assert.That("Hello World".CountSubstring("z", StringComparison.OrdinalIgnoreCase), Is.Zero);
});
}
@ -190,9 +186,7 @@ internal class StringTests
Assert.Multiple(() =>
{
Assert.That("Hello World".CountSubstring('e'), Is.EqualTo(1));
#pragma warning disable CA1307
Assert.That("Hello World".CountSubstring("e"), Is.EqualTo(1));
#pragma warning restore CA1307
Assert.That("Hello World".CountSubstring("e", StringComparison.OrdinalIgnoreCase), Is.EqualTo(1));
});
}
@ -203,9 +197,7 @@ internal class StringTests
Assert.Multiple(() =>
{
Assert.That(string.Empty.CountSubstring('\0'), Is.Zero);
#pragma warning disable CA1307
Assert.That(string.Empty.CountSubstring(string.Empty), Is.Zero);
#pragma warning restore CA1307
Assert.That(string.Empty.CountSubstring(string.Empty, StringComparison.OrdinalIgnoreCase), Is.Zero);
});
}
@ -215,9 +207,7 @@ internal class StringTests
{
string value = null!;
Assert.Throws<ArgumentNullException>(() => value.CountSubstring('\0'));
#pragma warning disable CA1307
Assert.Throws<ArgumentNullException>(() => value.CountSubstring(string.Empty));
#pragma warning restore CA1307
Assert.Throws<ArgumentNullException>(() => value.CountSubstring(string.Empty, StringComparison.OrdinalIgnoreCase));
}
@ -227,10 +217,7 @@ internal class StringTests
const string value = "Hello Worl";
const char substring = 'd';
#pragma warning disable CA1307
Assert.That(value.EnsureEndsWith(substring), Is.EqualTo("Hello World"));
#pragma warning restore CA1307
Assert.That(value.EnsureEndsWith(substring, StringComparison.Ordinal), Is.EqualTo("Hello World"));
}
[Test]
@ -239,10 +226,7 @@ internal class StringTests
const string value = "A";
const char substring = 'A';
#pragma warning disable CA1307
Assert.That(value.EnsureEndsWith(substring), Is.EqualTo(value));
#pragma warning restore CA1307
Assert.That(value.EnsureEndsWith(substring, StringComparison.Ordinal), Is.EqualTo(value));
}
[Test]
@ -251,10 +235,7 @@ internal class StringTests
const string value = "B";
const char substring = 'A';
#pragma warning disable CA1307
Assert.That(value.EnsureStartsWith(substring), Is.EqualTo("AB"));
#pragma warning restore CA1307
Assert.That(value.EnsureStartsWith(substring, StringComparison.Ordinal), Is.EqualTo("AB"));
}
[Test]
@ -263,10 +244,7 @@ internal class StringTests
const string value = "A";
const char substring = 'A';
#pragma warning disable CA1307
Assert.That(value.EnsureStartsWith(substring), Is.EqualTo(value));
#pragma warning restore CA1307
Assert.That(value.EnsureStartsWith(substring, StringComparison.Ordinal), Is.EqualTo(value));
}
[Test]
@ -275,10 +253,7 @@ internal class StringTests
const string value = "Hello ";
const string substring = "World";
#pragma warning disable CA1307
Assert.That(value.EnsureEndsWith(substring), Is.EqualTo("Hello World"));
#pragma warning restore CA1307
Assert.That(value.EnsureEndsWith(substring, StringComparison.Ordinal), Is.EqualTo("Hello World"));
}
[Test]
@ -286,10 +261,7 @@ internal class StringTests
{
const string substring = "World";
#pragma warning disable CA1307
Assert.That(substring.EnsureEndsWith(substring), Is.EqualTo(substring));
#pragma warning restore CA1307
Assert.That(substring.EnsureEndsWith(substring, StringComparison.Ordinal), Is.EqualTo(substring));
}
[Test]
@ -297,10 +269,7 @@ internal class StringTests
{
const string substring = "World";
#pragma warning disable CA1307
Assert.That(string.Empty.EnsureEndsWith(substring), Is.EqualTo(substring));
#pragma warning restore CA1307
Assert.That(string.Empty.EnsureEndsWith(substring, StringComparison.Ordinal), Is.EqualTo(substring));
}
[Test]
@ -308,10 +277,7 @@ internal class StringTests
{
const string substring = "World";
#pragma warning disable CA1307
Assert.That(substring.EnsureEndsWith(string.Empty), Is.EqualTo(substring));
#pragma warning restore CA1307
Assert.That(substring.EnsureEndsWith(string.Empty, StringComparison.Ordinal), Is.EqualTo(substring));
}
[Test]
@ -320,10 +286,7 @@ internal class StringTests
const string value = "World";
const string substring = "Hello ";
#pragma warning disable CA1307
Assert.That(value.EnsureStartsWith(substring), Is.EqualTo("Hello World"));
#pragma warning restore CA1307
Assert.That(value.EnsureStartsWith(substring, StringComparison.Ordinal), Is.EqualTo("Hello World"));
}
[Test]
@ -331,10 +294,7 @@ internal class StringTests
{
const string substring = "World";
#pragma warning disable CA1307
Assert.That(substring.EnsureStartsWith(substring), Is.EqualTo(substring));
#pragma warning restore CA1307
Assert.That(substring.EnsureStartsWith(substring, StringComparison.Ordinal), Is.EqualTo(substring));
}
[Test]
@ -342,10 +302,7 @@ internal class StringTests
{
const string substring = "World";
#pragma warning disable CA1307
Assert.That(string.Empty.EnsureStartsWith(substring), Is.EqualTo(substring));
#pragma warning restore CA1307
Assert.That(string.Empty.EnsureStartsWith(substring, StringComparison.Ordinal), Is.EqualTo(substring));
}
[Test]
@ -353,10 +310,7 @@ internal class StringTests
{
const string substring = "World";
#pragma warning disable CA1307
Assert.That(substring.EnsureStartsWith(string.Empty), Is.EqualTo(substring));
#pragma warning restore CA1307
Assert.That(substring.EnsureStartsWith(string.Empty, StringComparison.Ordinal), Is.EqualTo(substring));
}
[Test]
@ -439,7 +393,7 @@ internal class StringTests
[Test]
public void GetBytes_ShouldReturnUtf8Bytes_GivenHelloWorld()
{
var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
var expected = new byte[] {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64};
byte[] actual = "Hello World".GetBytes();
CollectionAssert.AreEqual(expected, actual);
@ -448,7 +402,7 @@ internal class StringTests
[Test]
public void GetBytes_ShouldReturnAsciiBytes_GivenHelloWorld()
{
var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
var expected = new byte[] {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64};
byte[] actual = "Hello World".GetBytes(Encoding.ASCII);
CollectionAssert.AreEqual(expected, actual);
@ -490,16 +444,14 @@ internal class StringTests
public void IsEmoji_ShouldReturnTrue_GivenMultiByteEmoji()
{
string[] regionalIndicatorCodes = Enumerable.Range(0, 26)
.Select(i => Encoding.Unicode.GetString(new byte[] { 0x3C, 0xD8, (byte)(0xE6 + i), 0xDD }))
.Select(i => Encoding.Unicode.GetString(new byte[] {0x3C, 0xD8, (byte)(0xE6 + i), 0xDD}))
.ToArray();
for (var i = 0; i < 26; i++)
for (var j = 0; j < 26; j++)
{
for (var j = 0; j < 26; j++)
{
string flag = (regionalIndicatorCodes[i] + regionalIndicatorCodes[j]);
Assert.That(flag.IsEmoji());
}
string flag = (regionalIndicatorCodes[i] + regionalIndicatorCodes[j]);
Assert.That(flag.IsEmoji());
}
}
@ -744,7 +696,7 @@ internal class StringTests
[Test]
public void Randomize_ShouldThrow_GivenNegativeLength()
{
Assert.Throws<ArgumentOutOfRangeException>(() => _ = string.Empty.Randomize(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => string.Empty.Randomize(-1));
}
[Test]
@ -762,62 +714,25 @@ internal class StringTests
Assert.That("a".Repeat(0), Is.EqualTo(string.Empty));
}
[Test]
public void Repeat_ShouldNotManipulateSpan_GivenCount0()
{
Span<char> destination = new char[11];
"Hello world".AsSpan().CopyTo(destination);
"a".Repeat(0, destination);
Assert.That(destination.ToString(), Is.EqualTo("Hello world"));
}
[Test]
public void Repeat_ShouldReturnItself_GivenCount1()
{
string repeated = "a".Repeat(1);
Assert.That(repeated, Has.Length.EqualTo(1));
Assert.That(repeated.Length, Is.EqualTo(1));
Assert.That(repeated, Is.EqualTo("a"));
}
[Test]
public void Repeat_ShouldThrowArgumentException_GivenSmallSpan()
{
Assert.Throws<ArgumentException>(() => "a".Repeat(10, Span<char>.Empty));
}
[Test]
public void Repeat_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount()
public void Repeat_ShouldThrow_GivenNegativeCount()
{
Assert.Throws<ArgumentOutOfRangeException>(() => _ = "a".Repeat(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => "a".Repeat(-1, Span<char>.Empty));
}
[Test]
public void Repeat_ShouldThrowArgumentNullException_GivenNull()
public void Repeat_ShouldThrow_GivenNull()
{
string value = null!;
Assert.Throws<ArgumentNullException>(() => _ = value.Repeat(0));
Assert.Throws<ArgumentNullException>(() => value.Repeat(0, Span<char>.Empty));
}
[Test]
public void Repeat_ShouldPopulateSpanWithRepeatedCharacter_GivenValidCount()
{
const string expected = "aaaaaaaaaa";
Span<char> destination = new char[10];
"a".Repeat(10, destination);
Assert.That(destination.ToString(), Is.EqualTo(expected));
}
[Test]
public void Repeat_ShouldOnlyWriteOneCharToSpan_GivenCount1()
{
Span<char> destination = new char[10];
"a".Repeat(1, destination);
Assert.That(destination.ToString(), Is.EqualTo("a\0\0\0\0\0\0\0\0\0"));
}
[Test]
@ -836,7 +751,7 @@ internal class StringTests
}
[Test]
public void Reverse_ShouldThrowArgumentNullException_GivenNull()
public void Reverse_ShouldThrow_GivenNull()
{
string value = null!;
Assert.Throws<ArgumentNullException>(() => _ = value.Reverse());
@ -854,7 +769,7 @@ internal class StringTests
}
[Test]
public void Shuffled_ShouldThrowArgumentNullException_GivenNull()
public void Shuffled_ShouldThrow_GivenNull()
{
string value = null!;
Assert.Throws<ArgumentNullException>(() => _ = value.Shuffled());
@ -888,7 +803,7 @@ internal class StringTests
}
[Test]
public void Split_ShouldThrowArgumentNullException_GivenNullString()
public void Split_ShouldThrow_GivenNullString()
{
string value = null!;
@ -963,7 +878,7 @@ internal class StringTests
[Test]
public void StartsWithAny_ShouldThrowArgumentNullException_GivenANullValue()
{
var values = new[] { "Hello", null!, "World" };
var values = new[] {"Hello", null!, "World"};
Assert.Throws<ArgumentNullException>(() => "Foobar".StartsWithAny(values));
Assert.Throws<ArgumentNullException>(() => "Foobar".StartsWithAny(StringComparison.Ordinal, values));
}

View File

@ -47,34 +47,4 @@ public static class CharExtensions
_ => new string(value, count)
};
}
/// <summary>
/// Writes a character to a span of characters, repeated a specified number of times.
/// </summary>
/// <param name="value">The character to repeat.</param>
/// <param name="count">The number of times to repeat.</param>
/// <param name="destination">The span of characters into which the repeated characters will be written.</param>
[MethodImpl(CompilerResources.MethodImplOptions)]
public static void Repeat(this char value, int count, Span<char> destination)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), ExceptionMessages.CountMustBeGreaterThanOrEqualTo0);
}
if (count == 0)
{
return;
}
if (destination.Length < count)
{
throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination));
}
for (var i = 0; i < count; i++)
{
destination[i] = value;
}
}
}

View File

@ -1,8 +1,3 @@
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Text;
using X10D.CompilerServices;
namespace X10D.Text;
/// <summary>
@ -72,73 +67,4 @@ public static class CharSpanExtensions
return count;
}
/// <summary>
/// Repeats a span of characters a specified number of times.
/// </summary>
/// <param name="value">The string to repeat.</param>
/// <param name="count">The repeat count.</param>
/// <returns>A string containing <paramref name="value" /> repeated <paramref name="count" /> times.</returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count" /> is less than 0.</exception>
[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
public static string Repeat(this ReadOnlySpan<char> value, int count)
{
switch (count)
{
case < 0:
throw new ArgumentOutOfRangeException(nameof(count), ExceptionMessages.CountMustBeGreaterThanOrEqualTo0);
case 0:
return string.Empty;
case 1:
return value.ToString();
}
var builder = new StringBuilder(value.Length * count);
for (var i = 0; i < count; i++)
{
builder.Append(value);
}
return builder.ToString();
}
/// <summary>
/// Repeats a span of character a specified number of times, writing the result to another span of characters.
/// </summary>
/// <param name="value">The span of characters to repeat.</param>
/// <param name="count">The repeat count.</param>
/// <param name="destination">The destination span to write to.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count" /> is less than 0.</exception>
/// <exception cref="ArgumentException">
/// <paramref name="destination" /> is too short to contain the repeated string.
/// </exception>
[MethodImpl(CompilerResources.MethodImplOptions)]
public static void Repeat(this ReadOnlySpan<char> value, int count, Span<char> destination)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), ExceptionMessages.CountMustBeGreaterThanOrEqualTo0);
}
if (count == 0)
{
return;
}
if (destination.Length < value.Length * count)
{
throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination));
}
for (var iteration = 0; iteration < count; iteration++)
{
Span<char> slice = destination.Slice(iteration * value.Length, value.Length);
value.CopyTo(slice);
}
}
}

View File

@ -932,50 +932,14 @@ public static class StringExtensions
return value;
}
Span<char> destination = stackalloc char[value.Length * count];
value.Repeat(count, destination);
return new string(destination);
}
var builder = new StringBuilder(value.Length * count);
/// <summary>
/// Repeats a string a specified number of times, writing the result to a span of characters.
/// </summary>
/// <param name="value">The string to repeat.</param>
/// <param name="count">The repeat count.</param>
/// <param name="destination">The destination span to write to.</param>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count" /> is less than 0.</exception>
/// <exception cref="ArgumentException">
/// <paramref name="destination" /> is too short to contain the repeated string.
/// </exception>
[MethodImpl(CompilerResources.MethodImplOptions)]
public static void Repeat(this string value, int count, Span<char> destination)
{
if (value is null)
for (var i = 0; i < count; i++)
{
throw new ArgumentNullException(nameof(value));
builder.Append(value);
}
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), ExceptionMessages.CountMustBeGreaterThanOrEqualTo0);
}
if (count == 0)
{
return;
}
if (destination.Length < value.Length * count)
{
throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination));
}
for (var iteration = 0; iteration < count; iteration++)
{
Span<char> slice = destination.Slice(iteration * value.Length, value.Length);
value.AsSpan().CopyTo(slice);
}
return builder.ToString();
}
/// <summary>