From 8a02507d441adcc814921295c61e7e7b37242ff0 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Mon, 11 Dec 2017 12:40:37 +0100 Subject: [PATCH] Let regex handle "getIdFromUrl" --- osu.Game/Online/Chat/ChatLink.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/osu.Game/Online/Chat/ChatLink.cs b/osu.Game/Online/Chat/ChatLink.cs index 90d2e46f62..acea78586b 100644 --- a/osu.Game/Online/Chat/ChatLink.cs +++ b/osu.Game/Online/Chat/ChatLink.cs @@ -18,6 +18,7 @@ using osu.Game.Overlays; using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; namespace osu.Game.Online.Chat { @@ -133,23 +134,7 @@ namespace osu.Game.Online.Chat base.OnLinkClicked(); } - private int getIdFromUrl(string url) - { - var lastSlashIndex = url.LastIndexOf('/'); - // Remove possible trailing slash - if (lastSlashIndex == url.Length) - { - url = url.Remove(url.Length - 1); - lastSlashIndex = url.LastIndexOf('/'); - } - - var lastQuestionMarkIndex = url.LastIndexOf('?'); - // Filter out possible queries like mode specifications (e.g. /b/252238?m=0) - if (lastQuestionMarkIndex > lastSlashIndex) - url = url.Remove(lastQuestionMarkIndex); - - return int.Parse(url.Substring(lastSlashIndex + 1)); - } + private int getIdFromUrl(string url) => int.Parse(Regex.Match(url, @"\/(\d+)\/?").Groups[1].Value); public string TooltipText {