forked from lay295/TwitchDownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove extra ToString() when stringifying M3U8 metadata
- Loading branch information
Showing
3 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
TwitchDownloaderCore.Tests/ExtensionTests/StringBuilderExtensionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Text; | ||
using TwitchDownloaderCore.Extensions; | ||
|
||
namespace TwitchDownloaderCore.Tests.ExtensionTests | ||
{ | ||
public class StringBuilderExtensionTests | ||
{ | ||
[Theory] | ||
[InlineData("Foo", "o", "F")] | ||
[InlineData("Foo\r\n", "\r\n", "Foo")] | ||
[InlineData("oo", "o", "")] | ||
[InlineData("Foo", "L", "Foo")] | ||
[InlineData("Foo", "oL", "F")] | ||
public void CorrectlyTrimsCharacters(string baseString, string trimChars, string expectedResult) | ||
{ | ||
var sb = new StringBuilder(baseString); | ||
|
||
sb.TrimEnd(trimChars); | ||
|
||
Assert.Equal(expectedResult, sb.ToString()); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
TwitchDownloaderCore/Extensions/StringBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace TwitchDownloaderCore.Extensions | ||
{ | ||
public static class StringBuilderExtensions | ||
{ | ||
public static StringBuilder TrimEnd(this StringBuilder sb, ReadOnlySpan<char> trimChars) | ||
{ | ||
var trimLength = 0; | ||
while (sb.Length - trimLength > 0 && trimChars.Contains(sb[^(trimLength + 1)])) | ||
{ | ||
trimLength++; | ||
} | ||
|
||
return sb.Remove(sb.Length - trimLength, trimLength); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters