use of java.util.Formatter in project android_frameworks_base by crdroidandroid.
the class StaticLayoutDirectionsTest method testDirections.
// @SmallTest
public void testDirections() {
StringBuilder buf = new StringBuilder("\n");
Formatter f = new Formatter(buf);
LayoutBuilder b = StaticLayoutTest.builder();
for (int i = 0; i < texts.length; ++i) {
b.setText(pseudoBidiToReal(texts[i]));
checkDirections(b.build(), i, b.text, expected, f);
}
if (buf.length() > 1) {
fail(buf.toString());
}
}
use of java.util.Formatter in project jdk8u_jdk by JetBrains.
the class ResourceBundleGenerator method generateBundle.
@Override
public void generateBundle(String packageName, String baseName, String localeID, boolean useJava, Map<String, ?> map, BundleType type) throws IOException {
String suffix = useJava ? ".java" : ".properties";
String lang = CLDRConverter.getLanguageCode(localeID);
String dirName = CLDRConverter.DESTINATION_DIR + File.separator + "sun" + File.separator + packageName + File.separator + "resources" + File.separator + "cldr";
if (lang.length() > 0) {
dirName = dirName + File.separator + lang;
packageName = packageName + ".resources.cldr." + lang;
} else {
packageName = packageName + ".resources.cldr";
}
File dir = new File(dirName);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir, baseName + ("root".equals(localeID) ? "" : "_" + localeID) + suffix);
if (!file.exists()) {
file.createNewFile();
}
CLDRConverter.info("\tWriting file " + file);
String encoding;
if (useJava) {
if (CLDRConverter.USE_UTF8) {
encoding = "utf-8";
} else {
encoding = "us-ascii";
}
} else {
encoding = "iso-8859-1";
}
Formatter fmt = null;
if (type == BundleType.TIMEZONE) {
fmt = new Formatter();
Set<String> metaKeys = new HashSet<>();
for (String key : map.keySet()) {
if (key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) {
String meta = key.substring(CLDRConverter.METAZONE_ID_PREFIX.length());
String[] value;
value = (String[]) map.get(key);
fmt.format(" final String[] %s = new String[] {\n", meta);
for (String s : value) {
fmt.format(" \"%s\",\n", CLDRConverter.saveConvert(s, useJava));
}
fmt.format(" };\n");
metaKeys.add(key);
}
}
for (String key : metaKeys) {
map.remove(key);
}
// Make it preferred ordered
LinkedHashMap<String, Object> newMap = new LinkedHashMap<>();
for (String preferred : preferredTZIDs) {
if (map.containsKey(preferred)) {
newMap.put(preferred, map.remove(preferred));
} else if (("GMT".equals(preferred) || "UTC".equals(preferred)) && metaKeys.contains(CLDRConverter.METAZONE_ID_PREFIX + preferred)) {
newMap.put(preferred, preferred);
}
}
newMap.putAll(map);
map = newMap;
}
try (PrintWriter out = new PrintWriter(file, encoding)) {
// Output copyright headers
out.println(CopyrightHeaders.getOpenJDKCopyright());
out.println(CopyrightHeaders.getUnicodeCopyright());
if (useJava) {
out.println("package sun." + packageName + ";\n");
out.printf("import %s;\n\n", type.getPathName());
out.printf("public class %s%s extends %s {\n", baseName, "root".equals(localeID) ? "" : "_" + localeID, type.getClassName());
out.println(" @Override\n" + " protected final Object[][] getContents() {");
if (fmt != null) {
out.print(fmt.toString());
}
out.println(" final Object[][] data = new Object[][] {");
}
for (String key : map.keySet()) {
if (useJava) {
Object value = map.get(key);
if (value == null) {
CLDRConverter.warning("null value for " + key);
} else if (value instanceof String) {
if (type == BundleType.TIMEZONE) {
out.printf(" { \"%s\", %s },\n", key, CLDRConverter.saveConvert((String) value, useJava));
} else {
out.printf(" { \"%s\", \"%s\" },\n", key, CLDRConverter.saveConvert((String) value, useJava));
}
} else if (value instanceof String[]) {
String[] values = (String[]) value;
out.println(" { \"" + key + "\",\n new String[] {");
for (String s : values) {
out.println(" \"" + CLDRConverter.saveConvert(s, useJava) + "\",");
}
out.println(" }\n },");
} else {
throw new RuntimeException("unknown value type: " + value.getClass().getName());
}
} else {
out.println(key + "=" + CLDRConverter.saveConvert((String) map.get(key), useJava));
}
}
if (useJava) {
out.println(" };\n return data;\n }\n}");
}
}
}
use of java.util.Formatter in project jdk8u_jdk by JetBrains.
the class EUC_TW method genClass.
static void genClass(String[] args) throws Exception {
InputStream is = new FileInputStream(new File(args[0], "euc_tw.map"));
PrintStream ps = new PrintStream(new File(args[1], "EUC_TWMapping.java"), "ISO-8859-1");
String copyright = getCopyright(new File(args[3]));
// ranges of byte1 and byte2, something should come from a "config" file
int b1Min = 0xa1;
int b1Max = 0xfe;
int b2Min = 0xa1;
int b2Max = 0xfe;
try {
// doublebyte
int[][] db = new int[8][0x10000];
// doublebyte
byte[] suppFlag = new byte[0x10000];
char[] indexC2B = new char[256];
char[] indexC2BSupp = new char[256];
for (int i = 0; i < 8; i++) for (int j = 0; j < 0x10000; j++) db[i][j] = UNMAPPABLE_DECODING;
Parser p = new Parser(is, euctw);
Entry e = null;
while ((e = p.next()) != null) {
int plane = 0;
if (e.bs >= 0x10000) {
plane = ((e.bs >> 16) & 0xff) - 1;
if (plane >= 14)
plane = 7;
e.bs = e.bs & 0xffff;
}
db[plane][e.bs] = e.cp;
if (e.cp < 0x10000) {
indexC2B[e.cp >> 8] = 1;
} else {
indexC2BSupp[(e.cp & 0xffff) >> 8] = 1;
suppFlag[e.bs] |= (1 << plane);
}
}
StringBuilder sb = new StringBuilder();
Output out = new Output(new Formatter(sb));
out.format(copyright);
out.format("%n// -- This file was mechanically generated: Do not edit! -- //%n");
out.format("package sun.nio.cs.ext;%n%n");
out.format("class EUC_TWMapping {%n%n");
// boundaries
out.format(" final static int b1Min = 0x%x;%n", b1Min);
out.format(" final static int b1Max = 0x%x;%n", b1Max);
out.format(" final static int b2Min = 0x%x;%n", b2Min);
out.format(" final static int b2Max = 0x%x;%n", b2Max);
// b2c tables
out.format("%n final static String[] b2c = {%n");
for (int plane = 0; plane < 8; plane++) {
out.format(" // Plane %d%n", plane);
out.format(toCharArray(db[plane], b1Min, b1Max, b2Min, b2Max), ",");
out.format("%n");
}
out.format(" };%n");
// c2bIndex
out.format("%n static final int C2BSIZE = 0x%x;%n", initC2BIndex(indexC2B));
out.format("%n static char[] c2bIndex = new char[] {%n");
out.format(indexC2B);
out.format(" };%n");
// c2bIndexSupp
out.format("%n static final int C2BSUPPSIZE = 0x%x;%n", initC2BIndex(indexC2BSupp));
out.format("%n static char[] c2bSuppIndex = new char[] {%n");
out.format(indexC2BSupp);
out.format(" };%n");
// suppFlags
out.format("%n static String b2cIsSuppStr =%n");
out.format(toCharArray(suppFlag, b1Min, b1Max, b2Min, b2Max), ";");
out.format("}");
out.close();
ps.println(sb.toString());
ps.close();
} catch (Exception x) {
x.printStackTrace();
}
}
use of java.util.Formatter in project jdk8u_jdk by JetBrains.
the class HKSCS method genClass0.
static void genClass0(InputStream isB2C, InputStream isC2B, PrintStream ps, String clzName, String copyright) throws Exception {
// ranges of byte1 and byte2, something should come from a "config" file
int b1Min = 0x87;
int b1Max = 0xfe;
int b2Min = 0x40;
int b2Max = 0xfe;
try {
char[] bmp = new char[0x10000];
char[] supp = new char[0x10000];
boolean[] b2cBmp = new boolean[0x100];
boolean[] b2cSupp = new boolean[0x100];
// pua should be in range of e000-f8ff. Expand
// it to 0xf93b becase the hkscs2001.c2b has
// the f920-f93b filled
//char[] pua = new char[0xF8FF - 0xE000 + 1];
char[] pua = new char[0xF93b - 0xE000 + 1];
boolean hasSupp = false;
boolean hasPua = false;
Arrays.fill(bmp, UNMAPPABLE_DECODING);
Arrays.fill(supp, UNMAPPABLE_DECODING);
Arrays.fill(pua, UNMAPPABLE_DECODING);
Parser p = new Parser(isB2C, hkscs);
Entry e = null;
while ((e = p.next()) != null) {
if (e.cp >= 0x10000) {
supp[e.bs] = (char) e.cp;
b2cSupp[e.bs >> 8] = true;
hasSupp = true;
} else {
bmp[e.bs] = (char) e.cp;
b2cBmp[e.bs >> 8] = true;
}
if (e.cp2 != 0 && e.cp2 >= 0xe000 && e.cp2 <= 0xf8ff) {
hasPua = true;
pua[e.cp2 - 0xE000] = (char) e.bs;
}
}
if (isC2B != null) {
p = new Parser(isC2B, hkscs);
e = null;
while ((e = p.next()) != null) {
pua[e.cp - 0xE000] = (char) e.bs;
}
hasPua = true;
}
StringBuilder sb = new StringBuilder();
Output out = new Output(new Formatter(sb));
out.format(copyright);
out.format("%n// -- This file was mechanically generated: Do not edit! -- //%n");
out.format("package sun.nio.cs.ext;%n%n");
out.format("class %s {%n%n", clzName);
/* hardcoded in sun.nio.cs.ext.HKSCS.java
out.format(" final static int b1Min = 0x%x;%n", b1Min);
out.format(" final static int b1Max = 0x%x;%n", b1Max);
out.format(" final static int b2Min = 0x%x;%n", b2Min);
out.format(" final static int b2Max = 0x%x;%n", b2Max);
*/
// bmp tables
out.format("%n static final String[] b2cBmpStr = new String[] {%n");
for (int i = 0; i < 0x100; i++) {
if (b2cBmp[i])
out.format(bmp, i, b2Min, b2Max, ",");
else
//unmappable segments
out.format(" null,%n");
}
out.format(" };%n");
// supp tables
out.format("%n static final String[] b2cSuppStr =");
if (hasSupp) {
out.format(" new String[] {%n");
for (int i = 0; i < 0x100; i++) {
if (b2cSupp[i])
out.format(supp, i, b2Min, b2Max, ",");
else
//unmappable segments
out.format(" null,%n");
}
out.format(" };%n");
} else {
out.format(" null;%n");
}
// private area tables
out.format("%n final static String pua =");
if (hasPua) {
out.format("%n");
out.format(pua, 0, pua.length, ";");
} else {
out.format(" null;%n");
}
out.format("%n");
out.format("}");
out.close();
ps.println(sb.toString());
ps.close();
} catch (Exception x) {
x.printStackTrace();
}
}
use of java.util.Formatter in project android by JetBrains.
the class ChildInfo method toString.
@Override
public String toString() {
Formatter formatter = new Formatter();
formatter.format("row1: %s%n", row1);
formatter.format("column1: %s%n", column1);
formatter.format("row2: %s%n", row2);
formatter.format("column2: %s%n", column2);
return formatter.toString();
}
Aggregations