aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-08-28 19:33:47 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-08-28 19:33:47 +0000
commit8fdf8c1d4cf33972a5fef7bf8dcf75478733da8c (patch)
treef2510a4e64846652d8eeb5fbda8f9eba313baf89 /src/Main.hs
parentcda7e7ac2143ca21bb3968c00fc9525d5f730339 (diff)
downloadpandoc-8fdf8c1d4cf33972a5fef7bf8dcf75478733da8c.tar.gz
+ Removed tabsToSpaces and tabsInLine from Text.Pandoc.Shared.
(They were used only in Main.) + Wrote new tabsToSpacesInLine function in Main that changes tabs to spaces and removes DOS line-endings in one pass, for a slight speed improvement. git-svn-id: https://pandoc.googlecode.com/svn/trunk@942 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/Main.hs b/src/Main.hs
index b1aa55982..4bd3982d2 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -31,7 +31,7 @@ writers.
module Main where
import Text.Pandoc
import Text.Pandoc.UTF8
-import Text.Pandoc.Shared ( joinWithSep, tabsToSpaces )
+import Text.Pandoc.Shared ( joinWithSep )
import Text.Regex ( mkRegex, matchRegex )
import System.Environment ( getArgs, getProgName, getEnvironment )
import System.Exit ( exitWith, ExitCode (..) )
@@ -445,8 +445,18 @@ main = do
Just cols -> read cols
Nothing -> stateColumns defaultParserState
- let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
- let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
+ let tabsToSpacesInLine _ [] = ""
+ tabsToSpacesInLine _ ('\r':[]) = "" -- remove DOS line-endings
+ tabsToSpacesInLine spsToNextStop (x:xs) =
+ if x == '\t'
+ then if preserveTabs
+ then x:(tabsToSpacesInLine tabStop xs)
+ else replicate spsToNextStop ' ' ++
+ tabsToSpacesInLine tabStop xs
+ else x:(tabsToSpacesInLine (spsToNextStop - 1) xs)
+
+ let tabFilter = unlines . map (tabsToSpacesInLine tabStop) . lines
+
let startParserState =
defaultParserState { stateParseRaw = parseRaw,
stateTabStop = tabStop,
@@ -484,7 +494,7 @@ main = do
(readSources sources) >>= (hPutStrLn output . toUTF8 .
(writer writerOptions) .
(reader startParserState) . tabFilter .
- removeCRs . fromUTF8 . (joinWithSep "\n")) >>
+ fromUTF8 . (joinWithSep "\n")) >>
hClose output
where