aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorHoël Bézier <hoelbezier@riseup.net>2025-11-23 19:09:48 +0100
committerLaurent Bercot <ska-skaware@skarnet.org>2026-02-03 01:24:07 +0000
commitbe207f5b5974ae9660e3a7eec664f8c65b5db068 (patch)
tree048bf6eccd508bdc1d17ba06d8d1fb50cb0efc56 /doc
parent973b9d9e0af9b1c363829385a08d93da189057ab (diff)
downloadskalibs-be207f5b5974ae9660e3a7eec664f8c65b5db068.tar.gz
add fmtscan.h documentation
Signed-off-by: Hoël Bézier <hoelbezier@riseup.net>
Diffstat (limited to 'doc')
-rw-r--r--doc/libstddjb/fmtscan.html82
1 files changed, 80 insertions, 2 deletions
diff --git a/doc/libstddjb/fmtscan.html b/doc/libstddjb/fmtscan.html
index 4e54e4f..dd93a5d 100644
--- a/doc/libstddjb/fmtscan.html
+++ b/doc/libstddjb/fmtscan.html
@@ -18,10 +18,88 @@
<a href="//skarnet.org/">skarnet.org</a>
</p>
-<h1> The <tt>skalibs/fmtscan.h</tt> header </h1>
+<h1> Formatting and scanning functions </h1>
<p>
- TODO: write this documentation page. (Sorry!)
+ The preferred skalibs way of converting objects to string for output is to use
+the various <tt>*_fmt</tt> functions available in <tt>skalibs/fmtscan.h</tt>
+and other object-specific headers. These functions take at least two parameters:
+</p>
+
+<ul>
+ <li> The target buffer into which the formatted object will be written.
+This buffer must be large enough to hold the formatted object. </li>
+ <li> The object that should be formatted into the buffer. </li>
+</ul>
+
+<p>
+ They return the number of bytes written into the buffer.
+</p>
+
+<p>
+ To ensure that the buffer is large enough, <tt>skalibs</tt> provides several
+<tt>x_FMT</tt> macros corresponding to the minimum buffer size necessary for
+formatting an object of type <em>x</em> to a string, including the terminating
+nul byte.
+</p>
+
+<p>
+ Conversely, to scan objects from a string, skalibs provides several
+<tt>*_scan</tt> functions. They take the same parameters as the <tt>*_fmt</tt>
+ones, with meaning reversed. They return the number of bytes read from the
+input buffer
+</p>
+
+<h2> Examples </h2>
+
+<pre>
+ uint32_t u = ... ;
+ char buf[UINT32_FMT] ;
+ buf[uint32_fmt(buf, u)] = 0 ;
+</pre>
+
+<pre>
+ char *buf = "123a" ;
+ uint32_t u ;
+ size_t p ;
+ p = uint32_scan(buf, &u) ;
+ // p is 3, u is 123
+</pre>
+
+<h2> Functions </h2>
+
+<p>
+ Formatting and scanning functions for the integer types can be found in
+<tt>skalibs/uint16h</tt>, <tt>skalibs/uint32.h</tt> and
+<tt>skalibs/uint64.h</tt>, those for standard unix types (such as
+<tt>pid_t</tt> or <tt>uid_t</tt>) can be found in <tt>skalibs/types.h</tt>.
+Other formatting functions can be found in <tt>skalibs/fmtscan.h</tt>.
+</p>
+
+<p>
+<code> size_t uint64_fmt_generic (char *s, uint64_t i, uint8_t b) </code> <br />
+Write the representation in base <em>b</em> of integer <em>i</em> into the buffer
+pointed to by <em>s</em>. Returns the number of bytes written.
+</p>
+
+<p>
+<code> size_t uint640_fmt_generic (char *s, uint64_t i, size_t pad, uint8_t b) </code> <br />
+Write the representation in base <em>b</em> of integer <em>i</em> into the buffer
+pointed to by <em>s</em>, padding if necessary with zeros to ensure the
+written string is at least <em>pad</em> bytes long. Returns the number of
+bytes written.
+</p>
+
+<p>
+<code> size_t uint64_scan_base (char const *s, uint64_t *i, uint8_t b) </code> <br />
+Scan the first bytes of the buffer pointed to by <em>s</em> for an <tt>uint64_t</tt>
+exrpessed in base <em>b</em> and write it into <em>i</em>. Returns the number of
+bytes read.
+<p>
+
+<p>
+ The above are the most fundamental functions. Other functions are usually expressed
+in terms of these, or have self-explanatory prototypes.
</p>
</body>