|
From: | Maurits Lamers |
Subject: | Re: Multi-byte characters in Lyrics |
Date: | Fri, 27 Oct 2017 11:49:59 +0200 |
This probably also has to do with me having to dive in scheme after just a few lessons quite a few years ago. :) But anyhow, this has changed now, so it is no longer valid.
Then I must have made some other kind of mistake which caused that.
#(define ((clz n) x) (let loop ((i 1) (x x)) (if (< i n) (loop (ash i 1) (logior x (ash x (- 0 i)))) (- n (logcount x))))) #(define (bitwise-andc1 x y) (logand (lognot x) y) ) #(define (utf8-n o) (max 1 ((clz 8) (bitwise-andc1 o #xff)))) #(define (string->utf8-list str) (if (equal? (string-length str) 0) '() (append '() (list (string-copy str 0 (utf8-n (char->integer (string-ref str 0))))) (string->utf8-list (string-copy str (utf8-n (char->integer (string-ref str 0)))))) ) ) The bitshifting is used to figure out how many high bits are set, as in UTF8 those indicate how many chars it takes to have the full character. The solution then splits the string by the amount of chars it take to assemble the full character From reading your solution, I figured you do something similar, but it uses the char code instead.
Interesting, will have to try the bitshifting solution with that :) cheers and thanks! Maurits |
[Prev in Thread] | Current Thread | [Next in Thread] |