void RegExp::newRegExp(QScriptValueImpl *result, const QString &pattern, int flags) { #ifndef QT_NO_REGEXP QRegExp rx = toRegExp(pattern, flags); newRegExp_helper(result, rx, flags); #else engine()->newObject(result, publicPrototype, classInfo()); initRegExp(result, pattern, flags); #endif // QT_NO_REGEXP }
void FlowValue::dump(bool x) const { fflush(stderr); switch (type_) { case FlowValue::VOID: printf("void"); break; case FlowValue::BOOLEAN: printf(toBool() ? "true" : "false"); break; case FlowValue::NUMBER: printf("%lld", toNumber()); break; case FlowValue::REGEXP: printf("/%s/", toRegExp().c_str()); break; case FlowValue::IP: printf("ip(%s)", toIPAddress().str().c_str()); break; case FlowValue::FUNCTION: printf("fnref(0x%p)", reinterpret_cast<void*>(toFunction())); break; case FlowValue::STRING: printf("'%s'", toString()); break; case FlowValue::BUFFER: { long long length = toNumber(); const char *p = toString(); std::string data(p, p + length); printf("'%s'", data.c_str()); break; } case FlowValue::ARRAY: { const FlowArray& p = toArray(); printf("["); for (size_t k = 0, ke = p.size(); k != ke; ++k) { if (k) printf(", "); p[k].dump(false); } printf("]"); break; } default: break; } if (x) printf("\n"); }
QVariant QScriptValueImpl::toVariant() const { switch (m_type) { case QScript::InvalidType: return QVariant(); case QScript::UndefinedType: case QScript::NullType: case QScript::PointerType: case QScript::ReferenceType: break; case QScript::BooleanType: return QVariant(m_bool_value); case QScript::IntegerType: return QVariant(m_int_value); case QScript::NumberType: return QVariant(m_number_value); case QScript::StringType: return QVariant(m_string_value->s); case QScript::LazyStringType: return QVariant(*m_lazy_string_value); case QScript::ObjectType: if (isDate()) return QVariant(toDateTime()); #ifndef QT_NO_REGEXP if (isRegExp()) return QVariant(toRegExp()); #endif if (isVariant()) return variantValue(); #ifndef QT_NO_QOBJECT if (isQObject()) return qVariantFromValue(toQObject()); #endif QScriptValueImpl v = engine()->toPrimitive(*this); if (!v.isObject()) return v.toVariant(); break; } // switch return QVariant(); }
void RegExp::execute(QScriptContextPrivate *context) { #ifndef Q_SCRIPT_NO_EVENT_NOTIFY engine()->notifyFunctionEntry(context); #endif QString P; int F; QScriptValueImpl pattern = context->argument(0); QScriptValueImpl flags = context->argument(1); if (!context->isCalledAsConstructor()) { if ((pattern.classInfo() == classInfo()) && flags.isUndefined()) { context->m_result = pattern; goto Lout; } } if (pattern.classInfo() == classInfo()) { if (!flags.isUndefined()) { context->throwTypeError(QString::fromLatin1("cannot specify flags when creating a copy of a RegExp")); goto Lout; } Instance *data = Instance::get(pattern, classInfo()); #ifndef QT_NO_REGEXP P = data->value.pattern(); #else P = data->pattern; #endif F = data->flags; } else { if (!pattern.isUndefined()) P = pattern.toString(); F = 0; if (!flags.isUndefined()) { QString flagsStr = flags.toString(); for (int i = 0; i < flagsStr.length(); ++i) { int bitflag = flagFromChar(flagsStr.at(i)); if (bitflag == 0) { context->throwError( QScriptContext::SyntaxError, QString::fromUtf8("invalid regular expression flag '%0'") .arg(flagsStr.at(i))); goto Lout; } F |= bitflag; } } } if (context->isCalledAsConstructor()) { QScriptValueImpl &object = context->m_thisObject; object.setClassInfo(classInfo()); object.setPrototype(publicPrototype); #ifndef QT_NO_REGEXP initRegExp(&object, toRegExp(P, F), F); #else initRegExp(&object, P, F); #endif } else { newRegExp(&context->m_result, P, F); } Lout: ; #ifndef Q_SCRIPT_NO_EVENT_NOTIFY engine()->notifyFunctionExit(context); #endif }