📄 bnftool.java
字号:
}
ret = mType.replaceAll("");
return ret;
}
public static String findAttrs(String input, List attrs, String parent, IdlFile fn) {
String ret = "";
// group 1--readonly, group 2--type, group 3--name
String attr_dcl = "(?>(readonly)\\s+)?attribute\\s+" + "(" + param_type_spec + ")" + "\\s+"
+ identifier_catch + "\\s*;";
Pattern pAttr = Pattern.compile(attr_dcl, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mAttr = pAttr.matcher(input);
while (mAttr.find()) {
String one = mAttr.group(0);
String name = mAttr.group(3);
String type = mAttr.group(2);
String readonly = mAttr.group(1);
// ready to create the node
IdlAttribute an = new IdlAttribute();
an.sName = name;
an.cName = parent + "::" + name;
an.content = one;
an.fn = fn;
an.type = type.replaceAll("\\s+", "").replaceAll("::_", "::");
if (readonly == null) {
an.readonly = false;
// Support attriute in inerface (Set Attribute)
IdlOperation set = new IdlOperation();
set.sName = "_set_" + name;
set.cName = parent + "::_set_" + name;
set.content = "pseudo set operation \" " + one + "\"";
set.fn = fn;
set.oneway = false;
set.rtype = "void";
set.paras = "in " + an.type + " " + name;
set.raises = "";
set.context = "";
attrs.add(set);
// put the node in the map
Warehouse.cname2node.put(set.cName, set);
} else {
an.readonly = true;
}
attrs.add(an);
// put the node in the map
Warehouse.cname2node.put(an.cName, an);
// Support attriute in inerface (Get Attribute)
IdlOperation get = new IdlOperation();
get.sName = "_get_" + name;
get.cName = parent + "::_get_" + name;
get.content = "pseudo get operation \" " + one + "\"";
get.fn = fn;
get.oneway = false;
get.rtype = an.type;
get.paras = "";
get.raises = "";
get.context = "";
attrs.add(get);
// put the node in the map
Warehouse.cname2node.put(get.cName, get);
}
ret = mAttr.replaceAll("");
return ret;
}
public static String findConst(String input, List consts, String parent, IdlFile fn) {
String ret = "";
// group 1--type, group 2--name, group 3--val
String const_dcl = "const\\s+" + "(" + const_type + ")" + "\\s+" + identifier_catch
+ "\\s*=(" + "[^;=]*" + ")\\s*;";
Pattern pConst = Pattern.compile(const_dcl, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mConst = pConst.matcher(input);
while (mConst.find()) {
String one = mConst.group(0);
String type = mConst.group(1);
String name = mConst.group(2);
String val = mConst.group(3);
// ready to create the node
IdlConstant cn = new IdlConstant();
cn.sName = name;
cn.cName = parent + "::" + name;
cn.content = one;
cn.fn = fn;
cn.type = type.replaceAll("\\s+", "").replaceAll("::_", "::");
cn.val = val;
consts.add(cn);
// put the node in the map
Warehouse.cname2node.put(cn.cName, cn);
}
ret = mConst.replaceAll("");
return ret;
}
public static String findInterface(String input, List infs, String parent, IdlFile fn) {
String ret = "";
// group 2-- inheritedInterface
String interface_inheritance_spec = ":\\s*" + "(" + scoped_name + "(?>\\s*,\\s*"
+ scoped_name + ")*" + ")";
// String interface_inheritance_spec = ":\\s*" + "(" +
// "[^\\{\\}]*" +
// ")";
// group 1--name
String interface_header = "(?>(?>abstract)|(?>local)\\s+)?interface\\s+" + identifier_catch
+ "\\s*(?>" + interface_inheritance_spec + ")?";
// group 4--name
String forward_dcl = "(?>(?>abstract)|(?>local)\\s+)?interface\\s+" + identifier_catch
+ "\\s*;";
// group 3--value
String interface_dcl = interface_header + "\\s*\\{" + "(" + nestingPair(4, '{', '}') + ")"
+ "\\}\\s*;";
String interf = "(?>" + interface_dcl + ")|(?>" + forward_dcl + ")";
Pattern pInf = Pattern.compile(interf, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mInf = pInf.matcher(input);
String test = "";
while (mInf.find()) {
test = mInf.group(1);
if (test == null) {
test = mInf.group(4);
}
String one = mInf.group(0);
String name = test;
String val = mInf.group(3);
if (val == null) {
val = "";
}
String inherit = mInf.group(2);
if (inherit == null) {
inherit = "";
}
// ready to create the node
IdlInterface in = new IdlInterface();
in.sName = name;
in.cName = parent + "::" + name;
in.content = one;
in.val = val;
in.inherit = inherit.replaceAll("\\s+", "").replaceAll("::_", "::");
in.fn = fn;
infs.add(in);
// put the node in the map
Warehouse.cname2node.put(in.cName, in);
}
ret = mInf.replaceAll("");
return ret;
}
public static String findModule(String input, List mods, String parent, IdlFile fn) {
String ret = "";
// group 1--name, group 2--value
Pattern pMod = Pattern.compile("module\\s+(\\w+)\\s*\\{(" + nestingPair(10, '{', '}')
+ ")\\}\\s*;", Pattern.DOTALL + Pattern.MULTILINE);
Matcher mMod = pMod.matcher(input);
while (mMod.find()) {
String one = mMod.group(0);
String name = mMod.group(1);
String val = mMod.group(2);
// ready to create the module node
IdlModule mn = new IdlModule();
mn.sName = name;
mn.cName = parent + "::" + name;
mn.content = one;
mn.val = val;
mn.fn = fn;
mods.add(mn);
// put the node in the map
Warehouse.cname2node.put(mn.cName, mn);
// System.out.println(one);
}
ret = mMod.replaceAll("");
return ret;
}
public static String removeComments(String input) {
String ret;
Pattern pComment = Pattern.compile("(//.*?$)|(/\\*.*?\\*/)", Pattern.DOTALL
+ Pattern.MULTILINE);
Matcher mGet = pComment.matcher(input);
ret = mGet.replaceAll("");
return ret;
}
public static String changeComments(String input) {
StringBuffer sb = new StringBuffer();
Pattern pComment = Pattern.compile("(//.*?$)|(/\\*.*?\\*/)", Pattern.DOTALL
+ Pattern.MULTILINE);
Matcher mGet = pComment.matcher(input);
int start = 0;
while (mGet.find()) {
int i_s = mGet.start();
int i_e = mGet.end();
sb.append(input.substring(start, i_s));
sb.append(fromNchar(' ', i_e - i_s));
start = i_e;
}
sb.append(input.substring(start));
return sb.toString();
}
private static String fromNchar(char c, int num) {
String str;
if (num <= 0)
return "";
char[] ca = new char[num];
for (int i = 0; i < ca.length; i++) {
ca[i] = c;
}
str = new String(ca);
return str;
}
public static int parsePositiveIntConst(String input) {
int ret = 0;
if (input == null)
return ret;
try {
ret = Integer.parseInt(input.trim());
} catch (Exception e) {
try {
ret = Integer.parseInt(Calculator.calc(input, true));
} catch (Exception ex) {
LoggerTool.logStackTrace(e, LOG);
ret = 0;
}
}
return ret;
}
private static String nestingPair(int level, char b, char e) {
String ret = "";
if (level <= 0) { return ret; }
String common = "(?>[^" + b + e + "]*(?>\\\\" + b + "888_888" + "\\\\" + e + ")*[^" + b + e
+ "]*)*";
String core = "[^" + b + e + "]*";
String replace = "(?>[^" + b + e + "]*(?>\\" + b + "888_888" + "\\" + e + ")*[^" + b + e
+ "]*)*";
for (int i = 0; i < level - 1; i++) {
// System.out.println(replace);
replace = replace.replaceFirst("888_888", common);
}
// System.out.println(replace);
ret = replace.replaceAll("888_888", core);
return ret;
}
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -