本文整理汇总了C++中JSString::getCharsAndLength方法的典型用法代码示例。如果您正苦于以下问题:C++ JSString::getCharsAndLength方法的具体用法?C++ JSString::getCharsAndLength怎么用?C++ JSString::getCharsAndLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSString
的用法示例。
在下文中一共展示了JSString::getCharsAndLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reviver
JSBool
js_json_parse(JSContext *cx, uintN argc, Value *vp)
{
JSString *s = NULL;
Value *argv = vp + 2;
AutoValueRooter reviver(cx);
if (!JS_ConvertArguments(cx, argc, Jsvalify(argv), "S / v", &s, reviver.addr()))
return JS_FALSE;
JSONParser *jp = js_BeginJSONParse(cx, vp);
JSBool ok = jp != NULL;
if (ok) {
const jschar *chars;
size_t length;
s->getCharsAndLength(chars, length);
ok = js_ConsumeJSONText(cx, jp, chars, length);
ok &= !!js_FinishJSONParse(cx, jp, reviver.value());
}
return ok;
}
示例2: tvr
JSBool
js_json_parse(JSContext *cx, uintN argc, jsval *vp)
{
JSString *s = NULL;
jsval *argv = vp + 2;
jsval reviver = JSVAL_NULL;
JSAutoTempValueRooter tvr(cx, 1, &reviver);
if (!JS_ConvertArguments(cx, argc, argv, "S / v", &s, &reviver))
return JS_FALSE;
JSONParser *jp = js_BeginJSONParse(cx, vp);
JSBool ok = jp != NULL;
if (ok) {
const jschar *chars;
size_t length;
s->getCharsAndLength(chars, length);
ok = js_ConsumeJSONText(cx, jp, chars, length);
ok &= js_FinishJSONParse(cx, jp, reviver);
}
return ok;
}
示例3: detect
static JSBool
JO(JSContext *cx, Value *vp, StringifyContext *scx)
{
JSObject *obj = &vp->toObject();
CycleDetector detect(scx, obj);
if (!detect.init(cx))
return JS_FALSE;
if (!scx->cb.append('{'))
return JS_FALSE;
Value vec[3] = { NullValue(), NullValue(), NullValue() };
AutoArrayRooter tvr(cx, JS_ARRAY_LENGTH(vec), vec);
Value& outputValue = vec[0];
Value& whitelistElement = vec[1];
AutoIdRooter idr(cx);
jsid& id = *idr.addr();
Value *keySource = vp;
bool usingWhitelist = false;
// if the replacer is an array, we use the keys from it
if (scx->replacer && JS_IsArrayObject(cx, scx->replacer)) {
usingWhitelist = true;
vec[2].setObject(*scx->replacer);
keySource = &vec[2];
}
JSBool memberWritten = JS_FALSE;
AutoIdVector props(cx);
if (!GetPropertyNames(cx, &keySource->toObject(), JSITER_OWNONLY, &props))
return JS_FALSE;
for (size_t i = 0, len = props.length(); i < len; i++) {
outputValue.setUndefined();
if (!usingWhitelist) {
if (!js_ValueToStringId(cx, IdToValue(props[i]), &id))
return JS_FALSE;
} else {
// skip non-index properties
jsuint index = 0;
if (!js_IdIsIndex(props[i], &index))
continue;
if (!scx->replacer->getProperty(cx, props[i], &whitelistElement))
return JS_FALSE;
if (!js_ValueToStringId(cx, whitelistElement, &id))
return JS_FALSE;
}
// We should have a string id by this point. Either from
// JS_Enumerate's id array, or by converting an element
// of the whitelist.
JS_ASSERT(JSID_IS_ATOM(id));
if (!JS_GetPropertyById(cx, obj, id, Jsvalify(&outputValue)))
return JS_FALSE;
if (outputValue.isObjectOrNull() && !js_TryJSON(cx, &outputValue))
return JS_FALSE;
// call this here, so we don't write out keys if the replacer function
// wants to elide the value.
if (!CallReplacerFunction(cx, id, obj, scx, &outputValue))
return JS_FALSE;
JSType type = JS_TypeOfValue(cx, Jsvalify(outputValue));
// elide undefined values and functions and XML
if (outputValue.isUndefined() || type == JSTYPE_FUNCTION || type == JSTYPE_XML)
continue;
// output a comma unless this is the first member to write
if (memberWritten && !scx->cb.append(','))
return JS_FALSE;
memberWritten = JS_TRUE;
if (!WriteIndent(cx, scx, scx->depth))
return JS_FALSE;
// Be careful below, this string is weakly rooted
JSString *s = js_ValueToString(cx, IdToValue(id));
if (!s)
return JS_FALSE;
const jschar *chars;
size_t length;
s->getCharsAndLength(chars, length);
if (!write_string(cx, scx->cb, chars, length) ||
!scx->cb.append(':') ||
!(scx->gap.empty() || scx->cb.append(' ')) ||
!Str(cx, id, obj, scx, &outputValue, true)) {
return JS_FALSE;
}
}
if (memberWritten && !WriteIndent(cx, scx, scx->depth - 1))
//.........这里部分代码省略.........