Skip to content

Commit

Permalink
Add more cases for handle the ruby text in the time-tag tag helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jul 22, 2023
1 parent 6a9a5d8 commit e5e8e60
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ public static RomajiTag ParseRomajiTag(string? str)
/// [0,start]:1000 -> has time-tag index with time. <br/>
/// [0,start] -> has time-tag index with no time. <br/>
/// [0,start]: -> has time-tag index with no time. <br/>
/// [0,start]#karaoke -> has time-tag index with romaji. <br/>
/// [0,start]#^karaoke -> has time-tag index with romaji, and it's initial romaji. <br/>
/// [0,start]:1000#karaoke -> has time-tag index with time and romaji. <br/>
/// </example>
/// <param name="str">Time tag string format</param>
/// <returns><see cref="TimeTag"/>Time tag object</returns>
Expand All @@ -137,6 +140,7 @@ public static TimeTag ParseTimeTag(string? str)
string regex = generateRegex(time_index_regex, new[]
{
getNumberPropertyRegex(':', "time"),
getStringPropertyRegex('#', "text"),
});

return getMatchByStatement<TimeTag>(str, regex, result =>
Expand All @@ -147,8 +151,14 @@ public static TimeTag ParseTimeTag(string? str)
int index = result.GetGroupValue<int>("index");
var state = result.GetGroupValue<string>("state") == "start" ? TextIndex.IndexState.Start : TextIndex.IndexState.End;
int? time = result.GetGroupValue<int?>("time");
string? text = result.GetGroupValue<string?>("text");
bool? initialRomaji = text?.StartsWith("^");

return new TimeTag(new TextIndex(index, state), time);
return new TimeTag(new TextIndex(index, state), time)
{
RomajiText = text?.Replace("^", ""),
InitialRomaji = initialRomaji ?? default,
};
});
}

Expand Down

0 comments on commit e5e8e60

Please sign in to comment.