| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package jpype.utf8; |
| 17 |
|
| 18 |
public class Utf8Test |
| 19 |
{ |
| 20 |
|
| 21 |
private final static String[] DEFAULT_STRINGS = |
| 22 |
{ |
| 23 |
"I can eat glass and it doesn't hurt me.", |
| 24 |
"Je peux manger du verre, \u00E7a ne me fait pas mal.", |
| 25 |
"\u16D6\u16B4 \u16B7\u16D6\u16CF \u16D6\u16CF\u16C1 \u16A7 \u16B7\u16DA\u16D6\u16B1 \u16D8\u16BE \u16A6\u16D6\u16CB\u16CB \u16A8\u16A7 \u16A1\u16D6 \u16B1\u16A7\u16A8 \u16CB\u16A8\u16B1", |
| 26 |
"\u4EBA\u4EBA\u751F\u800C\u81EA\u7531,\u5728\u5C0A\u4E25\u548C\u6743\u5229\u4E0A\u4E00\u5F8B\u5E73\u7B49\u3002\u4ED6\u4EEC\u8D4B\u6709\u7406\u6027\u548C\u826F\u5FC3,\u5E76\u5E94\u4EE5\u5144\u5F1F\u5173\u7CFB\u7684\u7CBE\u795E\u4E92\u76F8\u5BF9\u5F85\u3002", |
| 27 |
"\u4EBA\u4EBA\u751F\u800C\u81EA\u7531\uFE50\u5728\u5C0A\u56B4\u548C\u6B0A\u5229\u4E0A\u4E00\u5F8B\u5E73\u7B49\u3002\u4ED6\u5011\u8CE6\u6709\u7406\u6027\u548C\u826F\u5FC3\uFE50\u4E26\u61C9\u4EE5\u5144\u5F1F\u95DC\u4FC2\u7684\u7CBE\u795E\u4E92\u76F8\u5C0D\u5F85\u3002", |
| 28 |
"\u0623\u0646\u0627 \u0642\u0627\u062F\u0631 \u0639\u0644\u0649 \u0623\u0643\u0644 \u0627\u0644\u0632\u062C\u0627\u062C \u0648 \u0647\u0630\u0627 \u0644\u0627 \u064A\u0624\u0644\u0645\u0646\u064A.", |
| 29 |
"\uD83D\uDE01\uD83D\uDE02\uD83D\uDE03\uD83D\uDE04\uD83D\uDE05\uD83D\uDE06\uD83D\uDE20\uD83D\uDE21\uD83D\uDE22\uD83D\uDE23\uD83D\uDE24\uD83D\uDE25\uD83D\uDE28\uD83D\uDE29\uD83D\uDE2A\uD83D\uDE89\uD83D\uDE8C\uD83D\uDE8F\uD83D\uDE91\uD83D\uDE92\uD83D\uDE93\uD83D\uDE95\uD83D\uDE97\uD83D\uDE99\uD83D\uDE9A\uD83D\uDEA2\uD83D\uDEA4\uD83D\uDEA5\uD83D\uDEA7\uD83D\uDEA8\uD83D\uDEBB\uD83D\uDEBC\uD83D\uDEBD\uD83D\uDEBE\uD83D\uDEC0\uD83C\uDD95\uD83C\uDD96\uD83C\uDD97\uD83C\uDD98\uD83C\uDD99\uD83C\uDD9A\uD83C\uDE01\uD83C\uDE02\uD83C\uDE1A\uD83C\uDE2F\uD83C\uDE39\uD83C\uDE3A\uD83C\uDE50\uD83C\uDE518\u20E39\u20E37\u20E36\u20E31\u20E30" |
| 30 |
}; |
| 31 |
|
| 32 |
private String data; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public Utf8Test() |
| 38 |
{ |
| 39 |
this.data = "Utf8Test pure ASCII"; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public Utf8Test(int indx) |
| 49 |
{ |
| 50 |
this.data = DEFAULT_STRINGS[Math.abs(indx) % DEFAULT_STRINGS.length]; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public Utf8Test(String myinput) |
| 59 |
{ |
| 60 |
if (null == myinput) |
| 61 |
{ |
| 62 |
this.data = "NULL INPUT"; |
| 63 |
} else |
| 64 |
{ |
| 65 |
try |
| 66 |
{ |
| 67 |
int indx = Integer.parseInt(myinput); |
| 68 |
this.data = DEFAULT_STRINGS[Math.abs(indx) % DEFAULT_STRINGS.length]; |
| 69 |
} catch (NumberFormatException nfe) |
| 70 |
{ |
| 71 |
this.data = myinput; |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
public void print_system_info() |
| 77 |
{ |
| 78 |
System.out.println("----------------------------------------------------------------------------------------"); |
| 79 |
System.out.println("JVM: " + System.getProperty("java.vm.name") + ", version: " |
| 80 |
+ System.getProperty("java.version") + " (" + System.getProperty("java.vm.version") + ")"); |
| 81 |
System.out.println("OS: " + System.getProperty("os.name") + "-" + System.getProperty("os.arch") |
| 82 |
+ ", version: " + System.getProperty("os.version")); |
| 83 |
System.out.println("----------------------------------------------------------------------------------------"); |
| 84 |
} |
| 85 |
|
| 86 |
public void print_to_stdout() |
| 87 |
{ |
| 88 |
int nc = (int) this.data.codePoints().count(); |
| 89 |
int nb = this.data.getBytes().length; |
| 90 |
System.out.println(String.format("nc = %3d, nb = %3d: (%s)", nc, nb, this.data)); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public String get() |
| 97 |
{ |
| 98 |
return this.data; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public boolean equalsTo(int indx) |
| 105 |
{ |
| 106 |
return DEFAULT_STRINGS[Math.abs(indx) % DEFAULT_STRINGS.length].equals(this.data); |
| 107 |
} |
| 108 |
|
| 109 |
public static void main(String[] argv) |
| 110 |
{ |
| 111 |
Utf8Test jp; |
| 112 |
|
| 113 |
new Utf8Test().print_system_info(); |
| 114 |
if (0 == argv.length) |
| 115 |
{ |
| 116 |
new Utf8Test().print_to_stdout(); |
| 117 |
for (int i = 0; i < DEFAULT_STRINGS.length; i++) |
| 118 |
{ |
| 119 |
new Utf8Test(i).print_to_stdout(); |
| 120 |
} |
| 121 |
} else |
| 122 |
{ |
| 123 |
new Utf8Test(argv[0]).print_to_stdout(); |
| 124 |
} |
| 125 |
} |
| 126 |
} |