* added removeTrailingBraces() to ExpressionFormat scriptcontext (e.g. "Doctor Who (2005)" -> "Doctor Who")
* removed double/integer conversion hack
This commit is contained in:
parent
92fedf2ad1
commit
216dd4d383
|
@ -109,9 +109,8 @@ public class AssociativeScriptObject implements Scriptable {
|
||||||
/**
|
/**
|
||||||
* Returns the string value of this object.
|
* Returns the string value of this object.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public Object getDefaultValue(Class typeHint) {
|
public Object getDefaultValue(Class<?> typeHint) {
|
||||||
return this.toString();
|
return this.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Convenience method to pad strings or numbers with given characters ('0' by default)
|
* Pad strings or numbers with given characters ('0' by default).
|
||||||
|
*
|
||||||
|
* e.g. "1" -> "01"
|
||||||
*/
|
*/
|
||||||
String.prototype.pad = Number.prototype.pad = function(length, padding) {
|
String.prototype.pad = Number.prototype.pad = function(length, padding) {
|
||||||
var s = this.toString();
|
var s = this.toString();
|
||||||
|
@ -16,8 +18,20 @@ String.prototype.pad = Number.prototype.pad = function(length, padding) {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to replace space characters with a given characters
|
* Replace space characters with a given characters.
|
||||||
|
*
|
||||||
|
* e.g. "Doctor Who" -> "Doctor_Who"
|
||||||
*/
|
*/
|
||||||
String.prototype.space = function(replacement) {
|
String.prototype.space = function(replacement) {
|
||||||
return this.replace(/\s/g, replacement);
|
return this.replace(/\s/g, replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove trailing parenthesis including any leading whitespace.
|
||||||
|
*
|
||||||
|
* e.g. "Doctor Who (2005)" -> "Doctor Who"
|
||||||
|
*/
|
||||||
|
String.prototype.removeTrailingBraces = function() {
|
||||||
|
return this.replace(/\s*\([^\)]*\)$/, "");
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import java.security.PrivilegedExceptionAction;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
import java.text.FieldPosition;
|
import java.text.FieldPosition;
|
||||||
import java.text.Format;
|
import java.text.Format;
|
||||||
import java.text.NumberFormat;
|
|
||||||
import java.text.ParsePosition;
|
import java.text.ParsePosition;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -126,11 +125,6 @@ public class ExpressionFormat extends Format {
|
||||||
Object value = ((CompiledScript) snipped).eval(context);
|
Object value = ((CompiledScript) snipped).eval(context);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if (value instanceof Double && value.equals(Math.floor((Double) value))) {
|
|
||||||
// value is really an integer, not a decimal (number literals -1, 0 and 1 are interpreted as decimal by rhino)
|
|
||||||
value = NumberFormat.getIntegerInstance().format(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(value);
|
sb.append(value);
|
||||||
}
|
}
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
|
|
Loading…
Reference in New Issue