-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7a4b76
commit f023c3d
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
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,24 @@ | ||
// Copyright (c) karaoke.dev <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Text.RegularExpressions; | ||
using LrcParser.Extension; | ||
using LrcParser.Model; | ||
|
||
namespace LrcParser.Tests.Helper; | ||
|
||
public static class TestCaseTextIndexHelper | ||
{ | ||
public static TextIndex ParseTextIndex(string str) | ||
{ | ||
var regex = new Regex("(?<index>[-0-9]+),(?<state>start|end)"); | ||
var result = regex.Match(str); | ||
if (!result.Success) | ||
throw new RegexMatchTimeoutException(nameof(str)); | ||
|
||
int index = result.GetGroupValue<int>("index"); | ||
var state = result.GetGroupValue<string>("state") == "start" ? IndexState.Start : IndexState.End; | ||
|
||
return new TextIndex(index, state); | ||
} | ||
} |