Adding 00A0 to the list of whitespace characters per LANG-910

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1531643 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2013-10-13 09:02:07 +00:00
parent 439ee3bc05
commit f9b486a171
3 changed files with 8 additions and 3 deletions

View File

@ -22,6 +22,7 @@
<body> <body>
<release version="3.2" date="TBA" description="Next release"> <release version="3.2" date="TBA" description="Next release">
<action issue="LANG-910" type="update" due-to="Timur Yarosh">StringUtils.normalizeSpace now handles non-breaking spaces (Unicode 00A0)</action>
<action issue="LANG-804" type="update" dev="britter" due-to="Allon Mureinik">Redundant check for zero in HashCodeBuilder ctor</action> <action issue="LANG-804" type="update" dev="britter" due-to="Allon Mureinik">Redundant check for zero in HashCodeBuilder ctor</action>
<action issue="LANG-893" type="add" dev="oheger" due-to="Woonsan Ko">StrSubstitutor now supports default values for variables</action> <action issue="LANG-893" type="add" dev="oheger" due-to="Woonsan Ko">StrSubstitutor now supports default values for variables</action>
<action issue="LANG-913" type="add" dev="britter" due-to="Allon Mureinik">Adding .gitignore to commons-lang</action> <action issue="LANG-913" type="add" dev="britter" due-to="Allon Mureinik">Adding .gitignore to commons-lang</action>

View File

@ -178,7 +178,7 @@ public class StringUtils {
* single space, thus matching the same would likely cause a great * single space, thus matching the same would likely cause a great
* many noop replacements. * many noop replacements.
*/ */
private static final Pattern WHITESPACE_PATTERN = Pattern.compile("(?: \\s|[\\s&&[^ ]])\\s*"); private static final Pattern WHITESPACE_PATTERN = Pattern.compile("(?: |\\u00A0|\\s|[\\s&&[^ ]])\\s*");
/** /**
* <p>{@code StringUtils} instances should NOT be constructed in * <p>{@code StringUtils} instances should NOT be constructed in

View File

@ -47,11 +47,13 @@ public class StringUtilsTest {
static final String WHITESPACE; static final String WHITESPACE;
static final String NON_WHITESPACE; static final String NON_WHITESPACE;
static final String HARD_SPACE;
static final String TRIMMABLE; static final String TRIMMABLE;
static final String NON_TRIMMABLE; static final String NON_TRIMMABLE;
static { static {
String ws = ""; String ws = "";
String nws = ""; String nws = "";
String hs = String.valueOf(((char) 160));
String tr = ""; String tr = "";
String ntr = ""; String ntr = "";
for (int i = 0; i < Character.MAX_VALUE; i++) { for (int i = 0; i < Character.MAX_VALUE; i++) {
@ -69,6 +71,7 @@ public class StringUtilsTest {
} }
WHITESPACE = ws; WHITESPACE = ws;
NON_WHITESPACE = nws; NON_WHITESPACE = nws;
HARD_SPACE = hs;
TRIMMABLE = tr; TRIMMABLE = tr;
NON_TRIMMABLE = ntr; NON_TRIMMABLE = ntr;
} }
@ -2119,14 +2122,14 @@ public class StringUtilsTest {
assertEquals("", StringUtils.getCommonPrefix("xyz", "abcde")); assertEquals("", StringUtils.getCommonPrefix("xyz", "abcde"));
assertEquals("i am a ", StringUtils.getCommonPrefix("i am a machine", "i am a robot")); assertEquals("i am a ", StringUtils.getCommonPrefix("i am a machine", "i am a robot"));
} }
@Test @Test
public void testNormalizeSpace() { public void testNormalizeSpace() {
assertEquals(null, StringUtils.normalizeSpace(null)); assertEquals(null, StringUtils.normalizeSpace(null));
assertEquals("", StringUtils.normalizeSpace("")); assertEquals("", StringUtils.normalizeSpace(""));
assertEquals("", StringUtils.normalizeSpace(" ")); assertEquals("", StringUtils.normalizeSpace(" "));
assertEquals("", StringUtils.normalizeSpace("\t")); assertEquals("", StringUtils.normalizeSpace("\t"));
assertEquals("", StringUtils.normalizeSpace("\n")); assertEquals("", StringUtils.normalizeSpace("\n"));
assertEquals("", StringUtils.normalizeSpace("\u0009")); assertEquals("", StringUtils.normalizeSpace("\u0009"));
assertEquals("", StringUtils.normalizeSpace("\u000B")); assertEquals("", StringUtils.normalizeSpace("\u000B"));
assertEquals("", StringUtils.normalizeSpace("\u000C")); assertEquals("", StringUtils.normalizeSpace("\u000C"));
@ -2139,6 +2142,7 @@ public class StringUtilsTest {
assertEquals("a", StringUtils.normalizeSpace(" a ")); assertEquals("a", StringUtils.normalizeSpace(" a "));
assertEquals("a b c", StringUtils.normalizeSpace(" a b c ")); assertEquals("a b c", StringUtils.normalizeSpace(" a b c "));
assertEquals("a b c", StringUtils.normalizeSpace("a\t\f\r b\u000B c\n")); assertEquals("a b c", StringUtils.normalizeSpace("a\t\f\r b\u000B c\n"));
assertEquals("a b c", StringUtils.normalizeSpace("a\t\f\r " + HARD_SPACE + HARD_SPACE + "b\u000B c\n"));
} }
@Test @Test