1 Various Unicode-related utilities.
5 stringToUtf8, intsToUtf8
8 #include "HsVersions.h"
10 import Panic ( panic )
11 import Char ( chr, ord )
15 stringToUtf8 :: String -> String
16 stringToUtf8 s = intsToUtf8 (map ord s)
18 intsToUtf8 :: [Int] -> String
21 | c >= 1 && c <= 0x7F = chr c : intsToUtf8 s
22 | c < 0 = panic ("charToUtf8 ("++show c++")")
23 | c <= 0x7FF = chr (0xC0 + c `div` 0x40 ) :
24 chr (0x80 + c `mod` 0x40) :
26 | c <= 0xFFFF = chr (0xE0 + c `div` 0x1000 ) :
27 chr (0x80 + c `div` 0x40 `mod` 0x40) :
28 chr (0x80 + c `mod` 0x40) :
30 | c <= 0x10FFFF = chr (0xF0 + c `div` 0x40000 ) :
31 chr (0x80 + c `div` 0x1000 `mod` 0x40) :
32 chr (0x80 + c `div` 0x40 `mod` 0x40) :
33 chr (0x80 + c `mod` 0x40) :
35 | otherwise = panic ("charToUtf8 "++show c)