Skip to content

Commit 80da42a

Browse files
author
Henri Yandell
committed
Handles empty string now as well.
Submitted by: Mark Ford git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137371 13f79535-47bb-0310-9956-ffa450edef68
1 parent feac7d3 commit 80da42a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/java/org/apache/commons/lang/StringUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
* @author Arun Mammen Thomas
7878
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
7979
* @since 1.0
80-
* @version $Id: StringUtils.java,v 1.47 2003/06/21 22:24:55 bayard Exp $
80+
* @version $Id: StringUtils.java,v 1.48 2003/06/23 03:51:13 bayard Exp $
8181
*/
8282
public class StringUtils {
8383

@@ -1048,7 +1048,7 @@ public static String chop(String str) {
10481048
*/
10491049
public static String chopNewline(String str) {
10501050
int lastIdx = str.length() - 1;
1051-
if (lastIdx == 0) {
1051+
if (lastIdx <= 0) {
10521052
return "";
10531053
}
10541054
char last = str.charAt(lastIdx);

src/test/org/apache/commons/lang/StringUtilsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
* @author <a href="mailto:fredrik@westermarck.com>Fredrik Westermarck</a>
7070
* @author Holger Krauth
7171
* @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
72-
* @version $Id: StringUtilsTest.java,v 1.20 2003/06/21 22:24:56 bayard Exp $
72+
* @version $Id: StringUtilsTest.java,v 1.21 2003/06/23 03:51:13 bayard Exp $
7373
*/
7474
public class StringUtilsTest extends TestCase {
7575

@@ -343,6 +343,7 @@ public void testChopNewLine() {
343343
{ FOO + "\n" + FOO , FOO + "\n" + FOO },
344344
{ FOO + "\n\n", FOO + "\n"},
345345
{ "\n", "" },
346+
{ "", "" },
346347
{ "\r\n", "" }
347348
};
348349

0 commit comments

Comments
 (0)