[
https://issues.apache.org/jira/browse/LANG-1184?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15103572#comment-15103572
]
ASF GitHub Bot commented on LANG-1184:
--------------------------------------
Github user hen commented on a diff in the pull request:
https://github.com/apache/commons-lang/pull/113#discussion_r49941082
--- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
@@ -8026,34 +8026,31 @@ private static boolean endsWith(final CharSequence
str, final CharSequence suffi
* @since 3.0
*/
public static String normalizeSpace(final String str) {
- // LANG-1020: Improved performance significantly by normalizing
manually instead of using regex
- // See
https://github.com/librucha/commons-lang-normalizespaces-benchmark for
performance test
if (isEmpty(str)) {
return str;
}
+ if (isBlank(str)){
+ return EMPTY;
+ }
+
final int size = str.length();
final char[] newChars = new char[size];
int count = 0;
int whitespacesCount = 0;
- boolean startWhitespaces = true;
for (int i = 0; i < size; i++) {
char actualChar = str.charAt(i);
- boolean isWhitespace = Character.isWhitespace(actualChar);
+ boolean isWhitespace = Character.isWhitespace(actualChar) ||
actualChar == '\u00A0';
--- End diff --
Noting that the javadoc doesn't indicate that nbsp is escaped. I'm +1 to
also escaping nbsp, but javadoc should be updated.
> StringUtils#normalizeSpace no longer normalizes unicode non-breaking spaces
> (\u00A0) and does not trim control chars at the end any more
> ----------------------------------------------------------------------------------------------------------------------------------------
>
> Key: LANG-1184
> URL: https://issues.apache.org/jira/browse/LANG-1184
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.*
> Affects Versions: 3.4
> Reporter: Pascal Schumacher
>
> These work with 3.3.2, but fail with 3.4
> {code:java}assertEquals("a b", StringUtils.normalizeSpace("a\u00A0 b"));{code}
> {code:java}assertEquals("b", StringUtils.normalizeSpace("b\u0000"));{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)