本文整理汇总了C++中JSArray::put方法的典型用法代码示例。如果您正苦于以下问题:C++ JSArray::put方法的具体用法?C++ JSArray::put怎么用?C++ JSArray::put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSArray
的用法示例。
在下文中一共展示了JSArray::put方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stringProtoFuncSplit
JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
UString s = thisValue.toThisString(exec);
JSValue a0 = args.at(0);
JSValue a1 = args.at(1);
JSArray* result = constructEmptyArray(exec);
unsigned i = 0;
int p0 = 0;
unsigned limit = a1.isUndefined() ? 0xFFFFFFFFU : a1.toUInt32(exec);
if (a0.isObject(&RegExpObject::info)) {
RegExp* reg = asRegExpObject(a0)->regExp();
if (s.isEmpty() && reg->match(s, 0) >= 0) {
// empty string matched by regexp -> empty array
return result;
}
int pos = 0;
while (i != limit && pos < s.size()) {
OwnArrayPtr<int> ovector;
int mpos = reg->match(s, pos, &ovector);
if (mpos < 0)
break;
int mlen = ovector[1] - ovector[0];
pos = mpos + (mlen == 0 ? 1 : mlen);
if (mpos != p0 || mlen) {
result->put(exec, i++, jsSubstring(exec, s, p0, mpos - p0));
p0 = mpos + mlen;
}
for (unsigned si = 1; si <= reg->numSubpatterns(); ++si) {
int spos = ovector[si * 2];
if (spos < 0)
result->put(exec, i++, jsUndefined());
else
result->put(exec, i++, jsSubstring(exec, s, spos, ovector[si * 2 + 1] - spos));
}
}
} else {
UString u2 = a0.toString(exec);
if (u2.isEmpty()) {
if (s.isEmpty()) {
// empty separator matches empty string -> empty array
return result;
}
while (i != limit && p0 < s.size() - 1)
result->put(exec, i++, jsSingleCharacterSubstring(exec, s, p0++));
} else {
int pos;
while (i != limit && (pos = s.find(u2, p0)) >= 0) {
result->put(exec, i++, jsSubstring(exec, s, p0, pos - p0));
p0 = pos + u2.size();
}
}
}
// add remaining string
if (i != limit)
result->put(exec, i++, jsSubstring(exec, s, p0, s.size() - p0));
return result;
}