git.iko.soy/typeable/pandoc
on master help sign in
+ 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

commit8fdf8c1d4cf33972a5fef7bf8dcf75478733da8c authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateTue 28 Aug 2007, 19:33 (19 years ago) parentcda7e7a
2 files changed+14−26
src/Main.hs+14−4 src/Text/Pandoc/Shared.hs−22
src/Main.hs+14−4
@@ -31,7 +31,7 @@ writers.
3131module Main where
3232import Text.Pandoc
3333import Text.Pandoc.UTF8
34−import Text.Pandoc.Shared ( joinWithSep, tabsToSpaces )
34+import Text.Pandoc.Shared ( joinWithSep )
3535import Text.Regex ( mkRegex, matchRegex )
3636import System.Environment ( getArgs, getProgName, getEnvironment )
3737import System.Exit ( exitWith, ExitCode (..) )
@@ -445,8 +445,18 @@ main = do
445445 Just cols -> read cols
446446 Nothing -> stateColumns defaultParserState
447447
448− let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
449− let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
448+ let tabsToSpacesInLine _ [] = ""
449+ tabsToSpacesInLine _ ('\r':[]) = "" -- remove DOS line-endings
450+ tabsToSpacesInLine spsToNextStop (x:xs) =
451+ if x == '\t'
452+ then if preserveTabs
453+ then x:(tabsToSpacesInLine tabStop xs)
454+ else replicate spsToNextStop ' ' ++
455+ tabsToSpacesInLine tabStop xs
456+ else x:(tabsToSpacesInLine (spsToNextStop - 1) xs)
457+
458+ let tabFilter = unlines . map (tabsToSpacesInLine tabStop) . lines
459+
450460 let startParserState =
451461 defaultParserState { stateParseRaw = parseRaw,
452462 stateTabStop = tabStop,
@@ -484,7 +494,7 @@ main = do
484494 (readSources sources) >>= (hPutStrLn output . toUTF8 .
485495 (writer writerOptions) .
486496 (reader startParserState) . tabFilter .
487− removeCRs . fromUTF8 . (joinWithSep "\n")) >>
497+ fromUTF8 . (joinWithSep "\n")) >>
488498 hClose output
489499
490500 where
src/Text/Pandoc/Shared.hs−22
@@ -34,7 +34,6 @@ module Text.Pandoc.Shared (
3434 substitute,
3535 joinWithSep,
3636 -- * Text processing
37− tabsToSpaces,
3837 backslashEscapes,
3938 escapeStringUsing,
4039 stripTrailingNewlines,
@@ -143,27 +142,6 @@ joinWithSep sep lst = foldr1 (\a b -> a ++ sep ++ b) lst
143142-- Text processing
144143--
145144
146−-- | Convert tabs to spaces (with adjustable tab stop).
147−tabsToSpaces :: Int -- ^ Tabstop
148− -> String -- ^ String to convert
149− -> String
150−tabsToSpaces tabstop str =
151− unlines $ map (tabsInLine tabstop tabstop) (lines str)
152−
153−-- | Convert tabs to spaces in one line.
154−tabsInLine :: Int -- ^ Number of spaces to next tab stop
155− -> Int -- ^ Tabstop
156− -> String -- ^ Line to convert
157− -> String
158−tabsInLine num tabstop [] = ""
159−tabsInLine num tabstop (c:cs) =
160− let (replacement, nextnum) = if c == '\t'
161− then (replicate num ' ', tabstop)
162− else if num > 1
163− then ([c], num - 1)
164− else ([c], tabstop)
165− in replacement ++ tabsInLine nextnum tabstop cs
166−
167145-- | Returns an association list of backslash escapes for the
168146-- designated characters.
169147backslashEscapes :: [Char] -- ^ list of special characters to escape