[add sha1String routine
John Meacham <john@repetae.net>**20070825021232] hunk ./Util/SHA1.hs 28
-module Util.SHA1 (sha1file,sha1Bytes,hashToBytes,sha1Handle,ABCDE(..),Hash,emptyHash) where
+module Util.SHA1 (sha1String,sha1file,sha1Bytes,hashToBytes,sha1Handle,ABCDE(..),Hash,emptyHash) where
hunk ./Util/SHA1.hs 32
-import Data.Char (intToDigit)
+import Data.Char (intToDigit,ord)
hunk ./Util/SHA1.hs 46
+sha1String :: String -> Hash
+sha1String ss = sha1Bytes (toUTF ss) where
+    -- | Convert Unicode characters to UTF-8.
+    toUTF :: String -> [Word8]
+    toUTF [] = []
+    toUTF (x:xs) | ord x<=0x007F = (fromIntegral $ ord x):toUTF xs
+                 | ord x<=0x07FF = fromIntegral (0xC0 .|. ((ord x `shift` (-6)) .&. 0x1F)):
+                                   fromIntegral (0x80 .|. (ord x .&. 0x3F)):
+                                   toUTF xs
+                 | otherwise     = fromIntegral (0xE0 .|. ((ord x `shift` (-12)) .&. 0x0F)):
+                                   fromIntegral (0x80 .|. ((ord x `shift` (-6)) .&. 0x3F)):
+                                   fromIntegral (0x80 .|. (ord x .&. 0x3F)):
+                                   toUTF xs
+
+