本文整理汇总了C++中String16::substring方法的典型用法代码示例。如果您正苦于以下问题:C++ String16::substring方法的具体用法?C++ String16::substring怎么用?C++ String16::substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String16
的用法示例。
在下文中一共展示了String16::substring方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleScope
int V8Regex::match(const String16& string, int startFrom, int* matchLength) const
{
if (matchLength)
*matchLength = 0;
if (m_regex.IsEmpty() || string.isEmpty())
return -1;
// v8 strings are limited to int.
if (string.length() > INT_MAX)
return -1;
v8::Isolate* isolate = m_debugger->isolate();
v8::HandleScope handleScope(isolate);
v8::Local<v8::Context> context = m_debugger->regexContext();
v8::MicrotasksScope microtasks(isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::TryCatch tryCatch(isolate);
v8::Local<v8::RegExp> regex = m_regex.Get(isolate);
v8::Local<v8::Value> exec;
if (!regex->Get(context, toV8StringInternalized(isolate, "exec")).ToLocal(&exec))
return -1;
v8::Local<v8::Value> argv[] = { toV8String(isolate, string.substring(startFrom)) };
v8::Local<v8::Value> returnValue;
if (!exec.As<v8::Function>()->Call(context, regex, WTF_ARRAY_LENGTH(argv), argv).ToLocal(&returnValue))
return -1;
// RegExp#exec returns null if there's no match, otherwise it returns an
// Array of strings with the first being the whole match string and others
// being subgroups. The Array also has some random properties tacked on like
// "index" which is the offset of the match.
//
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp/exec
ASSERT(!returnValue.IsEmpty());
if (!returnValue->IsArray())
return -1;
v8::Local<v8::Array> result = returnValue.As<v8::Array>();
v8::Local<v8::Value> matchOffset;
if (!result->Get(context, toV8StringInternalized(isolate, "index")).ToLocal(&matchOffset))
return -1;
if (matchLength) {
v8::Local<v8::Value> match;
if (!result->Get(context, 0).ToLocal(&match))
return -1;
*matchLength = match.As<v8::String>()->Length();
}
return matchOffset.As<v8::Int32>()->Value() + startFrom;
}