Last active
February 8, 2017 08:17
-
-
Save SaitoAtsushi/319af29efab7fbd8ff54af69a0c19042 to your computer and use it in GitHub Desktop.
第25回シェル芸勉強会 Q6 -- UTF-16LE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!r6rs | |
;; 第25回シェル芸勉強会 Q6 -- UTF-16LE | |
;; http://qiita.com/nakataSyunsuke/items/339965853684dd11e755 | |
(import (rnrs) | |
(rnrs mutable-strings)) | |
(define (transcoded-from-hexstring-port in) | |
(define temporary (make-string 4)) | |
(define (read-cp) | |
(let* ((h (get-string-n! in temporary 2 2)) | |
(l (get-string-n! in temporary 0 2))) | |
(if (or (eof-object? h) (eof-object? l)) | |
(eof-object) | |
(string->number temporary 16)))) | |
(define (read! str start count) | |
(define cp) | |
(do ((start start (+ start 1)) | |
(i 0 (+ i 1))) | |
((or (= i count) (begin (set! cp (read-cp)) (eof-object? cp))) i) | |
(string-set! str start (integer->char cp)))) | |
(define (close) (close-port in)) | |
(make-custom-textual-input-port "hexstring->string" read! #f #f close)) | |
(define (q6 str) | |
(get-string-all | |
(transcoded-from-hexstring-port (open-string-input-port str)))) | |
(display (q6 "b730a730eb30b8820a00")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment