forked from OctaForge/libostd
format cleanups (and add convenience method put_string to the to_format range)
This commit is contained in:
parent
b2d656e481
commit
debbddc8da
|
@ -181,16 +181,17 @@ struct FormatSpec {
|
||||||
return p_fmt;
|
return p_fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void build_spec(char *buf, const char *spec, Size specn) {
|
template<typename R>
|
||||||
*buf++ = '%';
|
Size build_spec(R &&out, ConstCharRange spec) {
|
||||||
if (p_flags & FMT_FLAG_DASH ) *buf++ = '-';
|
Size ret = out.put('%');
|
||||||
if (p_flags & FMT_FLAG_ZERO ) *buf++ = '0';
|
if (p_flags & FMT_FLAG_DASH ) ret += out.put('-');
|
||||||
if (p_flags & FMT_FLAG_SPACE) *buf++ = ' ';
|
if (p_flags & FMT_FLAG_ZERO ) ret += out.put('0');
|
||||||
if (p_flags & FMT_FLAG_PLUS ) *buf++ = '+';
|
if (p_flags & FMT_FLAG_SPACE) ret += out.put(' ');
|
||||||
if (p_flags & FMT_FLAG_HASH ) *buf++ = '#';
|
if (p_flags & FMT_FLAG_PLUS ) ret += out.put('+');
|
||||||
memcpy(buf, "*.*", 3);
|
if (p_flags & FMT_FLAG_HASH ) ret += out.put('#');
|
||||||
memcpy(buf + 3, spec, specn);
|
ret += out.put_n("*.*", 3);
|
||||||
*(buf += specn + 3) = '\0';
|
ret += out.put_n(&spec[0], spec.size());
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int width() const { return p_width; }
|
int width() const { return p_width; }
|
||||||
|
@ -608,6 +609,9 @@ namespace detail {
|
||||||
p_written += ret;
|
p_written += ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Size put_string(ConstCharRange r) {
|
||||||
|
return put_n(&r[0], r.size());
|
||||||
|
}
|
||||||
Size get_written() const { return p_written; }
|
Size get_written() const { return p_written; }
|
||||||
private:
|
private:
|
||||||
R &p_out;
|
R &p_out;
|
||||||
|
@ -729,7 +733,7 @@ namespace detail {
|
||||||
if (specn == 7) fmtspec[Long] = 'g';
|
if (specn == 7) fmtspec[Long] = 'g';
|
||||||
if (Long) fmtspec[0] = 'L';
|
if (Long) fmtspec[0] = 'L';
|
||||||
|
|
||||||
this->build_spec(buf, fmtspec, sizeof(fmtspec));
|
buf[this->build_spec(iter(buf), fmtspec)] = '\0';
|
||||||
Ptrdiff ret = snprintf(rbuf, sizeof(rbuf), buf,
|
Ptrdiff ret = snprintf(rbuf, sizeof(rbuf), buf,
|
||||||
this->width(),
|
this->width(),
|
||||||
this->has_precision() ? this->precision() : 6, val);
|
this->has_precision() ? this->precision() : 6, val);
|
||||||
|
|
Loading…
Reference in a new issue