git.iko.soy/typeable/pandoc
on master help sign in
Changed encodeUTF8 to toUTF8, decodeUTF8 to fromUTF8,

for clarity. git-svn-id: https://pandoc.googlecode.com/svn/trunk@692 788f1e2b-df1e-0410-8736-df70ead52e1b

commit30375bb84737bd9536a73fc1929c15c50a80a655 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateFri 13 Jul 2007, 06:34 (19 years ago) parentbd5a5d4
3 files changed+23−25
src/Main.hs+5−7 src/Text/Pandoc.hs+2−2 src/Text/Pandoc/UTF8.hs+16−16
src/Main.hs+5−7
@@ -30,8 +30,8 @@ writers.
3030-}
3131module Main where
3232import Text.Pandoc
33−import Text.Pandoc.UTF8 ( encodeUTF8, decodeUTF8 )
34−import Text.Pandoc.ASCIIMathML ( asciiMathMLScript )
33+import Text.Pandoc.UTF8
34+import Text.Pandoc.ASCIIMathML
3535import Text.Pandoc.Shared ( joinWithSep, tabsToSpaces )
3636import Text.Regex ( mkRegex, matchRegex )
3737import System.Environment ( getArgs, getProgName, getEnvironment )
@@ -439,9 +439,7 @@ main = do
439439 Nothing -> stateColumns defaultParserState
440440
441441 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
442− let addBlank str = str
443442 let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
444− let filter = tabFilter . addBlank . removeCRs
445443 let startParserState =
446444 defaultParserState { stateParseRaw = parseRaw,
447445 stateTabStop = tabStop,
@@ -475,10 +473,10 @@ main = do
475473 writerStrictMarkdown = strict,
476474 writerReferenceLinks = referenceLinks }
477475
478− (readSources sources) >>= (hPutStr output . encodeUTF8 .
476+ (readSources sources) >>= (hPutStr output . toUTF8 .
479477 (writer writerOptions) .
480− (reader startParserState) . filter .
481− decodeUTF8 . (joinWithSep "\n")) >>
478+ (reader startParserState) . tabFilter .
479+ removeCRs . fromUTF8 . (joinWithSep "\n")) >>
482480 hClose output
483481
484482 where
src/Text/Pandoc.hs+2−2
@@ -38,9 +38,9 @@ inline links:
3838> import Text.Pandoc
3939>
4040> markdownToRST :: String -> String
41−> markdownToRST = encodeUTF8 .
41+> markdownToRST = toUTF8 .
4242> (writeRST defaultWriterOptions {writerReferenceLinks = True}) .
43−> (readMarkdown defaultParserState) . decodeUTF8
43+> (readMarkdown defaultParserState) . fromUTF8
4444>
4545> main = interact markdownToRST
4646
src/Text/Pandoc/UTF8.hs+16−16
@@ -7,38 +7,38 @@
77-- Modified by Martin Norbaeck
88-- to pass illegal UTF-8 sequences through unchanged.
99module Text.Pandoc.UTF8 (
10− decodeUTF8,
11− encodeUTF8
10+ fromUTF8,
11+ toUTF8
1212 ) where
1313
1414-- From the Char module supplied with HBC.
1515
1616-- | Take a UTF-8 string and decode it into a Unicode string.
17−decodeUTF8 :: String -> String
18−decodeUTF8 "" = ""
19−decodeUTF8 (c:c':cs) | '\xc0' <= c && c <= '\xdf' &&
20− '\x80' <= c' && c' <= '\xbf' =
21− toEnum ((fromEnum c `mod` 0x20) * 0x40 + fromEnum c' `mod` 0x40) : decodeUTF8 cs
22−decodeUTF8 (c:c':c'':cs) | '\xe0' <= c && c <= '\xef' &&
17+fromUTF8 :: String -> String
18+fromUTF8 "" = ""
19+fromUTF8 (c:c':cs) | '\xc0' <= c && c <= '\xdf' &&
20+ '\x80' <= c' && c' <= '\xbf' =
21+ toEnum ((fromEnum c `mod` 0x20) * 0x40 + fromEnum c' `mod` 0x40) : fromUTF8 cs
22+fromUTF8 (c:c':c'':cs) | '\xe0' <= c && c <= '\xef' &&
2323 '\x80' <= c' && c' <= '\xbf' &&
2424 '\x80' <= c'' && c'' <= '\xbf' =
25− toEnum ((fromEnum c `mod` 0x10 * 0x1000) + (fromEnum c' `mod` 0x40) * 0x40 + fromEnum c'' `mod` 0x40) : decodeUTF8 cs
26−decodeUTF8 (c:cs) = c : decodeUTF8 cs
25+ toEnum ((fromEnum c `mod` 0x10 * 0x1000) + (fromEnum c' `mod` 0x40) * 0x40 + fromEnum c'' `mod` 0x40) : fromUTF8 cs
26+fromUTF8 (c:cs) = c : fromUTF8 cs
2727
2828-- | Take a Unicode string and encode it as a UTF-8 string.
29−encodeUTF8 :: String -> String
30−encodeUTF8 "" = ""
31−encodeUTF8 (c:cs) =
29+toUTF8 :: String -> String
30+toUTF8 "" = ""
31+toUTF8 (c:cs) =
3232 if c > '\x0000' && c < '\x0080' then
33− c : encodeUTF8 cs
33+ c : toUTF8 cs
3434 else if c < toEnum 0x0800 then
3535 let i = fromEnum c
3636 in toEnum (0xc0 + i `div` 0x40) :
3737 toEnum (0x80 + i `mod` 0x40) :
38− encodeUTF8 cs
38+ toUTF8 cs
3939 else
4040 let i = fromEnum c
4141 in toEnum (0xe0 + i `div` 0x1000) :
4242 toEnum (0x80 + (i `mod` 0x1000) `div` 0x40) :
4343 toEnum (0x80 + i `mod` 0x40) :
44− encodeUTF8 cs
44+ toUTF8 cs