Skip to content

Commit

Permalink
Use one less regex
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Jul 3, 2024
1 parent 5696e85 commit bcb479d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions osu.Game/Rulesets/Edit/Checks/CheckTitleMarkers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using osu.Game.Rulesets.Edit.Checks.Components;
Expand Down Expand Up @@ -37,24 +38,22 @@ public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
bool hasRomanisedTitle = unicodeTitle != romanisedTitle;

if (check.AnyRegex.IsMatch(unicodeTitle) && !check.ExactRegex.IsMatch(unicodeTitle))
if (check.AnyRegex.IsMatch(unicodeTitle) && !unicodeTitle.Contains(check.CorrectMarkerFormat, StringComparison.Ordinal))
yield return new IssueTemplateIncorrectMarker(this).Create("Title", check.CorrectMarkerFormat);

if (hasRomanisedTitle && check.AnyRegex.IsMatch(romanisedTitle) && !check.ExactRegex.IsMatch(romanisedTitle))
if (hasRomanisedTitle && check.AnyRegex.IsMatch(romanisedTitle) && !romanisedTitle.Contains(check.CorrectMarkerFormat, StringComparison.Ordinal))
yield return new IssueTemplateIncorrectMarker(this).Create("Romanised title", check.CorrectMarkerFormat);
}
}

private class MarkerCheck
{
public readonly string CorrectMarkerFormat;
public readonly Regex ExactRegex;
public readonly Regex AnyRegex;

public MarkerCheck(string exact, string anyRegex)
{
CorrectMarkerFormat = exact;
ExactRegex = new Regex(Regex.Escape(exact), RegexOptions.Compiled);
AnyRegex = new Regex(anyRegex, RegexOptions.Compiled);
}
}
Expand Down

0 comments on commit bcb479d

Please sign in to comment.