Submitted by:	Fredrik Westermarck


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137370 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2003-06-21 22:24:56 +00:00
parent 0525da4d6c
commit feac7d3bc7
2 changed files with 26 additions and 2 deletions

View File

@ -77,7 +77,7 @@
* @author Arun Mammen Thomas
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @since 1.0
* @version $Id: StringUtils.java,v 1.46 2003/06/08 14:10:54 scolebourne Exp $
* @version $Id: StringUtils.java,v 1.47 2003/06/21 22:24:55 bayard Exp $
*/
public class StringUtils {
@ -1048,6 +1048,9 @@ public static String chop(String str) {
*/
public static String chopNewline(String str) {
int lastIdx = str.length() - 1;
if (lastIdx == 0) {
return "";
}
char last = str.charAt(lastIdx);
if (last == '\n') {
if (str.charAt(lastIdx - 1) == '\r') {

View File

@ -69,7 +69,7 @@
* @author <a href="mailto:fredrik@westermarck.com>Fredrik Westermarck</a>
* @author Holger Krauth
* @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: StringUtilsTest.java,v 1.19 2003/04/16 04:37:33 bayard Exp $
* @version $Id: StringUtilsTest.java,v 1.20 2003/06/21 22:24:56 bayard Exp $
*/
public class StringUtilsTest extends TestCase {
@ -333,6 +333,27 @@ public void testChomp() {
"foo", StringUtils.chomp("foo", "foooo"));
}
public void testChopNewLine() {
String[][] newLineCases = {
{ FOO + "\r\n", FOO } ,
{ FOO + "\n" , FOO } ,
{ FOO + "\r", FOO + "\r" },
{ FOO, FOO },
{ FOO + "\n" + FOO , FOO + "\n" + FOO },
{ FOO + "\n\n", FOO + "\n"},
{ "\n", "" },
{ "\r\n", "" }
};
for (int i = 0; i < newLineCases.length; i++) {
String original = newLineCases[i][0];
String expectedResult = newLineCases[i][1];
assertEquals("chopNewline(String) failed",
expectedResult, StringUtils.chopNewline(original));
}
}
public void testSliceFunctions() {
String[][] sliceCases = {