You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2014/04/11 15:28:30 UTC
svn commit: r1586649 - in /commons/proper/lang/trunk/src:
changes/changes.xml main/java/org/apache/commons/lang3/text/WordUtils.java
test/java/org/apache/commons/lang3/text/WordUtilsTest.java
Author: britter
Date: Fri Apr 11 13:28:30 2014
New Revision: 1586649
URL: http://svn.apache.org/r1586649
Log:
LANG-995: Fix bug with stripping spaces on last line in WordUtils.wrap(). This fixes #18 from github. Thanks to Andrey Khobnya
Modified:
commons/proper/lang/trunk/src/changes/changes.xml
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java
Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1586649&r1=1586648&r2=1586649&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Fri Apr 11 13:28:30 2014
@@ -22,6 +22,7 @@
<body>
<release version="3.4" date="tba" description="tba">
+ <action issue="LANG-995" type="fix" dev="britter" due-to="Andrey Khobnya">Fix bug with stripping spaces on last line in WordUtils.wrap()</action>
</release>
<release version="3.3.2" date="2014-04-09" description="Bugfix for a bug in NumberUtils introduced in 3.3.1">
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java?rev=1586649&r1=1586648&r2=1586649&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java Fri Apr 11 13:28:30 2014
@@ -183,11 +183,15 @@ public class WordUtils {
int offset = 0;
final StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32);
- while (inputLineLength - offset > wrapLength) {
+ while (offset < inputLineLength) {
if (str.charAt(offset) == ' ') {
offset++;
continue;
}
+ // only last line without leading spaces is left
+ if(inputLineLength - offset <= wrapLength) {
+ break;
+ }
int spaceToWrapAt = str.lastIndexOf(' ', wrapLength + offset);
if (spaceToWrapAt >= offset) {
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java?rev=1586649&r1=1586648&r2=1586649&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java Fri Apr 11 13:28:30 2014
@@ -71,6 +71,12 @@ public class WordUtilsTest {
expected = "Click here," + systemNewLine + "http://commons.apache.org," + systemNewLine
+ "to jump to the" + systemNewLine + "commons website";
assertEquals(expected, WordUtils.wrap(input, 20));
+
+ // leading spaces on a new line are stripped
+ // trailing spaces are not stripped
+ input = "word1 word2 word3";
+ expected = "word1 " + systemNewLine + "word2 " + systemNewLine + "word3";
+ assertEquals(expected, WordUtils.wrap(input, 7));
}
@Test