Skip to content

Commit

Permalink
Create the TestCaseTextIndexHelper for able to deal with time-index f…
Browse files Browse the repository at this point in the history
…ormat.
  • Loading branch information
andy840119 committed Dec 10, 2023
1 parent 98a6bb8 commit a51d51f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions osu.Framework.Font.Tests/Helper/TestCaseTextIndexHelper.cs
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);
}
}

0 comments on commit a51d51f

Please sign in to comment.