]> git.proxmox.com Git - mirror_edk2.git/commitdiff
There is a potential flaw in HelpInfo.java previously. It use String[substrnum] to...
authorjjin9 <jjin9@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 7 Sep 2006 02:37:43 +0000 (02:37 +0000)
committerjjin9 <jjin9@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 7 Sep 2006 02:37:43 +0000 (02:37 +0000)
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

Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java

index 92526a501f458193c02d5995d9f67f57b13b4e5c..99af925a6a8d9566b104183bf7dddcb777edb6af 100644 (file)
@@ -13,6 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 package org.tianocore.context;\r
 \r
+import java.util.LinkedList;\r
+\r
 public class HelpInfo {\r
 \r
     \r
@@ -39,17 +41,13 @@ public class HelpInfo {
      * @return no return value\r
      **/\r
     private static void outputSubUsageInfo(String str1, String str2) {\r
+        \r
         splitString(str2);\r
-        if (substrnum > 0) {\r
-            System.out.printf("\n%4s %-30s %s", "", str1, substr[0]);\r
-            for (int i = 1; i < substrnum; i++) {\r
-                if (substr[i] != null)\r
-                    System.out.printf("\n%4s %-30s %s", "", "", substr[i]);\r
-            }\r
-            substrnum = 0;\r
-        } else {\r
-            System.out.printf("\n%4s %-30s %s", "", str1, str2);\r
+        System.out.printf("\n%4s %-30s %s", "", str1, List.get(0));\r
+        for (int i=1; i<List.size(); i++){\r
+            System.out.printf("\n%4s %-30s %s", "", "", List.get(i));\r
         }\r
+        List.clear();\r
     }\r
 \r
     /** \r
@@ -60,31 +58,30 @@ public class HelpInfo {
     private static void splitString(String str) {\r
         int strlength = str.length();\r
         if (strlength > MaxSrtingLength) {\r
-            \r
-            //we should modify the array to list, for it is strange to + 2\r
-            substrnum = strlength / MaxSrtingLength + 2;\r
             String[] tokens = str.split("[ ]", 0);\r
-            substr = new String[substrnum];\r
+            String tempstr = null;\r
             int templength = 0;\r
-            int j = 0;\r
             int start = 0;\r
             int end = 0;\r
             for (int i = 0; i < tokens.length; i++) {\r
                 if ((templength = end + tokens[i].length() + 1) < (MaxSrtingLength + start)) {\r
                     end = templength;\r
                 } else {\r
-                    substr[j++] = str.substring(start, end);\r
+                    tempstr = str.substring(start, end);\r
+                    List.add(tempstr);\r
                     start = end;\r
                     i = i - 1;\r
                 }\r
             }\r
-            substr[j] = str.substring(start, end - 1);\r
+            tempstr = str.substring(start, end - 1);\r
+            List.add(tempstr);\r
+        } else {\r
+            List.add(str);\r
         }\r
     }\r
 \r
-    private static String[] substr = null;\r
-\r
-    private static int substrnum = 0;\r
+    \r
+    private static LinkedList<String> List = new LinkedList<String>();\r
 \r
     private static final int MaxSrtingLength = 40;\r
 \r