Exemplo n.º 1
0
void h2o_time2str_rfc1123(char *buf, struct tm *gmt)
{
    char *p = buf;

    /* format: Fri, 19 Sep 2014 05:24:04 GMT */
    p = emit_wday(p, gmt->tm_wday);
    *p++ = ',';
    *p++ = ' ';
    p = emit_digits(p, gmt->tm_mday, 2);
    *p++ = ' ';
    p = emit_mon(p, gmt->tm_mon);
    *p++ = ' ';
    p = emit_digits(p, gmt->tm_year + 1900, 4);
    *p++ = ' ';
    p = emit_digits(p, gmt->tm_hour, 2);
    *p++ = ':';
    p = emit_digits(p, gmt->tm_min, 2);
    *p++ = ':';
    p = emit_digits(p, gmt->tm_sec, 2);
    memcpy(p, " GMT", 4);
    p += 4;
    *p = '\0';

    assert(p - buf == H2O_TIMESTR_RFC1123_LEN);
}
Exemplo n.º 2
0
static void engineering(dec64_string_state state) {
    int64 exponent = dec64_exponent(state->number) + state->nr_digits;
    int to = state->nr_digits - state->nr_zeros;
    int fudge = (int)exponent % 3;
    if (fudge <= 0) {
        fudge += 3;
    }
    emit_digits(state, 0, fudge);
    if (fudge < to) {
        emit_decimal_point(state);
        emit_digits(state, fudge, to);
    }
    emit_exponent(state, exponent - fudge);
}
Exemplo n.º 3
0
static void standard(
    dec64_string_state state
) {
    int from = 0;
    int to;
    int places;
    int sep = 0;
    int64 exponent = dec64_exponent(state->number);
    if (exponent >= 0) {
        to = state->nr_digits + (int)exponent;
        if (to + state->places > 20) {
            scientific(state);
        } else {
            emit_digits_separated(state, 0, to);
            if (state->places > 0) {
                emit_decimal_point(state);
                emit_digits(state, to, state->places + to);
            }
        }
    } else {
        from = (int)exponent + state->nr_digits;
        to = state->nr_digits - state->nr_zeros;
        if (from <= 0) {
            places = to - from;
            if (places > 18) {
                scientific(state);
            } else {
                emit(state, '0');
                emit_decimal_point(state);
                if (places < state->places) {
                    to = state->places + from;
                }
                emit_digits(state, from, to);
            }
        } else {
            emit_digits_separated(state, 0, from);
            emit_decimal_point(state);
            if (to - from < state->places) {
                to = state->places + from;
            }
            emit_digits(state, from, to);
        }
    }
}
Exemplo n.º 4
0
static void scientific(dec64_string_state state) {
    int64 exponent = dec64_exponent(state->number) + state->nr_digits;
    int nr_digits = (state->nr_digits - state->nr_zeros);
    int at = 1;
    emit_at(state, 0);
    if (at < nr_digits) {
        emit_decimal_point(state);
        emit_digits(state, 1, nr_digits);
    }
    emit_exponent(state, exponent - 1);
}
Exemplo n.º 5
0
static void emit_digits_separated(
    dec64_string_state state,
    int from, int to
) {
    int sep;
    if (state->separation <= 0) {
        emit_digits(state, from, to);
    }
    sep = to % state->separation;
    if (sep <= 0) {
        sep = state->separation;
    }
    while (1) {
        emit_digits(state, from, sep);
        from = sep;
        if (from >= to) {
            break;
        }
        emit(state, state->separator);
        sep += state->separation;
    }
}