Skip to content

Instantly share code, notes, and snippets.



Last active Dec 17, 2015
What would you like to do?
A function for getting the name of unicode code points
#lang racket/base
(provide unicode-name)
;; We want to compute the table at compile-time, so that the result can be saved
;; by using raco make.
(require (for-syntax net/url
(define-syntax (define-unicode-lookup-table stx)
(syntax-case stx ()
[(_ id)
(let ()
(define ht (make-hash))
(define data
(get-pure-port (string->url
(for ([line (in-lines data)])
(match (regexp-split #rx";" line)
[(list code name _ ...)
(hash-set! ht (string->number code 16) name)]))
(close-input-port data)
#`(define id '#,ht))]))
(define-unicode-lookup-table unicode-lookup-table)
;; unicode-name: number -> string
(define (unicode-name n)
(hash-ref unicode-lookup-table n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment