git.iko.soy/typeable/pandoc
on master help sign in
Rewrote convertTabs to use Text not String.
commit72b45f05ed361d9fd21c0b8625263cf69494fe7a authorJohn MacFarlane <jgm@berkeley.edu> dateSat 10 Jun 2017, 15:22 (9 years ago) parent28bea39
1 file changed+11−17
src/Text/Pandoc/Shared.hs+11−17
src/Text/Pandoc/Shared.hs+11−17
@@ -133,7 +133,7 @@ import qualified Data.ByteString as BS
133133import qualified Data.ByteString.Char8 as B8
134134import Data.ByteString.Base64 (decodeLenient)
135135import Data.Sequence (ViewR(..), ViewL(..), viewl, viewr)
136−import qualified Data.Text as T (toUpper, pack, unpack)
136+import qualified Data.Text as T
137137import Data.ByteString.Lazy (toChunks, fromChunks)
138138import qualified Data.ByteString.Lazy as BL
139139import Paths_pandoc (version)
@@ -279,26 +279,20 @@ escapeURI = escapeURIString (not . needsEscaping)
279279 where needsEscaping c = isSpace c || c `elem`
280280 ['<','>','|','"','{','}','[',']','^', '`']
281281
282−
283282-- | Convert tabs to spaces and filter out DOS line endings.
284283-- Tabs will be preserved if tab stop is set to 0.
285284tabFilter :: Int -- ^ Tab stop
286− -> String -- ^ Input
287− -> String
285+ -> T.Text -- ^ Input
286+ -> T.Text
288287tabFilter tabStop =
289− let go _ [] = ""
290− go _ ('\n':xs) = '\n' : go tabStop xs
291− go _ ('\r':'\n':xs) = '\n' : go tabStop xs
292− go _ ('\r':xs) = '\n' : go tabStop xs
293− go spsToNextStop ('\t':xs) =
294− if tabStop == 0
295− then '\t' : go tabStop xs
296− else replicate spsToNextStop ' ' ++ go tabStop xs
297− go 1 (x:xs) =
298− x : go tabStop xs
299− go spsToNextStop (x:xs) =
300− x : go (spsToNextStop - 1) xs
301− in go tabStop
288+ T.unlines . (if tabStop == 0 then id else map go) . T.lines
289+ where go s =
290+ let (s1, s2) = T.break (== '\t') s
291+ in if T.null s2
292+ then s1
293+ else s1 <> T.replicate
294+ (tabStop - (T.length s1 `mod` tabStop)) (T.pack " ")
295+ <> go (T.drop 1 s2)
302296
303297--
304298-- Date/time