rcx

miscellaneous C library
git clone git://git.rr3.xyz/rcx
Log | Files | Refs | README | LICENSE

utf8.h (939B)


      1 #pragma once
      2 
      3 #include "def.h"
      4 
      5 #define R_UTF8_SIZE 4
      6 
      7 /* Return the number of bytes needed to encode c, or 0 if c is an invalid
      8  * codepoint. If s is nonnull, then it must have length >=
      9  * r_utf8_encode(0, c), which is guaranteed to be at most R_UTF8_SIZE;
     10  * in this case, if c is a valid codepoint, then encode c into s. */
     11 usize r_utf8_encode(char *s, rune c);
     12 
     13 /* Decode the first rune in s and return the number of consumed bytes. If this
     14  * succeeds and c is nonnull, then set *c to the decoded rune. Otherwise, no
     15  * valid rune is legally encoded as a prefix of s; in this case, set *c to
     16  * RUNE_BAD if c is nonnull, and return n such that
     17  *  - n = 0 iff s is null or an incomplete prefix of a valid rune;
     18  *  - n > 0 iff the first min(n+1,slen) bytes of s are not a prefix of any
     19  *    valid rune (but if n < slen, then s[n] might be the first byte of a
     20  *    valid rune). */
     21 usize r_utf8_decode(rune *c, char *s, usize slen);