本文整理汇总了C++中mozilla::Range类的典型用法代码示例。如果您正苦于以下问题:C++ Range类的具体用法?C++ Range怎么用?C++ Range使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Range类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EvalStringMightBeJSON
static bool
EvalStringMightBeJSON(const mozilla::Range<const CharT> chars)
{
// If the eval string starts with '(' or '[' and ends with ')' or ']', it may be JSON.
// Try the JSON parser first because it's much faster. If the eval string
// isn't JSON, JSON parsing will probably fail quickly, so little time
// will be lost.
size_t length = chars.length();
if (length > 2 &&
((chars[0] == '[' && chars[length - 1] == ']') ||
(chars[0] == '(' && chars[length - 1] == ')')))
{
// Remarkably, JavaScript syntax is not a superset of JSON syntax:
// strings in JavaScript cannot contain the Unicode line and paragraph
// terminator characters U+2028 and U+2029, but strings in JSON can.
// Rather than force the JSON parser to handle this quirk when used by
// eval, we simply don't use the JSON parser when either character
// appears in the provided string. See bug 657367.
if (sizeof(CharT) > 1) {
for (RangedPtr<const CharT> cp = chars.start() + 1, end = chars.end() - 1;
cp < end;
cp++)
{
char16_t c = *cp;
if (c == 0x2028 || c == 0x2029)
return false;
}
}
return true;
}
return false;
}
示例2: ArgsAndBodySubstring
static bool
ArgsAndBodySubstring(mozilla::Range<const CharT> chars, size_t *outOffset, size_t *outLen)
{
const CharT *const start = chars.start().get();
const CharT *const end = chars.end().get();
const CharT *s = start;
uint8_t parenChomp = 0;
if (s[0] == '(') {
s++;
parenChomp = 1;
}
/* Try to jump "function" keyword. */
s = js_strchr_limit(s, ' ', end);
if (!s)
return false;
/*
* Jump over the function's name: it can't be encoded as part
* of an ECMA getter or setter.
*/
s = js_strchr_limit(s, '(', end);
if (!s)
return false;
if (*s == ' ')
s++;
*outOffset = s - start;
*outLen = end - s - parenChomp;
MOZ_ASSERT(*outOffset + *outLen <= chars.length());
return true;
}
示例3: ParseEvalStringAsJSON
static EvalJSONResult
ParseEvalStringAsJSON(JSContext *cx, const mozilla::Range<const CharT> chars, MutableHandleValue rval)
{
size_t len = chars.length();
MOZ_ASSERT((chars[0] == '(' && chars[len - 1] == ')') ||
(chars[0] == '[' && chars[len - 1] == ']'));
auto jsonChars = (chars[0] == '[')
? chars
: mozilla::Range<const CharT>(chars.start().get() + 1U, len - 2);
JSONParser<CharT> parser(cx, jsonChars, JSONParserBase::NoError);
if (!parser.parse(rval))
return EvalJSON_Failure;
return rval.isUndefined() ? EvalJSON_NotJSON : EvalJSON_Success;
}
示例4: JS_ASSERT
UTF8CharsZ
JS::CharsToNewUTF8CharsZ(js::ThreadSafeContext *cx, const mozilla::Range<const CharT> chars)
{
JS_ASSERT(cx);
/* Get required buffer size. */
const CharT *str = chars.start().get();
size_t len = ::GetDeflatedUTF8StringLength(str, chars.length());
/* Allocate buffer. */
char *utf8 = cx->pod_malloc<char>(len + 1);
if (!utf8)
return UTF8CharsZ();
/* Encode to UTF8. */
::DeflateStringToUTF8Buffer(str, chars.length(), mozilla::RangedPtr<char>(utf8, len));
utf8[len] = '\0';
return UTF8CharsZ(utf8, len);
}
示例5: UTF8CharsZ
UTF8CharsZ
JS::CharsToNewUTF8CharsZ(js::ExclusiveContext* maybeCx, const mozilla::Range<CharT> chars)
{
/* Get required buffer size. */
const CharT* str = chars.start().get();
size_t len = ::GetDeflatedUTF8StringLength(str, chars.length());
/* Allocate buffer. */
char* utf8;
if (maybeCx)
utf8 = maybeCx->pod_malloc<char>(len + 1);
else
utf8 = js_pod_malloc<char>(len + 1);
if (!utf8)
return UTF8CharsZ();
/* Encode to UTF8. */
::DeflateStringToUTF8Buffer(str, chars.length(), mozilla::RangedPtr<char>(utf8, len));
utf8[len] = '\0';
return UTF8CharsZ(utf8, len);
}
示例6:
Latin1CharsZ
JS::LossyTwoByteCharsToNewLatin1CharsZ(js::ThreadSafeContext *cx,
const mozilla::Range<const jschar> tbchars)
{
JS_ASSERT(cx);
size_t len = tbchars.length();
unsigned char *latin1 = cx->pod_malloc<unsigned char>(len + 1);
if (!latin1)
return Latin1CharsZ();
for (size_t i = 0; i < len; ++i)
latin1[i] = static_cast<unsigned char>(tbchars[i]);
latin1[len] = '\0';
return Latin1CharsZ(latin1, len);
}