fix for StringIndexOutOfBoundsException caused by overlong string passed to titleize(String str)

This commit is contained in:
Brettflan 2011-06-30 01:46:12 -05:00
parent 2f61e83a8a
commit 86112380da
1 changed files with 5 additions and 1 deletions

View File

@ -12,7 +12,11 @@ public class TextUtil {
int pivot = line.length() / 2;
int eatLeft = center.length() / 2;
int eatRight = center.length() - eatLeft;
return line.substring(0, pivot - eatLeft) + center + line.substring(pivot + eatRight);
if (eatLeft < pivot)
return line.substring(0, pivot - eatLeft) + center + line.substring(pivot + eatRight);
else
return center;
}
public static String repeat(String s, int times) {