Beispiel #1
0
static value_t fl_length(value_t *args, u_int32_t nargs)
{
    argcount("length", nargs, 1);
    value_t a = args[0];
    cvalue_t *cv;
    if (isvector(a)) {
        return fixnum(vector_size(a));
    }
    else if (iscprim(a)) {
        cv = (cvalue_t*)ptr(a);
        if (cp_class(cv) == bytetype)
            return fixnum(1);
        else if (cp_class(cv) == wchartype)
            return fixnum(u8_charlen(*(uint32_t*)cp_data((cprim_t*)cv)));
    }
    else if (iscvalue(a)) {
        cv = (cvalue_t*)ptr(a);
        if (cv_class(cv)->eltype != NULL)
            return size_wrap(cvalue_arraylen(a));
    }
    else if (a == FL_NIL) {
        return fixnum(0);
    }
    else if (iscons(a)) {
        return fixnum(llength(a));
    }
    type_error("length", "sequence", a);
}
Beispiel #2
0
size_t u8_codingsize(const uint32_t *wcstr, size_t n)
{
    size_t i, c=0;

    for(i=0; i < n; i++)
        c += u8_charlen(wcstr[i]);
    return c;
}
Beispiel #3
0
size_t u8_codingsize(uint32_t *wcstr, size_t n)
{
    size_t i, c=0;

    for(i=0; i < n; i++) {
        size_t cl = u8_charlen(wcstr[i]);
        if (cl == 0) cl = 3;  // invalid: encoded as replacement char
        c += cl;
    }
    return c;
}