>>46
Why, in this day and age, is any program not utf8 by default?
Name:
Anonymous2010-06-06 0:02
>>47
because not every program needs a bunch of bullshit code to handle a variable-length encoding.
Name:
Anonymous2010-06-06 15:49
Shocking, not nearly enough “Toy language” implementations. Here is my overly-engineered Scheme version
#!/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)))
fullwidthConvert :: String -> String
fullwidthConvert = map fullwidthConvert'
where
fullwidthConvert' c = case lookup c table of
Just c' -> c'
Nothing -> c
where
table = zip (' ' : ['!'..'~'])
('\x3000' : ['\xff01'..'\xff5e'])
main :: IO ()
main = U.getContents >>= U.putStr . fullwidthConvert
Name:
Anonymous2010-06-06 16:19
>>47
because some people don't care about gookspeak