FileDocCategorySizeDatePackage
KVMStringTable.javaAPI DocJ2ME CLDC 1.14375Wed Feb 05 15:56:02 GMT 2003runtime

KVMStringTable

public class KVMStringTable extends vm.StringTable

Fields Summary
public static final String
charArrayName
public static final String
stringArrayName
StringHashTable
stringHashTable
private static final int
maxCom
Constructors Summary
Methods Summary
private voidcommentary(java.lang.String s, CCodeWriter out)


            
    out.print("\t\t/* ");
    if (s.length() > maxCom) { 
        s = s.substring(0, maxCom - 3) + "...";
    } 
    out.printSafeString(s);
    out.print(" */\n");
    
public voidintern(StringConstant s)

 
    super.intern(s);
    stringHashTable.addEntry(s);
    
private booleanwriteCharacterArray(KVMWriter writer)

    final CCodeWriter out = writer.out;
    int n = arrangeStringData();
    if ( n == 0 ) { 
        return false; // nothing to do here.
    }
    final char v[] = new char[n];
    data.getChars( 0, n, v, 0 );

    // First, typedef the header we're about to create
    out.print("static CONST CHARARRAY_X(" + n + ") " 
          + charArrayName + " = {\n");
    
    out.println("\tCHARARRAY_HEADER(" + v.length + "),");
    out.println("\t{");
    writer.writeArray(v.length, 10, "\t\t", 
              new KVMWriter.ArrayPrinter() { 
                              public void print(int index) { 
                  char c = v[index];
                  if (c == '\\") {
                      out.print("'\\\\'");
                  } else if (c == '\'") {
                      out.print("'\\''");
                  } else if (c >= ' " && c <= 0x7E) { 
                      out.print("'" + c + "' ");
                  } else { 
                      out.printHexInt(c);
                  }
                  }
                      });
    out.println("\t}");
    out.println("};\n");
    return true;
    
public voidwriteString(CCodeWriter out, StringConstant s)

 
    if (s.unicodeIndex < 0) { 
        System.out.println("String not in stringtable: \"" + s.str.string + "\"");
    }
    out.write('&");
    out.print(stringArrayName);
    out.write('[");
    out.print(s.unicodeIndex);
    out.write(']");        
    
private voidwriteStringInfo(KVMWriter writer)

    CCodeWriter out = writer.out;
    int count = internedStringCount();

    StringConstant stringTable[] = new StringConstant[count];
    
    for (Enumeration e = allStrings(); e.hasMoreElements(); ) { 
        StringConstant s = (StringConstant)e.nextElement();
        stringTable[ s.unicodeIndex ] = s;
    }
        
    out.println("static CONST struct internedStringInstanceStruct " + 
            stringArrayName + "[" + count + "] = {");
    for (int i = 0; i < count; i++) { 
        StringConstant s = stringTable[i];
        String string = s.str.string;
        StringConstant next = 
           (StringConstant)stringHashTable.getNext(s);

        commentary(string, out);
        out.print("\tKVM_INIT_JAVA_STRING(" + s.unicodeOffset + ", "
              + string.length() + ", ");
        if (next == null) { 
        out.print(0);
        } else { 
        writeString(out, next);
        } 
        out.println("), ");
    }
    out.println("};\n\n");
    
final intwriteStrings(KVMWriter writer, java.lang.String name)


         
    writeCharacterArray(writer);
    writeStringInfo(writer);
    stringHashTable.writeTable(writer.out, name);
    return internedStringCount();