示例#1
0
文件: tags.c 项目: flrl/goat
GoatError goat_message_get_tag_value(
    const GoatMessage *message, const char *key, char *value, size_t *size
) {
    if (NULL == message) return EINVAL;
    if (NULL == key) return EINVAL;
    if (NULL == value) return EINVAL;
    if (NULL == size) return EINVAL;

    const MessageTags *tags = message->m_tags;

    if (NULL == tags || 0 == strlen(tags->m_bytes)) return GOAT_E_NOTAG;

    const char *p, *v, *end;

    p = _find_tag(tags->m_bytes, key);
    if (NULL == p) return GOAT_E_NOTAG;

    v = _find_value(p);
    if (NULL == v) return GOAT_E_NOTAGVAL;

    end = _next_tag(v);
    if ('\0' != *end) end--; // account for separator

    char unescaped[GOAT_MESSAGE_MAX_TAGS];
    size_t unescaped_len = sizeof(unescaped);
    _unescape_value(v, unescaped, &unescaped_len);

    if (*size <= unescaped_len) return EOVERFLOW;

    memset(value, 0, *size);
    strncpy(value, unescaped, unescaped_len);
    *size = unescaped_len;

    return 0;
}
示例#2
0
文件: trie.c 项目: felipecruz/cdats
int trie_has_node (trie_node_t *trie, const char* word)
{
    while (*word) {
        trie_node_t *found = _find_value (trie->children, *(word));
        if (found) {
            trie = found;
        } else {
            return 0;
        }
        *(word++);
    }
    return 1;
}
示例#3
0
文件: trie.c 项目: felipecruz/cdats
int trie_add_word (trie_node_t *trie, const char* word)
{
    while (*word) {
        trie_node_t *found = _find_value (trie->children, *(word));
        if (found) {
            trie = found;
        } else {
            trie->children[NORMALIZE_(*(word))] = trie_node_init ();
            trie->children[NORMALIZE_(*(word))]->value = *(word);
            trie = trie->children[NORMALIZE_(*word)];
        }
        *(word++);
    }
    return 1;
}