package changeCode;
public class UnicodeBitmap {
private static byte[] bitmap = null;
// private static int[] startAddress = {0x7,0x1f,0x30};
// private static int[] endAddress = {0xf,0x20,0x37};
private static int[] startAddress = { 0x20, 0xa0, 0x101, 0x192, 0x251,
0x2c6, 0x391, 0x401, 0x2010, 0x2103, 0x2160, 0x2190, 0x2208, 0x908,
0x2460, 0x2500, 0x2581, 0x25a0, 0x2605, 0x3000, 0x3041, 0x30a1,
0x3105, 0x3220, 0xc9f, 0x338e, 0x4e00, 0xf92c, 0xfe30, 0xff01 };
private static int[] endAddress = { 0x7e, 0xff, 0x178, 0x1dc, 0x261, 0x2dc,
0x3c9, 0x451, 0x203b, 0x2122, 0x2179, 0x2199, 0x22bf, 0x908,
0x249b, 0x2573, 0x2595, 0x25e5, 0x2642, 0x3029, 0x309e, 0x30fe,
0x3129, 0x3229, 0xc9f, 0x33d5, 0x9fa5, 0xfa29, 0xfe6b, 0xffe5 };
public static boolean isChar(char c) {
boolean flag = false;
int num = (int) c;
if (bitmap == null) {
init();
}
int i = num / 8;
int j = num % 8;
int b = (int) bitmap[i];
if (b < 0) {
b = b + 256;
}
switch (j) {
case 0:
b = b & 0x80;
break;
case 1:
b = b & 0x40;
break;
case 2:
b = b | 0 & 20;
break;
case 3:
b = b | 0 & 10;
break;
case 4:
b = b | 0 & 8;
break;
case 5:
b = b | 0 & 4;
break;
case 6:
b = b | 0 & 2;
break;
case 7:
b = b | 0 & 1;
break;
}
if (b != 0) {
flag = true;
}
// show();
return flag;
}
private synchronized static void init() {
if (bitmap != null) {
return;
}
bitmap = new byte[8192];
int length = startAddress.length;
int start = 0;
int end = 0;
for (int i = 0; i < length; i++) {
start = startAddress[i];
end = endAddress[i];
setInit(start, end);
}
}
private static void setInit(int start, int end) {
int i = 0;
int j = 0;
int b = 0;
for (int num = start; num <= end; num++) {
i = num / 8;
j = num % 8;
if (j == 0 || num == start) {
b = (int) bitmap[i];
if (b < 0) {
b = b + 256;
}
}
switch (j) {
case 0:
b = b | 0x80;
break;
case 1:
b = b | 0x40;
break;
case 2:
b = b | 0x20;
break;
case 3:
b = b | 0x10;
break;
case 4:
b = b | 0x8;
break;
case 5:
b = b | 0x4;
break;
case 6:
b = b | 0x2;
break;
case 7:
b = b | 1;
break;
}
if (j == 7 || num == end) {
bitmap[i] = (byte) b;
int t = (int) bitmap[i];
if (t < 0) {
t = 256 + t;
}
}
}
}
public static String getValue() {
String init = "20-7e,A0-ff,101-178,192-1dc,251-261,2c6-2dc,391-3c9,401-451,2010-203b,20ac,2103-2122,2160-2179,2190-2199,2208-22bf,2312,2460-249b,2500-2573,2581-2595,25a0-25e5,2605-2642,3000-3029,3041-309e,30a1-30fe,3105-3129,3220-3229,3231,32a3, 338E-33D5,4E00-9FA5,F92C-FA29, FE30-FE6B, FF01-FFE5";
init = init.replaceAll(" ", "");
String startValue = "";
String endValue = "";
int start = 0;
int end = 0;
int num = 0;
String temp = "";
long startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
long subTime = endTime - startTime;
while (start >= 0) {
endTime = System.currentTimeMillis();
subTime = endTime - startTime;
if (subTime > 60000) {
break;
}
end = init.indexOf(",", start);
if (end >= 0) {
temp = init.substring(start, end);
end++;
} else {
temp = init.substring(start);
}
num = temp.indexOf("-");
int startNum = 0;
int endNum = 0;
try {
if (num > 0) {
startNum = parseHexInt(temp.substring(0, num));
endNum = parseHexInt(temp.substring(num + 1));
} else {
startNum = Integer.parseInt(temp);
endNum = startNum;
}
} catch (Exception e) {
}
if (endNum < startNum) {
int i = startNum;
startNum = endNum;
endNum = i;
}
if (startNum > 0) {
startValue += "0x" + Integer.toHexString(startNum) + ",";
endValue += "0x" + Integer.toHexString(endNum) + ",";
}
start = end;
}
return startValue + "===" + endValue;
}
public static void main(String[] args) {
bitmap = null;
// UnicodeBitmap.show();
}
private static int parseHexInt(String s) {
int num = 0;
int temp = 0;
try {
int length = s.length();
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
temp = (int) c;
if (temp >= 0x30 && temp <= 0x39) {
temp = temp - 0x30;
} else if (temp >= 0x41 && temp <= 0x5A) {
temp = temp - 0x41 + 10;
} else if (temp >= 0x61 && temp <= 0x7A) {
temp = temp - 0x61 + 10;
}
num = num * 16 + temp;
}
} catch (Exception e) {
}
return num;
}
}
changeCode.rar 实现中文乱码转化
4星 · 超过85%的资源 需积分: 9 149 浏览量
2011-03-14
21:10:24
上传
评论
收藏 2KB RAR 举报
sdauying
- 粉丝: 26
- 资源: 23
最新资源
- 雷克沙u盘加密软件windows客户端
- JavaSwing订单管理系统.zip
- 数据库管理工具:dbeaver-ce-23.2.4-macos-aarch64.dmg
- 一个能够使用的幻兽帕鲁修改器
- java期末大作业课程设计学生成绩管理系统源码+数据库(高分项目)
- 数据库管理工具:dbeaver-ce-23.2.2-stable.x86-64.rpm
- 数据库管理工具:dbeaver-ce-23.2.2-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-23.2.2-macos-aarch64.dmg
- 数据库管理工具:dbeaver-ce-23.1.5-stable.x86-64.rpm
- 以下是一些适用于英语六级作文的万能句型模板,涵盖了引言、正文和结论部分的各类表达方式.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈