private static void put(ArrayValue array, Value key, Value value, boolean addSlashes) { if (addSlashes && value.isString()) { value = StringModule.addslashes(value.toStringValue()); } if (key == null) array.put(value); else array.put(key, value); }
public BinaryStream fopen(Env env, StringValue path, StringValue mode, LongValue options) { boolean useIncludePath = (options.toLong() & StreamModule.STREAM_USE_PATH) != 0; Value pathComponent = UrlModule.parse_url(env, path, UrlModule.PHP_URL_PATH); if (!pathComponent.isset()) { log.info(L.l("no path component found in '{0}'", path.toString())); return null; } return ZlibModule.gzopen( env, pathComponent.toStringValue(env), mode.toString(), useIncludePath); }
public void setValue(Interpreter interpreter, final Value targetValue) { if (this.getBaseType().equals(DataTypes.ANY_TYPE) || this.getBaseType().equals(targetValue.getType())) { this.content = targetValue; this.expression = null; } else if (this.getBaseType().equals(DataTypes.TYPE_STRICT_STRING) || this.getBaseType().equals(DataTypes.TYPE_STRING)) { this.content = targetValue.toStringValue(); this.expression = null; } else if (this.getBaseType().equals(DataTypes.TYPE_INT) && targetValue.getType().equals(DataTypes.TYPE_FLOAT)) { this.content = targetValue.toIntValue(); this.expression = null; } else if (this.getBaseType().equals(DataTypes.TYPE_FLOAT) && targetValue.getType().equals(DataTypes.TYPE_INT)) { this.content = targetValue.toFloatValue(); this.expression = null; } else { throw new ScriptException( "Internal error: Cannot assign " + targetValue.getType() + " to " + this.getType()); } }
public void aset(final int index, final Value val, final Interpreter interpreter) { RecordType type = (RecordType) this.type; int size = type.fieldCount(); if (index < 0 || index >= size) { throw interpreter.runtimeException("Internal error: field index out of bounds"); } Value[] array = (Value[]) this.content; if (array[index].getType().equals(val.getType())) { array[index] = val; } else if (array[index].getType().equals(DataTypes.TYPE_STRING)) { array[index] = val.toStringValue(); } else if (array[index].getType().equals(DataTypes.TYPE_INT) && val.getType().equals(DataTypes.TYPE_FLOAT)) { array[index] = val.toIntValue(); } else if (array[index].getType().equals(DataTypes.TYPE_FLOAT) && val.getType().equals(DataTypes.TYPE_INT)) { array[index] = val.toFloatValue(); } else { throw interpreter.runtimeException( "Internal error: Cannot assign " + val.getType() + " to " + array[index].getType()); } }
@Test public void testToStringValue() { assertEquals("-123", mNegativeValue.toStringValue().toString()); assertEquals("0", mZeroValue.toStringValue().toString()); assertEquals("123", mPositiveValue.toStringValue().toString()); }