示例#1
0
void struct_attribute_foreach(FcitxConfiguration* config, const char* path, void* userData)
{
    FcitxDescription* desc = userData;
    if (desc->error) {
        return;
    }

    const char* type = fcitx_configuration_get_value_by_path(config, "Type");
    if (!type) {
        asprintf(&desc->errorMessage, "%s misses Type.", path);
        desc->error = true;
        return;
    }

    if (!is_builtin_type(type)) {
        asprintf(&desc->errorMessage, "Invalide Type.");
        desc->error = true;
        return;
    }

    if (strcmp(type, "List") == 0) {
        const char* subType = fcitx_configuration_get_value_by_path(config, "SubType");
        if (!subType) {
            asprintf(&desc->errorMessage, "%s misses SubType.", path);
            desc->error = true;
            return;
        }

        if (strcmp(subType, "List") == 0) {
            asprintf(&desc->errorMessage, "Recursive List is not allowed.");
            desc->error = true;
            return;
        }

        if (!is_builtin_type(subType) && !fcitx_string_hashset_contains(desc->structs, subType)) {
            asprintf(&desc->errorMessage, "Invalide SubType.");
            desc->error = true;
            return;
        }

        fcitx_string_hashset_remove(desc->topLevelStructs, subType);
    }
}
示例#2
0
void test_string_hash_set()
{

    FcitxStringHashSet* sset = fcitx_string_hashset_parse("a,b,c,d", ',');
    assert(fcitx_dict_size(sset) == 4);
    assert(fcitx_string_hashset_contains(sset, "c"));
    assert(!fcitx_string_hashset_contains(sset, "e"));
    fcitx_string_hashset_remove(sset, "c");
    assert(!fcitx_string_hashset_contains(sset, "c"));
    fcitx_string_hashset_insert(sset, "e");
    assert(fcitx_string_hashset_contains(sset, "e"));

    /* uthash guarantee order, so we can sure about this */
    char* joined = fcitx_string_hashset_join(sset, ',');
    assert(strcmp(joined, "a,b,d,e") == 0);

    free(joined);

    fcitx_string_hashset_free(sset);
}