static char *format_token(char *outbuf, size_t outbuf_len, tfs_token_t *token) {
    char *p = outbuf;
    char *match = tfs_match_token(posix_tokens, sizeof(posix_tokens)/sizeof(posix_tokens[0]), token);
    if (match) {
        p = stpncpy(p, match, outbuf_len);
    } else {
        p = NULL;
    }
    return p;
}
Beispiel #2
0
static char *format_token(char *outbuf, tfs_token_t *token) {
    char *p = outbuf;
    if (token->time_unit == TFS_MINUTE) {
        if (token->style == TFS_NUMBER) {
            p = stpcpy(p, "m");
        } else if (token->style == TFS_2DIGIT) {
            p = stpcpy(p, "mm");
        } else {
            p = NULL;
        }
    } else if (token->time_unit == TFS_HOUR) {
        if (token->style == TFS_NUMBER) {
            p = stpcpy(p, "h");
        } else if (token->style == TFS_2DIGIT) {
            p = stpcpy(p, "hh");
        } else {
            p = NULL;
        }
    } else if (token->time_unit == TFS_FRACTIONAL_SECOND) {
        if (token->add_dots) {
            p = stpcpy(p, ".");
        }
        size_t len = token->truncate_len;
        while (len--) {
            p = stpcpy(p, "0");
        }
    } else {
        char *match = tfs_match_token(excel_tokens, sizeof(excel_tokens)/sizeof(excel_tokens[0]), token);
        if (match) {
            p = stpcpy(p, match);
        } else {
            p = NULL;
        }
    }
    return p;
}