Esempio n. 1
0
/*
 * Copy :first-line|letter
 */
static void
copy_first(const rchar **source_, rchar **target_, rcssmin_ctx_t *ctx)
{
    const rchar *source = *source_, *next, *source_fork;
    rchar *target = *target_, *target_fork;

    *target++ = U(':');
    *target_ = target;

    if (!IMATCH(first, &source, &target, ctx)
        || !(source < ctx->sentinel && target < ctx->tsentinel))
        ABORT;

    source_fork = source;
    target_fork = target;

    if (!IMATCH(line, &source, &target, ctx)) {
        source = source_fork;
        target = target_fork;

        if (!IMATCH(letter, &source, &target, ctx)
            || !(source < ctx->sentinel && target < ctx->tsentinel))
            ABORT;
    }

    next = skip_space(source, ctx);
    if (!(next < ctx->sentinel && target < ctx->tsentinel
        && (*next == U('{') || *next == U(','))))
        ABORT;

    *target++ = U(' ');
    *target_ = target;
    *source_ = source;
    (void)copy_space_optional(source_, target_, ctx);
}
Esempio n. 2
0
STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) {
    const char *arg_type = *jtypesig;
    mp_obj_type_t *type = mp_obj_get_type(arg);

    if (type == &mp_type_str) {
        if (IMATCH(arg_type, "java.lang.String") || IMATCH(arg_type, "java.lang.Object")) {
            out->l = JJ(NewStringUTF, mp_obj_str_get_str(arg));
        } else {
            return false;
        }
    } else if (type == &mp_type_int) {
        if (IMATCH(arg_type, "int") || IMATCH(arg_type, "long")) {
            // TODO: Java long is 64-bit actually
            out->j = mp_obj_get_int(arg);
        } else {
            return false;
        }
    } else if (type == &jobject_type) {
        bool is_object = false;
        const char *expected_type = arg_type;
        while (1) {
            if (isalpha(*arg_type)) {
            } else if (*arg_type == '.') {
                is_object = true;
            } else {
                break;
            }
            arg_type++;
        }
        if (!is_object) {
            return false;
        }
        mp_obj_jobject_t *jo = arg;
        if (!MATCH(expected_type, "java.lang.Object")) {
            char class_name[64];
            get_jclass_name(jo->obj, class_name);
            //printf("Arg class: %s\n", class_name);
            if (strcmp(class_name, expected_type) != 0) {
                return false;
            }
        }
        out->l = jo->obj;
    } else if (type == &mp_type_bool) {
        if (IMATCH(arg_type, "boolean")) {
            out->z = arg == mp_const_true;
        } else {
            return false;
        }
    } else if (arg == mp_const_none) {
        //printf("TODO: Check java arg type!!\n");
        while (isalpha(*arg_type) || *arg_type == '.') {
            arg_type++;
        }
        out->l = NULL;
    } else {
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "arg type not supported"));
    }

    *jtypesig = arg_type;
    return true;
}