packages feed

deunicode (empty) → 0.1

raw patch · 4 files changed

+108/−0 lines, 4 filesdep +basedep +bytestringdep +utf8-stringsetup-changed

Dependencies added: base, bytestring, utf8-string

Files

+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2010 Benjamin Franksen++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ deunicode.cabal view
@@ -0,0 +1,22 @@+name:               deunicode+version:            0.1+synopsis:           Get rid of unicode (utf-8) symbols in Haskell sources+description:        A very simple-minded program to replace utf-8 encoded+                    unicode operators in Haskell source files with their+                    equivalent in ascii. It takes no arguments and acts as+                    a pure filter from stdin to stdout.+category:           Codec+license:            MIT+license-file:       LICENSE+author:             Ben Franksen <ben.franksen@online.de>+maintainer:         Ben Franksen <ben.franksen@online.de>+cabal-version:      >= 1.6+build-type:         Simple++executable          deunicode+    main-is:            deunicode.hs+    build-depends:      base == 4.2.*, bytestring == 0.9.*, utf8-string == 0.3.*++source-repository   head+    type:               darcs+    location:           http://code.haskell.org/~bfr/deunicode/
+ deunicode.hs view
@@ -0,0 +1,64 @@+import Prelude (return,otherwise,(>>),(>>=),(<),Maybe(..))+import Data.Char (ord,isAscii)+import qualified Data.ByteString.Lazy as B+import qualified Data.ByteString.Lazy.UTF8 as U+import qualified System.IO as S++expand_haskell_op c = case ord c of+  0x00AC -> S.putStr "not"		{- NOT SIGN -}+  0x00F7 -> S.putStr "/"		{- DIVISION SIGN -}+  0x03B1 -> S.putStr "a"		{- GREEK SMALL LETTER ALPHA -}+  0x03B2 -> S.putStr "b"		{- GREEK SMALL LETTER BETA -}+  0x03B3 -> S.putStr "c"		{- GREEK SMALL LETTER GAMMA -}+  0x03B4 -> S.putStr "d"		{- GREEK SMALL LETTER DELTA -}+  0x03B5 -> S.putStr "epsilon"		{- GREEK SMALL LETTER EPSILON -}+  0x03C0 -> S.putStr "pi"		{- GREEK SMALL LETTER PI -}+  0x2042 -> S.putStr "***"		{- ASTERISM -}+  0x2190 -> S.putStr "<-"		{- LEFTWARDS ARROW -}+  0x2192 -> S.putStr "->"		{- RIGHTWARDS ARROW -}+  0x21D0 -> S.putStr "<="		{- LEFTWARDS DOUBLE ARROW -}+  0x21D2 -> S.putStr "=>"		{- RIGHTWARDS DOUBLE ARROW -}+  0x2200 -> S.putStr "forall"		{- FOR ALL -}+  0x2208 -> S.putStr "`elem`"		{- ELEMENT OF -}+  0x2209 -> S.putStr "`notElem`"	{- NOT AN ELEMENT OF -}+  0x2216 -> S.putStr "\\\\"		{- SET MINUS -}+  0x2218 -> S.putStr "."		{- RING OPERATOR -}+  0x2227 -> S.putStr "&&"		{- LOGICAL AND -}+  0x2228 -> S.putStr "||"		{- LOGICAL OR -}+  0x2229 -> S.putStr "`intersect`"	{- INTERSECTION -}+  0x222A -> S.putStr "`union`"		{- UNION -}+  0x2237 -> S.putStr "::"		{- PROPORTION -}+  0x2260 -> S.putStr "/="		{- NOT EQUAL TO -}+  0x2261 -> S.putStr "=="		{- IDENTICAL TO -}+  0x2262 -> S.putStr "/="		{- NOT IDENTICAL TO -}+  0x2264 -> S.putStr "<="		{- LESS-THAN OR EQUAL TO -}+  0x2265 -> S.putStr ">="		{- GREATER-THAN OR EQUAL TO -}+  0x226B -> S.putStr ">>"		{- MUCH GREATER-THAN -}+  0x226E -> S.putStr ">="		{- NOT LESS-THAN -}+  0x226F -> S.putStr "<="		{- NOT GREATER-THAN -}+  0x2295 -> S.putStr "`mappend`"	{- CIRCLED PLUS -}+  0x229B -> S.putStr "<*>"		{- CIRCLED ASTERISK OPERATOR -}+  0x22A5 -> S.putStr "undefined"	{- UP TACK -}+  0x22C5 -> S.putStr "*"		{- DOT OPERATOR -}+  0x22D8 -> S.putStr "<<<"		{- VERY MUCH LESS-THAN -}+  0x22D9 -> S.putStr ">>>"		{- VERY MUCH GREATER-THAN -}+  0x29FA -> S.putStr "++"		{- DOUBLE PLUS -}+  0x29FB -> S.putStr "+++"		{- TRIPLE PLUS -}+  0x2AF4 -> S.putStr "|||"		{- TRIPLE VERTICAL BAR BINARY RELATION -}+  _      -> S.putChar c++deunicode s+  | B.null s  = return ()+  | otherwise = B.putStr ascii >> deunicode' rest+  where+    (ascii,rest) = U.span isAscii s++deunicode' s = expand nonascii >> deunicode rest+  where+    (nonascii,rest) = U.break isAscii s++expand s = case U.decode s of+  Nothing       -> return ()+  Just (c,rest) -> expand_haskell_op c++main = B.getContents >>= deunicode