All pastes #2069533 Raw Edit

Anonymous

public text v1 · immutable
#2069533 ·published 2011-05-26 17:17 UTC
rendered paste body
char * trivia_build_hint(char * buf, char * in, int level) {
    int i = 0;
    int j = 0;
    for (; i < strlen(in); i++) {
        int bc = utfbytes(in[i]);
        if (bc == 1) {
            if (level >= 1) {
                if (in[i] != ' ')
                    buf[j] = '*';
                else
                    buf[j] = ' ';
            }
            if (level >= 2) {
                if (i < 3 || strchr(punctuation,in[i]))
                    buf[j] = in[i];
            }
            if (level >= 3) {
                if (strchr(vowels,in[i]))
                    buf[j] = in[i];
            }

            j++;

        } else {
            i += bc-1; // skip the rest of this multibyte
            buf[j++] = '#';
        }
    }

    return buf;
}