package javatohtml;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Function {
public static String strIn = null;
private static Matcher m = null;
private static Matcher m1 = null;
public static void quotToEntity() {
strIn = strIn.replaceAll(Const.HTMLENTITY, "$1amp;$2");
strIn = strIn.replaceAll("<", "<").replaceAll(">", ">");
}
public static void addComments() {
m = Const.COMMENTSPT.matcher(strIn);
while (m.find()) {
String s = m.group();
if (s.indexOf("//") == 0) {
addSingleComment(s);
} else if (s.indexOf("/*") == 0) {
if (!s.contains("@")) {
addSingleComment(s);
} else {
addMultilComment(s);
}
} else if (s.indexOf("\"") == 0 || s.indexOf("'") == 0) {
addString(s);
}
}
}
public static void addSingleComment(String str) {
String key = Const.getId();
strIn = strIn.replace(str, key);
str = str.replaceAll(Const.SINGLECOMMENTKEY,
"<span class=\"commentKey\">$1</span>");
str = str.replaceAll(Const.ONESPACE, " *");
str = "<span class=\"singleComment\">" + str + "</span>";
Const.map.put(key, str);
}
public static void addString(String str) {
String key = Const.getId();
strIn = strIn.replace(str, key);
str = "<span class=\"string\">" + str + "</span>";
Const.map.put(key, str);
}
public static void addMultilComment(String str) {
String key = Const.getId();
strIn = strIn.replace(str, key);
str = str.replaceAll(Const.COMMENTHTMLKEY,
"<span class=\"commentHtmlKey\">$1</span>");
str = str.replaceAll(Const.COMMENTBRACESKEY,
"<span class=\"commentBracesKey\">$1</span>");
str = str.replaceAll(Const.COMMENTKEY,
"<span class=\"commentKey\">$1</span>");
str = str.replaceAll(Const.ONESPACE, " *");
str = "<span class=\"multilComment\">" + str + "</span>";
Const.map.put(key, str);
}
public static void addKey() {
strIn = strIn.replaceAll(Const.KEYWORDS,
"<span class=\"key\">$1</span>");
}
public static void addMethodFlag() {
m = Const.ANNOTATION.matcher(strIn);
while (m.find()) {
String str = m.group();
String key = Const.getId();
strIn = strIn.replace(str, key);
str = "<span class=\"annotation\">" + str + "</span>";
Const.map.put(key, str);
}
}
public static void addLocalVar() {
int start = strIn.indexOf("{") + 1;
int end = start + 1;
if (strIn.indexOf("{", start) != -1) {
end = strIn.indexOf("{", start);
}
String golobalStr = strIn.substring(start, end);
StringBuffer sb1 = new StringBuffer();
StringBuffer sb2 = new StringBuffer();
m = Const.GOLOBALVAR_PT.matcher(golobalStr);
while (m.find()) {
String str = m.group().trim();
sb1.append(str + "|");
m1 = Pattern.compile(
"(?s).*\\s+static\\s+[^=]*\\s+" + str + "\\b.*").matcher(
golobalStr);
if (m1.matches()) {
sb2.append(str + "|");
}
}
if (sb2.length() != 0) {
sb2.deleteCharAt(sb2.length() - 1);
private_add(Pattern.compile("(?m)(\\W)(" + sb2.toString()
+ ")(\\W)"), "staticVar");
}
if (sb1.length() != 0) {
sb1.deleteCharAt(sb1.length() - 1);
private_add(Pattern.compile("(?m)(\\W)(" + sb1.toString()
+ ")(\\W)"), "golobalVar");
}
}
public static void addExternStatic() {
private_add(Const.EXTERN_STATICVAR, "staticVar");
// private_add(Const.STATICMETHOD,"staticMethod");
}
public static void format() {
}
private static void private_add(final Pattern p, String className) {
m = p.matcher(strIn);
while (m.find()) {
String str = m.group();
String key = Const.getId();
strIn = strIn.replace(str, m.group(1) + key + m.group(3));
Const.map.put(key, str.replace(str, "<span class=\"" + className
+ "\">" + m.group(2) + "</span>"));
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java2htm(llliiiuuu作品)l.rar (4个子文件)
JavaToHTML.java 2KB
Const.java 2KB
Function.java 4KB
style.css 1KB
共 4 条
- 1
资源评论
- gdmlzq2012-11-30还算可以,对于初学者有一定指导意义
- andrew102410242012-10-29学习了. 感觉不是很好咯
llliiiuuu
- 粉丝: 6
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功