PicoLisp implementation of the BOAWP specification https://boawp.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
936 B

### String
(de _boawp-utf8-str (Str)
(if (lst? Str)
(let P (native "@" "malloc" 'N (length Str))
(eval (append '(struct P NIL) Str (0))) # always add a terminating null byte
(if (=0 (native ".lib/libpilrust.so" "validate_utf8" 'I P))
(let Res (struct P 'S)
(native "@" "free" NIL P)
Res )
(native "@" "free" NIL P)
(_boawp-err "Invalid UTF-8 string")) )
(if (=0 (native ".lib/libpilrust.so" "validate_utf8" 'I Str))
(_boawp-err "Invalid UTF-8 string")) ]
(de _boawp-ascii-str (Buffer)
(pack (mapcar '((S) (if (member S (range 33 126))
(char S)
(_boawp-err "Invalid header name ASCII encoding")) )
Buffer) ]
(de _boawp-utf8-list (Str)
(when (str? Str)
(head -1 (native ".lib/libpilrust.so" "utf8_to_bytes" (cons 'B (bytes Str)) Str) ]