Repository: google/filament
File: libs/filament-matp/src/JsonishParser.cpp (C++)

Code before:
    }

    return array;
}

// Strings optionally have an array suffix, as in: "float[9]". To handle this we parse the array
// value (which might be multidimensional), discard the parsed value, and append it to the string.
JsonishValue* JsonishParser::parseString() noexcept {
    std::string tmp;
    const JsonLexeme* strLexeme = consumeLexeme(STRING);
    const JsonLexeme* arrLexeme = peekNextLexemeType();
    JsonishValue* arrValue;
    if (arrLexeme && arrLexeme->getType() == ARRAY_START && (arrValue = parseArray())) {
        delete arrValue;

        const JsonLexeme* next = peekNextLexemeType();
        if (!next) {
            return nullptr;
        }

        size_t length = next->getStart() - strLexeme->getStart();
        tmp = std::string(strLexeme->getStart(), length);
    } else {
        tmp = std::string(strLexeme->getStart(), strLexeme->getSize());
    }
    return new JsonishString(resolveEscapes(tmp, mStatus));
}

JsonishValue* JsonishParser::parseValue() noexcept {
    const JsonLexeme* next = peekNextLexemeType();
    if (next == nullptr) {
        return nullptr;
    }

    switch (next->getType()) {
        case STRING:
            return parseString();
        case NUMBER:
            consumeLexeme(NUMBER);
            return new JsonishNumber(utils::strtof_c(next->getStart(), nullptr));
        case BLOCK_START:
            return parseObject();
        case ARRAY_START:
            return parseArray();
        case BOOLEAN:
            consumeLexeme(BOOLEAN);
            return new JsonishBool(!strncmp(next->getStart(), "true", next->getSize()));
        case NUll:
            consumeLexeme(NUll);
            return new JsonishNull();
        default:

Review comment (bug):
This feels like it should return null if `resolveEscapes` failed.  It's more in line with the rest of the error handling. 

Code after:
}

// Strings optionally have an array suffix, as in: "float[9]". To handle this we parse the array
// value (which might be multidimensional), discard the parsed value, and append it to the string.
JsonishValue* JsonishParser::parseString() noexcept {
    std::string tmp;
    const JsonLexeme* strLexeme = consumeLexeme(STRING);
    const JsonLexeme* arrLexeme = peekNextLexemeType();
    JsonishValue* arrValue;
    if (arrLexeme && arrLexeme->getType() == ARRAY_START && (arrValue = parseArray())) {
        delete arrValue;

        const JsonLexeme* next = peekNextLexemeType();
        if (!next) {
            return nullptr;
        }

        size_t length = next->getStart() - strLexeme->getStart();
        tmp = std::string(strLexeme->getStart(), length);
    } else {
        tmp = std::string(strLexeme->getStart(), strLexeme->getSize());
    }
    auto [status, resolvedStr] = resolveEscapes(tmp);
    if (!status.isOk()) {
        mStatus = status;
        return nullptr;
    }
    return new JsonishString(resolvedStr);
}

JsonishValue* JsonishParser::parseValue() noexcept {
    const JsonLexeme* next = peekNextLexemeType();
    if (next == nullptr) {
        return nullptr;
    }

    switch (next->getType()) {
        case STRING:
            return parseString();
        case NUMBER:
            consumeLexeme(NUMBER);
            return new JsonishNumber(utils::strtof_c(next->getStart(), nullptr));
        case BLOCK_START:
            return parseObject();
        case ARRAY_START:
            return parseArray();
        case BOOLEAN:
            consumeLexeme(BOOLEAN);
            return new JsonishBool(!strncmp(next->getStart(), "true", next->getSize()));
        case NUll:
            consumeLexeme(NUll);