You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pa...@apache.org on 2017/05/04 10:34:44 UTC
[1/3] [text] port changes from commons-lang WordUtils to commons-text
WordUtils
Repository: commons-text
Updated Branches:
refs/heads/master 0b6a285bb -> 4d84a33e4
port changes from commons-lang WordUtils to commons-text WordUtils
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/c0f7877b
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/c0f7877b
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/c0f7877b
Branch: refs/heads/master
Commit: c0f7877b0e72b0b27fbd14c02da315e3247a2e95
Parents: 0b6a285
Author: Pascal Schumacher <pa...@gmx.net>
Authored: Thu May 4 12:30:02 2017 +0200
Committer: Pascal Schumacher <pa...@gmx.net>
Committed: Thu May 4 12:30:02 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/commons/text/WordUtils.java | 36 +++++++++++---------
.../org/apache/commons/text/WordUtilsTest.java | 8 +++++
2 files changed, 28 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-text/blob/c0f7877b/src/main/java/org/apache/commons/text/WordUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/WordUtils.java b/src/main/java/org/apache/commons/text/WordUtils.java
index 0cee2f6..f4a4c8e 100644
--- a/src/main/java/org/apache/commons/text/WordUtils.java
+++ b/src/main/java/org/apache/commons/text/WordUtils.java
@@ -16,10 +16,12 @@
*/
package org.apache.commons.text;
-import java.lang.reflect.Array;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
+
/**
* <p>Operations on Strings that contain words.</p>
*
@@ -31,8 +33,6 @@ import java.util.regex.Pattern;
*/
public class WordUtils {
- private static final int THIRTY_TWO = 32;
-
/**
* <p><code>WordUtils</code> instances should NOT be constructed in
* standard programming. Instead, the class should be used as
@@ -108,7 +108,7 @@ public class WordUtils {
* <table border="1" summary="Wrap Results">
* <tr>
* <th>input</th>
- * <th>wrapLenght</th>
+ * <th>wrapLength</th>
* <th>newLineString</th>
* <th>wrapLongWords</th>
* <th>result</th>
@@ -189,7 +189,7 @@ public class WordUtils {
* <table border="1" summary="Wrap Results">
* <tr>
* <th>input</th>
- * <th>wrapLenght</th>
+ * <th>wrapLength</th>
* <th>newLineString</th>
* <th>wrapLongWords</th>
* <th>wrapOn</th>
@@ -280,18 +280,18 @@ public class WordUtils {
return null;
}
if (newLineStr == null) {
- newLineStr = System.getProperty("line.separator");
+ newLineStr = System.lineSeparator();
}
if (wrapLength < 1) {
wrapLength = 1;
}
- if (wrapOn == null || wrapOn.length() == 0 || wrapOn.trim().length() == 0) {
+ if (StringUtils.isBlank(wrapOn)) {
wrapOn = " ";
}
final Pattern patternToWrapOn = Pattern.compile(wrapOn);
final int inputLineLength = str.length();
int offset = 0;
- final StringBuilder wrappedLine = new StringBuilder(inputLineLength + THIRTY_TWO);
+ final StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32);
while (offset < inputLineLength) {
int spaceToWrapAt = -1;
@@ -301,8 +301,9 @@ public class WordUtils {
if (matcher.start() == 0) {
offset += matcher.end();
continue;
+ } else {
+ spaceToWrapAt = matcher.start() + offset;
}
- spaceToWrapAt = matcher.start();
}
// only last line without leading spaces is left
@@ -410,7 +411,7 @@ public class WordUtils {
*/
public static String capitalize(final String str, final char... delimiters) {
final int delimLen = delimiters == null ? -1 : delimiters.length;
- if (str == null || str.length() == 0 || delimLen == 0) {
+ if (StringUtils.isEmpty(str) || delimLen == 0) {
return str;
}
final char[] buffer = str.toCharArray();
@@ -478,7 +479,7 @@ public class WordUtils {
*/
public static String capitalizeFully(String str, final char... delimiters) {
final int delimLen = delimiters == null ? -1 : delimiters.length;
- if (str == null || str.length() == 0 || delimLen == 0) {
+ if (StringUtils.isEmpty(str) || delimLen == 0) {
return str;
}
str = str.toLowerCase();
@@ -533,7 +534,7 @@ public class WordUtils {
*/
public static String uncapitalize(final String str, final char... delimiters) {
final int delimLen = delimiters == null ? -1 : delimiters.length;
- if (str == null || str.length() == 0 || delimLen == 0) {
+ if (StringUtils.isEmpty(str) || delimLen == 0) {
return str;
}
final char[] buffer = str.toCharArray();
@@ -574,7 +575,7 @@ public class WordUtils {
* @return the changed String, <code>null</code> if null String input
*/
public static String swapCase(final String str) {
- if (str == null || str.length() == 0) {
+ if (StringUtils.isEmpty(str)) {
return str;
}
final char[] buffer = str.toCharArray();
@@ -623,6 +624,7 @@ public class WordUtils {
* @param str the String to get initials from, may be null
* @return String of initial letters, <code>null</code> if null String input
* @see #initials(String,char[])
+ * @since 2.2
*/
public static String initials(final String str) {
return initials(str, null);
@@ -652,9 +654,10 @@ public class WordUtils {
* @param delimiters set of characters to determine words, null means whitespace
* @return String of initial characters, <code>null</code> if null String input
* @see #initials(String)
+ * @since 2.2
*/
public static String initials(final String str, final char... delimiters) {
- if (str == null || str.length() == 0) {
+ if (StringUtils.isEmpty(str)) {
return str;
}
if (delimiters != null && delimiters.length == 0) {
@@ -701,13 +704,14 @@ public class WordUtils {
* @param word The CharSequence to check, may be null
* @param words The array of String words to search for, may be null
* @return {@code true} if all search words are found, {@code false} otherwise
+ * @since 3.5
*/
public static boolean containsAllWords(final CharSequence word, final CharSequence... words) {
- if (word == null || word.length() == 0 || words == null || Array.getLength(words) == 0) {
+ if (StringUtils.isEmpty(word) || ArrayUtils.isEmpty(words)) {
return false;
}
for (final CharSequence w : words) {
- if (w == null || w.length() == 0 || String.valueOf(w).trim().length() == 0) {
+ if (StringUtils.isBlank(w)) {
return false;
}
final Pattern p = Pattern.compile(".*\\b" + w + "\\b.*");
http://git-wip-us.apache.org/repos/asf/commons-text/blob/c0f7877b/src/test/java/org/apache/commons/text/WordUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/WordUtilsTest.java b/src/test/java/org/apache/commons/text/WordUtilsTest.java
index 0ab8b09..ced2716 100644
--- a/src/test/java/org/apache/commons/text/WordUtilsTest.java
+++ b/src/test/java/org/apache/commons/text/WordUtilsTest.java
@@ -417,4 +417,12 @@ public class WordUtilsTest {
assertEquals(expect, WordUtils.swapCase(test));
}
+ @Test
+ public void testLANG1292() throws Exception {
+ // Prior to fix, this was throwing StringIndexOutOfBoundsException
+ WordUtils.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
+ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
+ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",70);
+ }
+
}
[2/3] [text] checkstyle-suppressions.xml: also suppress MagicNumber
warning for WordUitls
Posted by pa...@apache.org.
checkstyle-suppressions.xml: also suppress MagicNumber warning for WordUitls
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/8140c6a7
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/8140c6a7
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/8140c6a7
Branch: refs/heads/master
Commit: 8140c6a7be164d03920734002febf5f763ad5bce
Parents: c0f7877
Author: Pascal Schumacher <pa...@gmx.net>
Authored: Thu May 4 12:31:15 2017 +0200
Committer: Pascal Schumacher <pa...@gmx.net>
Committed: Thu May 4 12:31:15 2017 +0200
----------------------------------------------------------------------
checkstyle-suppressions.xml | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-text/blob/8140c6a7/checkstyle-suppressions.xml
----------------------------------------------------------------------
diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml
index bdf6ecf..687034d 100644
--- a/checkstyle-suppressions.xml
+++ b/checkstyle-suppressions.xml
@@ -52,4 +52,6 @@
<suppress checks="MagicNumber" files="UnicodeEscaper.java" lines="0-99999" />
<suppress checks="MagicNumber" files="UnicodeUnescaper.java" lines="0-99999" />
+
+ <suppress checks="MagicNumber" files="WordUtils.java" lines="0-99999" />
</suppressions>
[3/3] [text] WordUtils: correct since javadoc tags
Posted by pa...@apache.org.
WordUtils: correct since javadoc tags
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/4d84a33e
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/4d84a33e
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/4d84a33e
Branch: refs/heads/master
Commit: 4d84a33e4aa0e72bce0047a059673d52a4e9a608
Parents: 8140c6a
Author: Pascal Schumacher <pa...@gmx.net>
Authored: Thu May 4 12:32:42 2017 +0200
Committer: Pascal Schumacher <pa...@gmx.net>
Committed: Thu May 4 12:32:42 2017 +0200
----------------------------------------------------------------------
src/main/java/org/apache/commons/text/WordUtils.java | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-text/blob/4d84a33e/src/main/java/org/apache/commons/text/WordUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/WordUtils.java b/src/main/java/org/apache/commons/text/WordUtils.java
index f4a4c8e..7988822 100644
--- a/src/main/java/org/apache/commons/text/WordUtils.java
+++ b/src/main/java/org/apache/commons/text/WordUtils.java
@@ -29,7 +29,7 @@ import org.apache.commons.lang3.StringUtils;
* An exception will not be thrown for a <code>null</code> input.
* Each method documents its behaviour in more detail.</p>
*
- * @since 1.0
+ * @since 1.1
*/
public class WordUtils {
@@ -624,7 +624,6 @@ public class WordUtils {
* @param str the String to get initials from, may be null
* @return String of initial letters, <code>null</code> if null String input
* @see #initials(String,char[])
- * @since 2.2
*/
public static String initials(final String str) {
return initials(str, null);
@@ -654,7 +653,6 @@ public class WordUtils {
* @param delimiters set of characters to determine words, null means whitespace
* @return String of initial characters, <code>null</code> if null String input
* @see #initials(String)
- * @since 2.2
*/
public static String initials(final String str, final char... delimiters) {
if (StringUtils.isEmpty(str)) {
@@ -704,7 +702,6 @@ public class WordUtils {
* @param word The CharSequence to check, may be null
* @param words The array of String words to search for, may be null
* @return {@code true} if all search words are found, {@code false} otherwise
- * @since 3.5
*/
public static boolean containsAllWords(final CharSequence word, final CharSequence... words) {
if (StringUtils.isEmpty(word) || ArrayUtils.isEmpty(words)) {