本文整理汇总了C++中RegExpConstructor类的典型用法代码示例。如果您正苦于以下问题:C++ RegExpConstructor类的具体用法?C++ RegExpConstructor怎么用?C++ RegExpConstructor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RegExpConstructor类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: match
// Shared implementation used by test and exec.
bool RegExpObject::match(ExecState* exec, const ArgList& args)
{
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
UString input = args.isEmpty() ? regExpConstructor->input() : args.at(0).toString(exec);
if (input.isNull()) {
throwError(exec, GeneralError, "No input to " + toString(exec) + ".");
return false;
}
if (!regExp()->global()) {
int position;
int length;
regExpConstructor->performMatch(d->regExp.get(), input, 0, position, length);
return position >= 0;
}
if (d->lastIndex < 0 || d->lastIndex > input.size()) {
d->lastIndex = 0;
return false;
}
int position;
int length = 0;
regExpConstructor->performMatch(d->regExp.get(), input, static_cast<int>(d->lastIndex), position, length);
if (position < 0) {
d->lastIndex = 0;
return false;
}
d->lastIndex = position + length;
return true;
}
示例2: match
// Shared implementation used by test and exec.
bool RegExpObject::match(ExecState* exec)
{
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
UString input = !exec->argumentCount() ? regExpConstructor->input() : exec->argument(0).toString(exec);
if (input.isNull()) {
throwError(exec, createError(exec, makeString("No input to ", toString(exec), ".")));
return false;
}
if (!regExp()->global()) {
int position;
int length;
regExpConstructor->performMatch(d->regExp.get(), input, 0, position, length);
return position >= 0;
}
if (d->lastIndex < 0 || d->lastIndex > input.length()) {
d->lastIndex = 0;
return false;
}
int position;
int length = 0;
regExpConstructor->performMatch(d->regExp.get(), input, static_cast<int>(d->lastIndex), position, length);
if (position < 0) {
d->lastIndex = 0;
return false;
}
d->lastIndex = position + length;
return true;
}
示例3: visitChildren
void RegExpConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
RegExpConstructor* thisObject = jsCast<RegExpConstructor*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
Base::visitChildren(thisObject, visitor);
thisObject->m_cachedResult.visitChildren(visitor);
}
示例4: stringProtoFuncMatch
JSValue JSC_HOST_CALL stringProtoFuncMatch(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
UString s = thisValue.toThisString(exec);
JSValue a0 = args.at(0);
UString u = s;
RefPtr<RegExp> reg;
RegExpObject* imp = 0;
if (a0.isObject(&RegExpObject::info))
reg = asRegExpObject(a0)->regExp();
else {
/*
* ECMA 15.5.4.12 String.prototype.search (regexp)
* If regexp is not an object whose [[Class]] property is "RegExp", it is
* replaced with the result of the expression new RegExp(regexp).
*/
reg = RegExp::create(&exec->globalData(), a0.toString(exec));
}
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
int pos;
int matchLength;
regExpConstructor->performMatch(reg.get(), u, 0, pos, matchLength);
if (!(reg->global())) {
// case without 'g' flag is handled like RegExp.prototype.exec
if (pos < 0)
return jsNull();
return regExpConstructor->arrayOfMatches(exec);
}
// return array of matches
MarkedArgumentBuffer list;
int lastIndex = 0;
while (pos >= 0) {
list.append(jsSubstring(exec, u, pos, matchLength));
lastIndex = pos;
pos += matchLength == 0 ? 1 : matchLength;
regExpConstructor->performMatch(reg.get(), u, pos, pos, matchLength);
}
if (imp)
imp->setLastIndex(lastIndex);
if (list.isEmpty()) {
// if there are no matches at all, it's important to return
// Null instead of an empty array, because this matches
// other browsers and because Null is a false value.
return jsNull();
}
return constructArray(exec, list);
}
示例5: regExpProtoFuncSearch
EncodedJSValue JSC_HOST_CALL regExpProtoFuncSearch(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
if (!thisValue.inherits(RegExpObject::info()))
return throwVMTypeError(exec);
RegExp* regExp = asRegExpObject(thisValue)->regExp();
JSString* string = exec->argument(0).toString(exec);
String s = string->value(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
MatchResult result = regExpConstructor->performMatch(exec->vm(), regExp, string, s, 0);
return JSValue::encode(result ? jsNumber(result.start) : jsNumber(-1));
}
示例6: match
// Shared implementation used by test and exec.
bool RegExpObject::match(ExecState* exec)
{
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
UString input = exec->argument(0).toString(exec);
JSGlobalData* globalData = &exec->globalData();
if (!regExp()->global()) {
int position;
int length;
regExpConstructor->performMatch(*globalData, d->regExp.get(), input, 0, position, length);
return position >= 0;
}
JSValue jsLastIndex = getLastIndex();
unsigned lastIndex;
if (LIKELY(jsLastIndex.isUInt32())) {
lastIndex = jsLastIndex.asUInt32();
if (lastIndex > input.length()) {
setLastIndex(0);
return false;
}
} else {
double doubleLastIndex = jsLastIndex.toInteger(exec);
if (doubleLastIndex < 0 || doubleLastIndex > input.length()) {
setLastIndex(0);
return false;
}
lastIndex = static_cast<unsigned>(doubleLastIndex);
}
int position;
int length = 0;
regExpConstructor->performMatch(*globalData, d->regExp.get(), input, lastIndex, position, length);
if (position < 0) {
setLastIndex(0);
return false;
}
setLastIndex(position + length);
return true;
}
示例7: stringProtoFuncSearch
JSValue JSC_HOST_CALL stringProtoFuncSearch(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
UString s = thisValue.toThisString(exec);
JSValue a0 = args.at(0);
UString u = s;
RefPtr<RegExp> reg;
if (a0.isObject(&RegExpObject::info))
reg = asRegExpObject(a0)->regExp();
else {
/*
* ECMA 15.5.4.12 String.prototype.search (regexp)
* If regexp is not an object whose [[Class]] property is "RegExp", it is
* replaced with the result of the expression new RegExp(regexp).
*/
reg = RegExp::create(&exec->globalData(), a0.toString(exec));
}
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
int pos;
int matchLength;
regExpConstructor->performMatch(reg.get(), u, 0, pos, matchLength);
return jsNumber(exec, pos);
}
示例8: stringProtoFuncSearch
JSValue* stringProtoFuncSearch(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
UString s = thisValue->toThisString(exec);
JSValue* a0 = args.at(exec, 0);
UString u = s;
RefPtr<RegExp> reg;
if (a0->isObject() && static_cast<JSObject*>(a0)->inherits(&RegExpObject::info))
reg = static_cast<RegExpObject*>(a0)->regExp();
else {
/*
* ECMA 15.5.4.12 String.prototype.search (regexp)
* If regexp is not an object whose [[Class]] property is "RegExp", it is
* replaced with the result of the expression new RegExp(regexp).
*/
reg = RegExp::create(exec, a0->toString(exec));
}
RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
int pos;
int matchLength;
regExpObj->performMatch(reg.get(), u, 0, pos, matchLength);
return jsNumber(exec, pos);
}
示例9: match
bool RegExpObject::match(ExecState* exec, const ArgList& args)
{
RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
UString input;
if (!args.isEmpty())
input = args.at(exec, 0)->toString(exec);
else {
input = regExpObj->input();
if (input.isNull()) {
throwError(exec, GeneralError, "No input.");
return false;
}
}
bool global = get(exec, exec->propertyNames().global)->toBoolean(exec);
int lastIndex = 0;
if (global) {
if (d->lastIndex < 0 || d->lastIndex > input.size()) {
d->lastIndex = 0;
return false;
}
lastIndex = static_cast<int>(d->lastIndex);
}
int foundIndex;
int foundLength;
regExpObj->performMatch(d->regExp.get(), input, lastIndex, foundIndex, foundLength);
if (global) {
lastIndex = foundIndex < 0 ? 0 : foundIndex + foundLength;
d->lastIndex = lastIndex;
}
return foundIndex >= 0;
}
示例10: stringProtoFuncReplace
JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
JSString* sourceVal = thisValue.toThisJSString(exec);
const UString& source = sourceVal->value();
JSValue pattern = args.at(0);
JSValue replacement = args.at(1);
UString replacementString;
CallData callData;
CallType callType = replacement.getCallData(callData);
if (callType == CallTypeNone)
replacementString = replacement.toString(exec);
if (pattern.isObject(&RegExpObject::info)) {
RegExp* reg = asRegExpObject(pattern)->regExp();
bool global = reg->global();
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
int lastIndex = 0;
int startPosition = 0;
Vector<UString::Range, 16> sourceRanges;
Vector<UString, 16> replacements;
// This is either a loop (if global is set) or a one-way (if not).
if (global && callType == CallTypeJS) {
// reg->numSubpatterns() + 1 for pattern args, + 2 for match start and sourceValue
int argCount = reg->numSubpatterns() + 1 + 2;
JSFunction* func = asFunction(replacement);
CachedCall cachedCall(exec, func, argCount, exec->exceptionSlot());
if (exec->hadException())
return jsNull();
while (true) {
int matchIndex;
int matchLen;
int* ovector;
regExpConstructor->performMatch(reg, source, startPosition, matchIndex, matchLen, &ovector);
if (matchIndex < 0)
break;
sourceRanges.append(UString::Range(lastIndex, matchIndex - lastIndex));
int completeMatchStart = ovector[0];
unsigned i = 0;
for (; i < reg->numSubpatterns() + 1; ++i) {
int matchStart = ovector[i * 2];
int matchLen = ovector[i * 2 + 1] - matchStart;
if (matchStart < 0)
cachedCall.setArgument(i, jsUndefined());
else
cachedCall.setArgument(i, jsSubstring(exec, source, matchStart, matchLen));
}
cachedCall.setArgument(i++, jsNumber(exec, completeMatchStart));
cachedCall.setArgument(i++, sourceVal);
cachedCall.setThis(exec->globalThisValue());
replacements.append(cachedCall.call().toString(cachedCall.newCallFrame()));
if (exec->hadException())
break;
lastIndex = matchIndex + matchLen;
startPosition = lastIndex;
// special case of empty match
if (matchLen == 0) {
startPosition++;
if (startPosition > source.size())
break;
}
}
} else {
do {
int matchIndex;
int matchLen;
int* ovector;
regExpConstructor->performMatch(reg, source, startPosition, matchIndex, matchLen, &ovector);
if (matchIndex < 0)
break;
sourceRanges.append(UString::Range(lastIndex, matchIndex - lastIndex));
if (callType != CallTypeNone) {
int completeMatchStart = ovector[0];
MarkedArgumentBuffer args;
for (unsigned i = 0; i < reg->numSubpatterns() + 1; ++i) {
int matchStart = ovector[i * 2];
int matchLen = ovector[i * 2 + 1] - matchStart;
if (matchStart < 0)
args.append(jsUndefined());
else
args.append(jsSubstring(exec, source, matchStart, matchLen));
}
args.append(jsNumber(exec, completeMatchStart));
//.........这里部分代码省略.........
示例11: ASSERT
JSValue RegExpObject::matchGlobal(ExecState* exec, JSGlobalObject* globalObject, JSString* string)
{
RegExp* regExp = this->regExp();
ASSERT(regExp->global());
VM* vm = &globalObject->vm();
setLastIndex(exec, 0);
if (exec->hadException())
return jsUndefined();
String s = string->value(exec);
RegExpConstructor* regExpConstructor = globalObject->regExpConstructor();
MatchResult result = regExpConstructor->performMatch(*vm, regExp, string, s, 0);
// return array of matches
MarkedArgumentBuffer list;
// We defend ourselves from crazy.
const size_t maximumReasonableMatchSize = 1000000000;
if (regExp->unicode()) {
unsigned stringLength = s.length();
while (result) {
if (list.size() > maximumReasonableMatchSize) {
throwOutOfMemoryError(exec);
return jsUndefined();
}
size_t end = result.end;
size_t length = end - result.start;
list.append(jsSubstring(exec, s, result.start, length));
if (!length)
end = advanceStringUnicode(s, stringLength, end);
result = regExpConstructor->performMatch(*vm, regExp, string, s, end);
}
} else {
while (result) {
if (list.size() > maximumReasonableMatchSize) {
throwOutOfMemoryError(exec);
return jsUndefined();
}
size_t end = result.end;
size_t length = end - result.start;
list.append(jsSubstring(exec, s, result.start, length));
if (!length)
++end;
result = regExpConstructor->performMatch(*vm, regExp, string, s, end);
}
}
if (list.isEmpty()) {
// if there are no matches at all, it's important to return
// Null instead of an empty array, because this matches
// other browsers and because Null is a false value.
return jsNull();
}
return constructArray(exec, static_cast<ArrayAllocationProfile*>(0), list);
}
示例12: stringProtoFuncReplace
JSValue* stringProtoFuncReplace(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
JSString* sourceVal = thisValue->toThisJSString(exec);
const UString& source = sourceVal->value();
JSValue* pattern = args.at(exec, 0);
JSValue* replacement = args.at(exec, 1);
UString replacementString;
CallData callData;
CallType callType = replacement->getCallData(callData);
if (callType == CallTypeNone)
replacementString = replacement->toString(exec);
if (pattern->isObject(&RegExpObject::info)) {
RegExp* reg = static_cast<RegExpObject*>(pattern)->regExp();
bool global = reg->global();
RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
int lastIndex = 0;
int startPosition = 0;
Vector<UString::Range, 16> sourceRanges;
Vector<UString, 16> replacements;
// This is either a loop (if global is set) or a one-way (if not).
do {
int matchIndex;
int matchLen;
int* ovector;
regExpObj->performMatch(reg, source, startPosition, matchIndex, matchLen, &ovector);
if (matchIndex < 0)
break;
sourceRanges.append(UString::Range(lastIndex, matchIndex - lastIndex));
if (callType != CallTypeNone) {
int completeMatchStart = ovector[0];
ArgList args;
for (unsigned i = 0; i < reg->numSubpatterns() + 1; ++i) {
int matchStart = ovector[i * 2];
int matchLen = ovector[i * 2 + 1] - matchStart;
if (matchStart < 0)
args.append(jsUndefined());
else
args.append(jsSubstring(exec, source, matchStart, matchLen));
}
args.append(jsNumber(exec, completeMatchStart));
args.append(sourceVal);
replacements.append(call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec));
} else
replacements.append(substituteBackreferences(replacementString, source, ovector, reg));
lastIndex = matchIndex + matchLen;
startPosition = lastIndex;
// special case of empty match
if (matchLen == 0) {
startPosition++;
if (startPosition > source.size())
break;
}
} while (global);
if (lastIndex < source.size())
sourceRanges.append(UString::Range(lastIndex, source.size() - lastIndex));
UString result = source.spliceSubstringsWithSeparators(sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size());
if (result == source)
return sourceVal;
return jsString(exec, result);
}
// First arg is a string
UString patternString = pattern->toString(exec);
int matchPos = source.find(patternString);
int matchLen = patternString.size();
// Do the replacement
if (matchPos == -1)
return sourceVal;
if (callType != CallTypeNone) {
ArgList args;
args.append(jsSubstring(exec, source, matchPos, matchLen));
args.append(jsNumber(exec, matchPos));
args.append(sourceVal);
replacementString = call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec);
}
return jsString(exec, source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
}