From 28f37f2b4d357656f16b1bf1b5ec36cb90d63d87 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sat, 23 Nov 2002 00:54:24 +0000 Subject: [PATCH] Added the second fix from Mark McDowell [mcdoma@ncs.com] for bug #14062 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137160 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang/StringUtils.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index eed87d859..d461960dd 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -73,7 +73,7 @@ import java.util.Iterator; * @author Rand McNeely * @author Stephen Colebourne * @author Fredrik Westermarck - * @version $Id: StringUtils.java,v 1.25 2002/11/16 10:41:03 scolebourne Exp $ + * @version $Id: StringUtils.java,v 1.26 2002/11/23 00:54:24 bayard Exp $ */ public class StringUtils { @@ -487,22 +487,21 @@ public class StringUtils { String[] list = new String[listSize]; int i = 0; + int lastTokenBegin = 0; + int lastTokenEnd = 0; while (tok.hasMoreTokens()) { if (max > 0 && i == listSize - 1) { // In the situation where we hit the max yet have // tokens left over in our input, the last list // element gets all remaining text. - StringBuffer buf = new StringBuffer((int) 1.2 * str.length() * (listSize - i) / listSize); - while (tok.hasMoreTokens()) { - buf.append(tok.nextToken()); - if (tok.hasMoreTokens()) { - buf.append(separator); - } - } - list[i] = buf.toString(); + String endToken = tok.nextToken(); + lastTokenBegin = str.indexOf(endToken, lastTokenEnd); + list[i] = str.substring(lastTokenBegin); break; } else { list[i] = tok.nextToken(); + lastTokenBegin = str.indexOf(list[i], lastTokenEnd); + lastTokenEnd = lastTokenBegin + list[i].length(); } i++; }