String f_json_encode(CVarRef value, bool loose /* = false */) { VariableSerializer vs(VariableSerializer::JSON, loose ? 1 : 0); String ret = vs.serialize(value, true); if (value.isContagious()) { value.clearContagious(); } return ret; }
Variant Array::append(CVarRef v) { if (!m_px) { SmartPtr<ArrayData>::operator=(ArrayData::Create(v)); } else { if (v.isContagious()) { escalate(); } ArrayData *escalated = m_px->append(v, (m_px->getCount() > 1)); if (escalated) { SmartPtr<ArrayData>::operator=(escalated); } } return v; }
Variant VariableSerializer::serialize(CVarRef v, bool ret) { std::ostringstream oss; if (ret) { m_out = &oss; m_outputLimit = RuntimeOption::SerializationSizeLimit; } else { m_out = &g_context->out(); } m_initPos = m_out->tellp(); m_valueCount = 1; if (m_type == VarDump && v.isContagious()) *m_out << '&'; write(v); if (ret) { return String(oss.str()); // TODO: fix this one extra string copy here } return true; }