Bug 1319740 - Add a slash-matching function rather than using MatchPart. r=arai

--HG--
extra : rebase_source : 49eb87fca5f844e1b6eec00e6db3a380cc6300c8
This commit is contained in:
Jeff Walden 2016-12-02 13:59:59 -08:00
Родитель a2f6acca0f
Коммит 6fa1238476
1 изменённых файлов: 18 добавлений и 18 удалений

Просмотреть файл

@ -3027,6 +3027,18 @@ MatchPart(const char** pattern, const char (&part)[N])
return true;
}
static bool
MatchSlash(JSContext* cx, const JSAutoByteString& pattern, const char** iter)
{
if (MOZ_LIKELY(**iter == '/')) {
*iter += 1;
return true;
}
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_INVALID_KEY, pattern.ptr());
return false;
}
bool
js::intl_ComputeDisplayNames(JSContext* cx, unsigned argc, Value* vp)
{
@ -3112,16 +3124,12 @@ js::intl_ComputeDisplayNames(JSContext* cx, unsigned argc, Value* vp)
return false;
}
if (!MatchPart(&pat, "/")) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_INVALID_KEY, pattern.ptr());
if (!MatchSlash(cx, pattern, &pat))
return false;
}
if (MatchPart(&pat, "fields")) {
if (!MatchPart(&pat, "/")) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_INVALID_KEY, pattern.ptr());
if (!MatchSlash(cx, pattern, &pat))
return false;
}
UDateTimePatternField fieldType;
@ -3158,19 +3166,15 @@ js::intl_ComputeDisplayNames(JSContext* cx, unsigned argc, Value* vp)
wordVal.setString(word);
} else if (MatchPart(&pat, "gregorian")) {
if (!MatchPart(&pat, "/")) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_INVALID_KEY, pattern.ptr());
if (!MatchSlash(cx, pattern, &pat))
return false;
}
UDateFormatSymbolType symbolType;
int32_t index;
if (MatchPart(&pat, "months")) {
if (!MatchPart(&pat, "/")) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_INVALID_KEY, pattern.ptr());
if (!MatchSlash(cx, pattern, &pat))
return false;
}
if (equal(style, "narrow")) {
symbolType = UDAT_STANDALONE_NARROW_MONTHS;
@ -3210,10 +3214,8 @@ js::intl_ComputeDisplayNames(JSContext* cx, unsigned argc, Value* vp)
return false;
}
} else if (MatchPart(&pat, "weekdays")) {
if (!MatchPart(&pat, "/")) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_INVALID_KEY, pattern.ptr());
if (!MatchSlash(cx, pattern, &pat))
return false;
}
if (equal(style, "narrow")) {
symbolType = UDAT_STANDALONE_NARROW_WEEKDAYS;
@ -3243,10 +3245,8 @@ js::intl_ComputeDisplayNames(JSContext* cx, unsigned argc, Value* vp)
return false;
}
} else if (MatchPart(&pat, "dayperiods")) {
if (!MatchPart(&pat, "/")) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_INVALID_KEY, pattern.ptr());
if (!MatchSlash(cx, pattern, &pat))
return false;
}
symbolType = UDAT_AM_PMS;