From 86112380da9b98a2582ba4c6add5b7a734ebeed8 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 30 Jun 2011 01:46:12 -0500 Subject: [PATCH] fix for StringIndexOutOfBoundsException caused by overlong string passed to titleize(String str) --- src/org/mcteam/factions/util/TextUtil.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/org/mcteam/factions/util/TextUtil.java b/src/org/mcteam/factions/util/TextUtil.java index 20c60ee5..7e1d5efa 100644 --- a/src/org/mcteam/factions/util/TextUtil.java +++ b/src/org/mcteam/factions/util/TextUtil.java @@ -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) {