From 5b469025f6c5faf08d69b6a357e562fb82ca48bd Mon Sep 17 00:00:00 2001 From: Ron Young Date: Thu, 18 Oct 2018 17:24:40 -0500 Subject: [PATCH] text: Add Jagex name formatter --- .../main/java/net/runelite/client/util/Text.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/util/Text.java b/runelite-client/src/main/java/net/runelite/client/util/Text.java index 83f3b89ed8..72be89f3b4 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/Text.java +++ b/runelite-client/src/main/java/net/runelite/client/util/Text.java @@ -25,6 +25,7 @@ */ package net.runelite.client.util; +import com.google.common.base.CharMatcher; import java.util.regex.Pattern; /** @@ -56,6 +57,18 @@ public class Text return removeTags(str).replace('\u00A0', ' ').trim().toLowerCase(); } + /** + * Convert a string into Jagex username format + * Remove all non-ascii characters, replace nbsp with space, replace _- with spaces, and trim + * + * @param str The string to standardize + * @return The given `str` that is in Jagex name format + */ + public static String toJagexName(String str) + { + return CharMatcher.ascii().retainFrom(str.replace('\u00A0', ' ')).replaceAll("[_-]+", " ").trim(); + } + /** * In addition to removing all tags, replaces all
delimited text with spaces and all multiple continuous * spaces with single space