From a51d51fa2183b725ac25c7c86c42b3686f3be75f Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 10 Dec 2023 22:27:27 +0800 Subject: [PATCH] Create the TestCaseTextIndexHelper for able to deal with time-index format. --- .../Helper/TestCaseTextIndexHelper.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 osu.Framework.Font.Tests/Helper/TestCaseTextIndexHelper.cs diff --git a/osu.Framework.Font.Tests/Helper/TestCaseTextIndexHelper.cs b/osu.Framework.Font.Tests/Helper/TestCaseTextIndexHelper.cs new file mode 100644 index 0000000..c3f6107 --- /dev/null +++ b/osu.Framework.Font.Tests/Helper/TestCaseTextIndexHelper.cs @@ -0,0 +1,23 @@ +// Copyright (c) karaoke.dev . 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("(?[-0-9]+),(?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); + } +}