From 67ce7c51e719e82ef5be38aca6bb65588b73c016 Mon Sep 17 00:00:00 2001 From: jjin9 Date: Thu, 7 Sep 2006 02:37:43 +0000 Subject: [PATCH] There is a potential flaw in HelpInfo.java previously. It use String[substrnum] to save the result of splitString(), the substrnum is calculated approximatively and has to be set larger enough to provide sufficient space. So substrnum relate to the string specifically. In this version, it use ListedList to implement the splitString(), which is independent of string specifically. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1488 6f19259b-4bc3-4df7-8a09-765794883524 --- .../org/tianocore/context/HelpInfo.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java b/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java index 92526a501f..99af925a6a 100644 --- a/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java +++ b/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java @@ -13,6 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. package org.tianocore.context; +import java.util.LinkedList; + public class HelpInfo { @@ -39,17 +41,13 @@ public class HelpInfo { * @return no return value **/ private static void outputSubUsageInfo(String str1, String str2) { + splitString(str2); - if (substrnum > 0) { - System.out.printf("\n%4s %-30s %s", "", str1, substr[0]); - for (int i = 1; i < substrnum; i++) { - if (substr[i] != null) - System.out.printf("\n%4s %-30s %s", "", "", substr[i]); - } - substrnum = 0; - } else { - System.out.printf("\n%4s %-30s %s", "", str1, str2); + System.out.printf("\n%4s %-30s %s", "", str1, List.get(0)); + for (int i=1; i MaxSrtingLength) { - - //we should modify the array to list, for it is strange to + 2 - substrnum = strlength / MaxSrtingLength + 2; String[] tokens = str.split("[ ]", 0); - substr = new String[substrnum]; + String tempstr = null; int templength = 0; - int j = 0; int start = 0; int end = 0; for (int i = 0; i < tokens.length; i++) { if ((templength = end + tokens[i].length() + 1) < (MaxSrtingLength + start)) { end = templength; } else { - substr[j++] = str.substring(start, end); + tempstr = str.substring(start, end); + List.add(tempstr); start = end; i = i - 1; } } - substr[j] = str.substring(start, end - 1); + tempstr = str.substring(start, end - 1); + List.add(tempstr); + } else { + List.add(str); } } - private static String[] substr = null; - - private static int substrnum = 0; + + private static LinkedList List = new LinkedList(); private static final int MaxSrtingLength = 40; -- 2.39.2