Exemplo n.º 1
0
static char*
S_camel_to_lower(const char *camel) {
    if (camel[0] == '\0') { return CFCUtil_strdup(""); }

    size_t alloc = 1;
    for (size_t i = 1; camel[i]; i++) {
        if (CFCUtil_isupper(camel[i]) && CFCUtil_islower(camel[i+1])) {
            alloc += 1;
        }
        alloc += 1;
    }
    char *lower = (char*)MALLOCATE(alloc + 1);

    lower[0] = CFCUtil_tolower(camel[0]);
    size_t j = 1;
    for (size_t i = 1; camel[i]; i++) {
        // Only insert underscore if next char is lowercase.
        if (CFCUtil_isupper(camel[i]) && CFCUtil_islower(camel[i+1])) {
            lower[j++] = '_';
        }
        lower[j++] = CFCUtil_tolower(camel[i]);
    }
    lower[j] = '\0';

    return lower;
}
Exemplo n.º 2
0
CFCClass*
CFCParcel_class_by_full_sym(CFCParcel *self, const char *full_struct_sym) {
    size_t prefix_len = 0;
    size_t sym_len    = strlen(full_struct_sym);
    while (prefix_len < sym_len
           && !CFCUtil_isupper(full_struct_sym[prefix_len])
          ) {
        prefix_len += 1;
    }
    if (!prefix_len) {
        CFCUtil_die("Full struct symbol '%s' has invalid prefix",
                    full_struct_sym);
    }

    return S_class_by_struct_sym_prereq(self, full_struct_sym, prefix_len);
}