提交 71317439 authored 作者: Thomas Mueller's avatar Thomas Mueller

Re-implemented translate.

上级 a56021d5
...@@ -571,7 +571,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -571,7 +571,7 @@ public class Function extends Expression implements FunctionCall {
} }
private static strictfp double log10(double value) { private static strictfp double log10(double value) {
return roundmagic(StrictMath.log(value) / StrictMath.log(10)); return roundMagic(StrictMath.log(value) / StrictMath.log(10));
} }
@Override @Override
...@@ -648,7 +648,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -648,7 +648,7 @@ public class Function extends Expression implements FunctionCall {
break; break;
} }
case ROUNDMAGIC: case ROUNDMAGIC:
result = ValueDouble.get(roundmagic(v0.getDouble())); result = ValueDouble.get(roundMagic(v0.getDouble()));
break; break;
case SIGN: case SIGN:
result = ValueInt.get(v0.getSignum()); result = ValueInt.get(v0.getSignum());
...@@ -1920,41 +1920,39 @@ public class Function extends Expression implements FunctionCall { ...@@ -1920,41 +1920,39 @@ public class Function extends Expression implements FunctionCall {
return e; return e;
} }
/** This is the org.apache.commons.lang3.StringUtils private static String translate(String original, String findChars,
* #replaceChars(String, String, String) implementation String replaceChars) {
*/ if (StringUtils.isNullOrEmpty(original) ||
private static String translate(String str, String searchChars, String replaceChars) { StringUtils.isNullOrEmpty(findChars)) {
return original;
if (str == null || str.length() == 0 || searchChars == null || searchChars.length() == 0) { }
return str; // if it stays null, then no replacements have been made
} StringBuilder buff = null;
if (replaceChars == null) { // if shorter than findChars, then characters are removed
// empty // (if null, we don't access replaceChars at all)
replaceChars = ""; int replaceSize = replaceChars == null ? 0 : replaceChars.length();
} for (int i = 0, size = original.length(); i < size; i++) {
boolean modified = false; char ch = original.charAt(i);
int replaceCharsLength = replaceChars.length(); int index = findChars.indexOf(ch);
int strLength = str.length();
StringBuilder buf = new StringBuilder(strLength);
for (int i = 0; i < strLength; i++) {
char ch = str.charAt(i);
int index = searchChars.indexOf(ch);
if (index >= 0) { if (index >= 0) {
modified = true; if (buff == null) {
if (index < replaceCharsLength) { buff = new StringBuilder(size);
buf.append(replaceChars.charAt(index)); if (i > 0) {
buff.append(original.substring(0, i));
}
}
if (index < replaceSize) {
ch = replaceChars.charAt(index);
} }
} else {
buf.append(ch);
} }
if (buff != null) {
buff.append(ch);
} }
if (modified) {
return buf.toString();
} }
return str; return buff == null ? original : buff.toString();
} }
private static double roundmagic(double d) { private static double roundMagic(double d) {
if ((d < 0.0000000000001) && (d > -0.0000000000001)) { if ((d < 0.0000000000001) && (d > -0.0000000000001)) {
return 0.0; return 0.0;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论