copy version ##sys#char->utf8-string added by liao on Mon Dec 13 15:47:36 2021
(import (chicken fixnum)) (define (ichar->utf8-string c) (print c) (let ([i (char->integer c)]) (cond [(fx<= i #x7F) (string c) ] [(fx<= i #x7FF) (string (integer->char (fxior #b11000000 (fxshr i 6))) (integer->char (fxior #b10000000 (fxand i #b111111)))) ] [(fx<= i #xFFFF) (string (integer->char (fxior #b11100000 (fxshr i 12))) (integer->char (fxior #b10000000 (fxand (fxshr i 6) #b111111))) (integer->char (fxior #b10000000 (fxand i #b111111)))) ] [(fx<= i #x1FFFFF) (string (integer->char (fxior #b11110000 (fxshr i 18))) (integer->char (fxior #b10000000 (fxand (fxshr i 12) #b111111))) (integer->char (fxior #b10000000 (fxand (fxshr i 6) #b111111))) (integer->char (fxior #b10000000 (fxand i #b111111)))) ] [else (error "UTF-8 codepoint out of range:" i) ] ) ) )