Name: Anonymous 2010-06-05 0:56
Is there any script, preferably bash or Perl, that will convert normal ASCII ("deal") into wide-width latin ("deal")?
Thanks.
Thanks.
#!/usr/bin/env scheme-script
; Hey Emacs!, This is a -*- Scheme -*- file
;;; fullwidth.ss
; Takes n command line arguments, and returns n lines with each argument
; string converted to be fullwidth
; Example:
; fullwidth "can i play with magic?"
; => can i play with magic?
(import (rnrs) (only (srfi :13) string-map))
; figure out the offset
; notice that the first 'a' is fullwidth
(define offset (- (char->integer #\a)
(char->integer #\a)))
(define (char+ char int)
(integer->char (+ int (char->integer char))))
(define fullwidth-symbols
; various other fullwidth symbols according to
; the unicode standard
'((#\x00A2 . #\xFFE0)
(#\x00A3 . #\xFFE1)
(#\x00AC . #\xFFE2)
(#\x00AF . #\xFFE3)
(#\x00A6 . #\xFFE4)
(#\x00A5 . #\xFFE5)
(#\x20A9 . #\xFFE6)))
(define (char-fullwidth x)
(cond ((char=? x #\space)
#\ ) ;special case for fullwidth space
((char<=? #\! x #\~)
(char+ x offset))
((assoc x fullwidth-symbols) => cdr)
(else x)))
(define (string-fullwidth s)
(string-map char-fullwidth s))
(define (main)
(let ((argv (cdr (command-line))))
(for-each (lambda (x)
(display (string-fullwidth x))
(newline))
argv)))
(main)