Skip to content

Instantly share code, notes, and snippets.

@ijp
Created September 7, 2014 19:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijp/071ef252f8e887741d5b to your computer and use it in GitHub Desktop.
Save ijp/071ef252f8e887741d5b to your computer and use it in GitHub Desktop.
#!/usr/local/bin/guile -s
!#
;; Hey emacs this is -*- scheme -*- code
(eval-when (compile load eval)
(set! %load-extensions '(".guile.sls" ".sls" ".ss" ".scm" "")))
(import (ijputils strings)
(only (rnrs) let*-values)
(ice-9 match))
; 𝘠𝘰𝘶𝘳 𝘴𝘵𝘳𝘢𝘵𝘦𝘨𝘪𝘦𝘴 𝘩𝘢𝘷𝘦 𝙣𝙤 𝘦𝘧𝘧𝘦𝘤𝘵 𝘰𝘯 𝘮𝘦.
; <offby1> ¿ɯǝlqoɹd ɹnoʎ s‚ʇɐɥʍ ;ʞɐǝds I uǝɥʍ ɹɐǝlɔ ʎlʇɔǝfɹǝd ɯ‚I
(define alphabetic "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
(define fraktur "𝔄𝔅ℭ𝔇𝔈𝔉𝔊ℌℑ𝔍𝔎𝔏𝔐𝔑𝔒𝔓𝔔ℜ𝔖𝔗𝔘𝔙𝔚𝔛𝔜ℨ𝔞𝔟𝔠𝔡𝔢𝔣𝔤𝔥𝔦𝔧𝔨𝔩𝔪𝔫𝔬𝔭𝔮𝔯𝔰𝔱𝔲𝔳𝔴𝔵𝔶𝔷")
(define fullwidth "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") ;; TODO: add a fullwidth space "hello there"
(define upside-down "")
;; small letter small capitals?
(define (frakturify string)
(string-translate string alphabetic fraktur))
(define (fullwidthify string)
(string-translate string alphabetic fullwidth))
(define (upside-downify string)
(string-reverse (string-translate string alphabetic upside-down)))
(define (lookup s)
;; TODO: create a translation specification structure
(match s
("fraktur" (values frakturify #f))
("fullwidth" (values fullwidthify #f))
("flip" (values upside-downify #t))
(else (values identity #f))))
(define (main args)
(let*-values ([(convert reverse?)
(lookup (basename (car args)))]
[(join) (if reverse?
(compose string-join reverse)
string-join)])
(display (join (map convert (cdr args))))
(newline)))
(setlocale LC_ALL "")
(main (command-line))
#!r6rs
(library (ijputils strings)
(export string-translate)
(import (rnrs base)
(only (srfi :13 strings) string-index string-map))
(define (string-translate string from to)
(define (convert c)
(cond ((string-index from c) =>
(lambda (i)
(string-ref to i)))
(else c)))
(string-map convert string))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment