text: Add Jagex name formatter

This commit is contained in:
Ron Young
2018-10-18 17:24:40 -05:00
parent ae65bca6f5
commit 5b469025f6

View File

@@ -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 <br> delimited text with spaces and all multiple continuous
* spaces with single space