1/* @ajax/rsfmt: text exactly as Rust's format! writes it, for C ports that must print the same bytes.
2 *
3 * Floats: Rust and glibc both print the exact binary value correctly rounded (ties to even), so
4 * printf does the digits; this fixes what differs: NaN is "NaN" (never signed), infinity "inf",
5 * the exponent form is "1.5e-3" (no '+', no leading zeros), and widths count characters (code
6 * points), not bytes. Every function writes at most cap bytes (NUL included) and returns the
7 * length it needed, as snprintf does. */
8#ifndef RSFMT_H
9#define RSFMT_H
1011#include <stdbool.h>
12#include <stddef.h>
1314enum {
15 RSFMT_PLUS = 1, /* {:+} */
16 RSFMT_ZERO = 2, /* {:0w}: sign-aware zero padding (numbers only) */
17};
1819/* {:.prec$} of v (an f32 passed as double prints the same, as the value is exact). */
20int rsfmt_fixed(char *out, size_t cap, double v, int prec, int flags);
21/* {:.prec$e} */
22int rsfmt_exp(char *out, size_t cap, double v, int prec, int flags);
23/* {:.prec$} padded to width: align is '<', '>' or '^' ('>' is Rust's default for numbers). */
24int rsfmt_fixed_w(char *out, size_t cap, double v, int prec, int width, char align, int flags);
25/* {:<w$} {:>w$} {:^w$} of a string: pads with fill to width characters (never truncates). */
26int rsfmt_pad(char *out, size_t cap, const char *s, int width, char align, char fill);
27/* Unicode scalar values in a UTF-8 string (Rust's s.chars().count()). */
28size_t rsfmt_chars(const char *s);
29/* The first n characters of s, as a byte length (Rust's s.chars().take(n)). */
30size_t rsfmt_prefix(const char *s, size_t n);
3132#endif