Merge remote-tracking branch 'runelite/master'
This commit is contained in:
@@ -211,34 +211,7 @@ public class Text
|
||||
*/
|
||||
public static String toJagexName(String str)
|
||||
{
|
||||
char[] chars = str.toCharArray();
|
||||
int newIdx = 0;
|
||||
|
||||
for (int oldIdx = 0, strLen = str.length(); oldIdx < strLen; oldIdx++)
|
||||
{
|
||||
char c = chars[oldIdx];
|
||||
|
||||
// take care of replacing and trimming in 1 go
|
||||
if (c == '\u00A0' || c == '-' || c == '_' || c == ' ')
|
||||
{
|
||||
if (oldIdx == strLen - 1 || newIdx == 0 || chars[newIdx - 1] == ' ')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
c = ' ';
|
||||
}
|
||||
|
||||
// 0 - 127 is valid ascii
|
||||
if (c > 127)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
chars[newIdx++] = c;
|
||||
}
|
||||
|
||||
return new String(chars, 0, newIdx);
|
||||
return CharMatcher.ascii().retainFrom(str.replaceAll("[\u00A0_-]", " ")).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,12 +45,6 @@ public class TextTest
|
||||
assertEquals("", Text.removeTags("<col=ffffff><img=2><col=00ffff> (level-126)", true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toJagexName()
|
||||
{
|
||||
assertEquals("Whoever This Is Lmao", Text.toJagexName("-__- - \u00A0\u00A0 Whoever\uABCD\uABCD\u00A0T\uABBBhis Is-Lmao"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFormattingTags()
|
||||
{
|
||||
@@ -64,4 +58,21 @@ public class TextTest
|
||||
assertEquals("a <lt> b", Text.removeFormattingTags("a <lt> b"));
|
||||
assertEquals("Remove no tags", Text.removeFormattingTags("Remove no tags"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toJagexName()
|
||||
{
|
||||
assertEquals("lab rat", Text.toJagexName("lab rat"));
|
||||
assertEquals("lab rat", Text.toJagexName("-lab_rat"));
|
||||
assertEquals("lab rat", Text.toJagexName(" lab-rat__"));
|
||||
assertEquals("lab rat", Text.toJagexName("lab\u00A0rat\u00A0\u00A0"));
|
||||
assertEquals("Test Man", Text.toJagexName("蹔Test\u00A0蹔Man"));
|
||||
assertEquals("Test Boy", Text.toJagexName(" Te⓲st\u00A0B⓲oy⓲ "));
|
||||
assertEquals("mR nAmE", Text.toJagexName("mR nAmE"));
|
||||
assertEquals("mR nAmE", Text.toJagexName("mR__nAmE"));
|
||||
assertEquals("mR nAmE", Text.toJagexName("mR--nAmE"));
|
||||
assertEquals("mR nAmE", Text.toJagexName("-_ mR\u00A0-nAmE _-"));
|
||||
assertEquals("mR nAmE", Text.toJagexName("--__--mR_-nAmE__ --"));
|
||||
assertEquals("Mind the gap", Text.toJagexName("Mind_-_-the-- __gap"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user