-
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.
Create the TestCaseTextIndexHelper for able to deal with time-index f…
…ormat.
- Loading branch information
1 parent
98a6bb8
commit a51d51f
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
osu.Framework.Font.Tests/Helper/TestCaseTextIndexHelper.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 @@ | ||
// 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 osu.Framework.Graphics.Sprites; | ||
|
||
namespace osu.Framework.Font.Tests.Helper; | ||
|
||
public 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 = int.Parse(result.Groups["index"].Value); | ||
var state = result.Groups["state"].Value == "start" ? TextIndex.IndexState.Start : TextIndex.IndexState.End; | ||
|
||
return new TextIndex(index, state); | ||
} | ||
} |