Пример #1
0
/**
 * Saffire method: match a string against (compiled) regex
 */
SAFFIRE_METHOD(regex, match) {
    t_string_object *str;
    int ovector[OVECCOUNT];
    int rc;

    // Parse the arguments
    if (! object_parse_arguments(SAFFIRE_METHOD_ARGS, "s", &str)) {
        saffire_warning("Error while parsing argument list\n");
        RETURN_NUMERICAL(0);
    }

    // Convert to utf8 and execute regex
    rc = pcre_exec(self->regex, 0, str->value, strlen(str->value), 0, 0, ovector, OVECCOUNT);

    // Check result
    if (rc < 0) {
        switch (rc) {
            case PCRE_ERROR_NOMATCH:
                saffire_warning("String didn't match.\n");
                break;
            default :
                saffire_warning("Error while matching: %d\n", rc);
                break;
        }
    }

    // Display result
    for (int i=0; i<rc; i++) {
        DEBUG_PRINT("%2d: %.*s\n", i, ovector[2*i+1] - ovector[2*i], str->value + ovector[2*i]);
    }

    // Return number of matches
    RETURN_NUMERICAL(rc);
}
Пример #2
0
/**
 * Saffire method:
 */
SAFFIRE_METHOD(hash, add) {
    t_string_object *key, *val;

    if (! object_parse_arguments(SAFFIRE_METHOD_ARGS, "ss", &key, &val)) {
        saffire_warning("Error while parsing argument list\n");
        RETURN_NUMERICAL(0);
    }

    ht_add(self->ht, key->value, val->value);
    RETURN_SELF;
}
Пример #3
0
/**
 * Saffire method:
 */
SAFFIRE_METHOD(hash, remove) {
    t_string_object *key;

    if (! object_parse_arguments(SAFFIRE_METHOD_ARGS, "s", &key)) {
        saffire_warning("Error while parsing argument list\n");
        RETURN_NUMERICAL(0);
    }

    ht_remove(self->ht, key->value);
    RETURN_SELF;
}
Пример #4
0
/**
  * Saffire method: Returns object stored at "key" inside the hash (or NULL when not found)
  */
SAFFIRE_METHOD(hash, find) {
    t_string_object *key;

    if (! object_parse_arguments(SAFFIRE_METHOD_ARGS, "s", &key)) {
        saffire_warning("Error while parsing argument list\n");
        RETURN_NUMERICAL(0);
    }

    t_object *obj = ht_find(self->ht, key->value);
    if (obj == NULL) RETURN_NULL;
    RETURN_OBJECT(obj);
}
Пример #5
0
SAFFIRE_OPERATOR_METHOD(numerical, sr) {
    t_numerical_object *self = (t_numerical_object *)_self;
    t_numerical_object *other;

    // Parse the arguments
    if (! object_parse_arguments(SAFFIRE_METHOD_ARGS, "n", &other)) {
        saffire_warning("Error while parsing argument list\n");
        RETURN_NUMERICAL(0);
    }

    if (in_place) {
        DEBUG_PRINT("Add to self\n");
        self->value >>= other->value;
        RETURN_SELF;
    }

    t_object *obj = object_new(Object_Numerical, self->value >> other->value);
    RETURN_OBJECT(obj);
}
Пример #6
0
SAFFIRE_METHOD(regex, conv_numerical) {
    RETURN_NUMERICAL(0);
}
Пример #7
0
SAFFIRE_METHOD(null, conv_numerical) {
    RETURN_NUMERICAL(0);
}
Пример #8
0
/**
 * Saffire method: Returns the number of elements stored inside the hash
 */
SAFFIRE_METHOD(hash, length) {
    RETURN_NUMERICAL(self->ht->element_count);
}
Пример #9
0
SAFFIRE_METHOD(hash, conv_numerical) {
    RETURN_NUMERICAL(self->ht->element_count);
}