Skip to content

Commit

Permalink
Merge pull request #29172 from kadambishreyas/handle-timestamp-mod-co…
Browse files Browse the repository at this point in the history
…ntent

Handle timestamp mod content
  • Loading branch information
bdach authored Jul 29, 2024
2 parents 12e553a + ae61df0 commit 3a30ff7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions osu.Game.Tests/Editing/EditorTimestampParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class EditorTimestampParserTest
new object?[] { "1:02:3000", false, null, null },
new object?[] { "1:02:300 ()", false, null, null },
new object?[] { "1:02:300 (1,2,3)", true, new TimeSpan(0, 0, 1, 2, 300), "1,2,3" },
new object?[] { "1:02:300 (1,2,3) - ", true, new TimeSpan(0, 0, 1, 2, 300), "1,2,3" },
new object?[] { "1:02:300 (1,2,3) - following mod", true, new TimeSpan(0, 0, 1, 2, 300), "1,2,3" },
new object?[] { "1:02:300 (1,2,3) - following mod\nwith newlines", true, new TimeSpan(0, 0, 1, 2, 300), "1,2,3" },
};

[TestCaseSource(nameof(test_cases))]
Expand Down
8 changes: 6 additions & 2 deletions osu.Game/Rulesets/Edit/EditorTimestampParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public static class EditorTimestampParser
{
/// <summary>
/// Used for parsing in contexts where we don't want e.g. normal times of day to be parsed as timestamps (e.g. chat)
/// Original osu-web regex: https://github.com/ppy/osu-web/blob/3b1698639244cfdaf0b41c68bfd651ea729ec2e3/resources/js/utils/beatmapset-discussion-helper.ts#L78
/// Original osu-web regex:
/// https://github.com/ppy/osu-web/blob/3b1698639244cfdaf0b41c68bfd651ea729ec2e3/resources/js/utils/beatmapset-discussion-helper.ts#L78
/// </summary>
/// <example>
/// 00:00:000 (...) - test
Expand All @@ -32,7 +33,10 @@ public static class EditorTimestampParser
/// <item>1:02:300 (1,2,3) - parses to 01:02:300 with selection</item>
/// </list>
/// </example>
private static readonly Regex time_regex_lenient = new Regex(@"^(((?<minutes>\d{1,3}):(?<seconds>([0-5]?\d))([:.](?<milliseconds>\d{0,3}))?)(?<selection>\s\([^)]+\))?)$", RegexOptions.Compiled);
private static readonly Regex time_regex_lenient = new Regex(
@"^(((?<minutes>\d{1,3}):(?<seconds>([0-5]?\d))([:.](?<milliseconds>\d{0,3}))?)(?<selection>\s\([^)]+\))?)(?<suffix>\s-.*)?$",
RegexOptions.Compiled | RegexOptions.Singleline
);

public static bool TryParse(string timestamp, [NotNullWhen(true)] out TimeSpan? parsedTime, out string? parsedSelection)
{
Expand Down

0 comments on commit 3a30ff7

Please sign in to comment.