\r
**/\r
class StringTable {\r
- private ArrayList<String> al;\r
+ class UnicodeString {\r
+ //\r
+ // In Schema, we define VariableName in DynamicPcdBuildDefinitions in FPD\r
+ // file to be HexWordArrayType. For example, Unicode String L"Setup" is \r
+ // <VariableName>0x0053 0x0065 0x0074 0x0075 0x0070</VariableName>. \r
+ // We use raw to differentiate if the String is in form of L"Setup" (raw is false) or\r
+ // in form of {0x0053, 0x0065, 0x0074, 0x0075, 0x0070}\r
+ //\r
+ // This str is the string that can be pasted directly into the C structure. \r
+ // For example, this str can be two forms:\r
+ // \r
+ // L"Setup",\r
+ // {0x0053, 0065, 0x0074, 0x0075, 0x0070, 0x0000}, //This is another form of L"Setup"\r
+ //\r
+ public String str;\r
+ //\r
+ // This len includes the NULL character at the end of the String.\r
+ //\r
+ public int len;\r
+ \r
+ public UnicodeString (String str, int len) {\r
+ this.str = str;\r
+ this.len = len;\r
+ }\r
+ }\r
+ \r
+ private ArrayList<UnicodeString> al;\r
private ArrayList<String> alComments;\r
private String phase;\r
- int len;\r
+ int stringTableCharNum;\r
\r
public StringTable (String phase) {\r
this.phase = phase;\r
- al = new ArrayList<String>();\r
+ al = new ArrayList<UnicodeString>();\r
alComments = new ArrayList<String>();\r
- len = 0;\r
+ stringTableCharNum = 0;\r
}\r
\r
public String getSizeMacro () {\r
//\r
// We have at least one Unicode Character in the table.\r
//\r
- return len == 0 ? 1 : len;\r
+ return stringTableCharNum == 0 ? 1 : stringTableCharNum;\r
}\r
\r
public String getExistanceMacro () {\r
// If there is any String in the StringTable\r
//\r
for (int i = 0; i < al.size(); i++) {\r
- String str = al.get(i);\r
+ UnicodeString uStr = al.get(i);\r
String stringTableName;\r
\r
if (i == 0) {\r
cDeclCode += tab;\r
}\r
cDeclCode += String.format("%-20s%s[%d]; /* %s */", "UINT16",\r
- stringTableName, str.length() + 1,\r
+ stringTableName, uStr.len,\r
alComments.get(i))\r
+ newLine;\r
\r
cInstCode = "/* StringTable */" + newLine;\r
}\r
\r
- cInstCode += tab + String.format("L\"%s\" /* %s */", al.get(i), alComments.get(i));\r
+ cInstCode += tab + String.format("%s /* %s */", uStr.str, alComments.get(i));\r
if (i != al.size() - 1) {\r
cInstCode += commaNewLine;\r
}\r
instTable.put(stringTable, cInstCode);\r
}\r
}\r
+ \r
+ public int add (List inputStr, Token token) {\r
+ String str;\r
+ \r
+ str = "{";\r
+ \r
+ for (int i = 0; i < inputStr.size(); i++) {\r
+ str += " " + inputStr.get(i) + ",";\r
+ }\r
+ \r
+ str += " 0x0000";\r
+ \r
+ str += "}";\r
+ //\r
+ // This is a raw Unicode String\r
+ //\r
+ return addToTable (str, inputStr.size() + 1, token);\r
+ }\r
\r
public int add (String inputStr, Token token) {\r
- int i;\r
- int pos;\r
\r
+ int len;\r
String str = inputStr;\r
\r
//\r
// "L\"Bootmode\"" or "Bootmode".\r
// We drop the L\" and \" for the first type.\r
if (str.startsWith("L\"") && str.endsWith("\"")) {\r
- str = str.substring(2, str.length() - 1);\r
+ //\r
+ // Substract the character of "L", """, """.\r
+ // and add in the NULL character. So it is 2.\r
+ //\r
+ len = str.length() - 2;\r
+ } else {\r
+ //\r
+ // Include the NULL character.\r
+ //\r
+ len = str.length() + 1;\r
+ str = "L\"" + str + "\"";\r
}\r
+ \r
+ //\r
+ // After processing, this is L"A String Sample" type of string.\r
+ //\r
+ return addToTable (str, len, token);\r
+ }\r
+ \r
+ private int addToTable (String inputStr, int len, Token token) {\r
+ int i;\r
+ int pos;\r
+\r
//\r
// Check if StringTable has this String already.\r
// If so, return the current pos.\r
//\r
for (i = 0, pos = 0; i < al.size(); i++) {\r
- String s = al.get(i);;\r
+ UnicodeString s = al.get(i);;\r
\r
- if (str.equals(s)) {\r
+ if (inputStr.equals(s.str)) {\r
return pos;\r
}\r
- pos = s.length() + 1;\r
+ pos += s.len;\r
}\r
\r
- i = len;\r
+ i = stringTableCharNum;\r
//\r
// Include the NULL character at the end of String\r
//\r
- len += str.length() + 1;\r
- al.add(str);\r
+ stringTableCharNum += len;\r
+ al.add(new UnicodeString(inputStr, len));\r
alComments.add(token.getPrimaryKeyString());\r
\r
return i;\r