[LANG-1557] Change a Pattern to a static final field, for not letting it compile each time the function invoked. (#542)

* Pattern_to_static_

* move the constants to head of the file.

* Simplify private comment.

Co-authored-by: Gary Gregory <garydgregory@users.noreply.github.com>
This commit is contained in:
XenoAmess 2020-06-14 21:46:53 +08:00 committed by GitHub
parent 7852ed9d4d
commit 677604fb84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -179,6 +179,11 @@ public class StringUtils {
*/
private static final int PAD_LIMIT = 8192;
/**
* Pattern used in {@link #stripAccents(String)}.
*/
private static final Pattern STRIP_ACCENTS_PATTERN = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); //$NON-NLS-1$
// Abbreviating
//-----------------------------------------------------------------------
/**
@ -8215,11 +8220,10 @@ public class StringUtils {
if (input == null) {
return null;
}
final Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); //$NON-NLS-1$
final StringBuilder decomposed = new StringBuilder(Normalizer.normalize(input, Normalizer.Form.NFD));
convertRemainingAccentCharacters(decomposed);
// Note that this doesn't correctly remove ligatures...
return pattern.matcher(decomposed).replaceAll(EMPTY);
return STRIP_ACCENTS_PATTERN.matcher(decomposed).replaceAll(EMPTY);
}
// StripAll