text: Add Jagex name formatter
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.util;
|
package net.runelite.client.util;
|
||||||
|
|
||||||
|
import com.google.common.base.CharMatcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,6 +57,18 @@ public class Text
|
|||||||
return removeTags(str).replace('\u00A0', ' ').trim().toLowerCase();
|
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
|
* In addition to removing all tags, replaces all <br> delimited text with spaces and all multiple continuous
|
||||||
* spaces with single space
|
* spaces with single space
|
||||||
|
|||||||
Reference in New Issue
Block a user