Extract parse_space_separated_languages

A bit too much logic in an attribute switch case which can be given a
better name. This function remains specialized until such time as it may
need to be generalized.

Change-Id: Idc5f7653cb8706d2c54c23a858b320266d4f989e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439737
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2021-08-16 12:04:35 -04:00 committed by SkCQ
parent 9a6f3990af
commit 7f4abe85a6

View File

@ -152,6 +152,21 @@ static void trim_string(SkString* s) {
s->resize(len);
}
static void parse_space_separated_languages(const char* value, size_t valueLen,
SkTArray<SkLanguage, true>& languages)
{
size_t i = 0;
while (true) {
for (; i < valueLen && is_whitespace(value[i]); ++i) { }
if (i == valueLen) { break; }
size_t j;
for (j = i + 1; j < valueLen && !is_whitespace(value[j]); ++j) { }
languages.emplace_back(value + i, j - i);
i = j;
if (i == valueLen) { break; }
}
}
namespace lmpParser {
static const TagHandler axisHandler = {
@ -286,16 +301,7 @@ static const TagHandler familyHandler = {
family->fNames.push_back().set(tolc.lc());
family->fIsFallbackFont = false;
} else if (MEMEQ("lang", name, nameLen)) {
size_t i = 0;
while (true) {
for (; i < valueLen && is_whitespace(value[i]); ++i) { }
if (i == valueLen) { break; }
size_t j;
for (j = i + 1; j < valueLen && !is_whitespace(value[j]); ++j) { }
family->fLanguages.emplace_back(value + i, j - i);
i = j;
if (i == valueLen) { break; }
}
parse_space_separated_languages(value, valueLen, family->fLanguages);
} else if (MEMEQ("variant", name, nameLen)) {
if (MEMEQ("elegant", value, valueLen)) {
family->fVariant = kElegant_FontVariant;