* added removeTrailingBraces() to ExpressionFormat scriptcontext (e.g. "Doctor Who (2005)" -> "Doctor Who")

* removed double/integer conversion hack
This commit is contained in:
Reinhard Pointner 2009-05-14 12:30:06 +00:00
parent 92fedf2ad1
commit 216dd4d383
3 changed files with 17 additions and 10 deletions

View File

@ -109,9 +109,8 @@ public class AssociativeScriptObject implements Scriptable {
/**
* Returns the string value of this object.
*/
@SuppressWarnings("unchecked")
@Override
public Object getDefaultValue(Class typeHint) {
public Object getDefaultValue(Class<?> typeHint) {
return this.toString();
}

View File

@ -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) {
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) {
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*\([^\)]*\)$/, "");
}

View File

@ -18,7 +18,6 @@ import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
import java.text.FieldPosition;
import java.text.Format;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.List;
@ -126,11 +125,6 @@ public class ExpressionFormat extends Format {
Object value = ((CompiledScript) snipped).eval(context);
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);
}
} catch (ScriptException e) {