public TextElement(PhpString str, Encoding encoding) { Debug.Assert(str != null); _data = str.ContainsBinaryData ? (object)str.ToBytes(encoding) : str.ToString(encoding); Debug.Assert(IsText ^ IsBinary); }
public void Append(PhpString value) { if (value != null && !value.IsEmpty) { Debug.Assert(value._chunks != null); if (value.IsArrayOfChunks) { AddChunk(value); } else { AddChunk(value._chunks); // if containing only one chunk, add it directly } _flags |= (value._flags & Flags.ContainsBinary); // maintain the binary data flag } }
public void Append(PhpString value) { if (value != null && !value.IsEmpty) { Debug.Assert(value._blob._chunks != null); if (value._blob.IsArrayOfChunks) { AddChunk(value.DeepCopy()); } else { // if containing only one chunk, add it directly var chunk = value._blob._chunks; InplaceDeepCopy(ref chunk); AddChunk(chunk); } _flags |= (value._blob._flags & (Flags.ContainsBinary | Flags.ContainsMutables)); // maintain the binary data flag } }
/// <summary> /// Gets value indicating the variable contains a single-byte string value. /// </summary> public static bool IsBinaryString(this PhpValue value, out PhpString @string) { switch (value.TypeCode) { case PhpTypeCode.MutableString: if (value.MutableStringBlob.ContainsBinaryData) { @string = value.MutableString; return(true); } else { goto default; } case PhpTypeCode.Alias: return(value.Alias.Value.IsBinaryString(out @string)); default: @string = default; return(false); } }
public static stdClass ToObject(PhpString value) => new stdClass(PhpValue.Create(value.DeepCopy()));
/// <summary> /// Converts string to boolean according to PHP. /// </summary> public static bool ToBoolean(PhpString value) => value.ToBoolean();
/// <summary> /// Converts mutable string to byte[]. /// </summary> public static byte[] ToBytes(PhpString value, Context ctx) => value.ToBytes(ctx);
/// <summary> /// Converts mutable string to string. /// </summary> public static string ToString(PhpString value, Context ctx) => value.ToString(ctx);
public override IPhpArray EnsureArray(ref PhpValue me) { var arr = new PhpString(me.String); // me is changed if value is empty if (string.IsNullOrEmpty(me.String)) me = PhpValue.Create(arr); return arr; }
public static PhpValue Create(PhpString value) => new PhpValue(TypeTable.WritableStringTable, value);
/// <summary> /// Gets instance of blob that is not shared. /// </summary> public static Blob AsWritable(PhpString str) => str.EnsureWritable();
public PhpString(PhpString from) { _blob = from._blob.AddRef(); }
public PhpString(PhpString from) : this(from._blob?.AddRef()) { }
public static bool IsMutableString(this PhpValue value, out PhpString @string) => value.IsMutableStringImpl(out @string);
public void Append(PhpString value) => Add(value);
/// <summary> /// Wraps the string into <see cref="PhpValue"/>. /// </summary> public PhpValue AsPhpValue(PhpString str) => str.IsEmpty ? PhpValue.Create(string.Empty) : PhpValue.Create(str._blob);
/// <summary> /// Gets read-only array access to the string. /// For write access, use <see cref="EnsureWritable()"/>. /// </summary> public static Blob AsArray(PhpString str) => str._blob ?? new Blob();
/// <summary> /// Performs conversion of a value to a number. /// </summary> public static PhpNumber ToNumber(PhpString value) => value.ToNumber();
public void Echo(PhpString value) => value.Output(this);
/// <summary> /// Operator that checks the string is default/uninitialized not containing any value. /// </summary> public static bool IsNull(PhpString value) => value.IsDefault;
public override void Accept(PhpString obj) => _output.Append(obj);
public override void Accept(PhpString obj) { _output.Append("'"); _output.Append(obj); _output.Append("'"); }
public void Append(PhpString value) => EnsureWritable().Append(value);
public PhpString Serialize(PhpValue value) { _output = new PhpString(); _indent = 0; // Accept(value); _output.Append(_nl); return _output; }
public static PhpValue Create(PhpString value) => PhpString.AsPhpValue(value);
public override void Accept(PhpString obj) { _output.Append(PhpVariable.TypeNameString); _output.Append($"({obj.Length}) "); _output.Append("\""); _output.Append(obj); _output.Append("\""); }
public virtual void Accept(PhpString obj) { }