Commits

Luke Plant committed 38238aa

Replaced strict ByteStrings with lazy ByteStrings for consistency and simplicity

Comments (0)

Files changed (3)

src/Blog/DBUtils.hs

 import Blog.Utils (regexReplace)
 import Database.HDBC
 import GHC.Unicode (toLower)
-import qualified Data.ByteString.Char8 as B
+import qualified Data.ByteString.Lazy.Char8 as BL
 
-slugFromTitle title = map toLower $ B.unpack $
-                      regexReplace (B.pack "-+$") (B.pack "") $
-                      regexReplace (B.pack "[^A-Za-z0-9]+") (B.pack "-") (B.pack title)
+slugFromTitle title = map toLower $ BL.unpack $
+                      regexReplace (BL.pack "-+$") (BL.pack "") $
+                      regexReplace (BL.pack "[^A-Za-z0-9]+") (BL.pack "-") (BL.pack title)
 
 makeSlugGeneric cn title table = makeSlugGeneric' cn (slugFromTitle title) table 1
 makeSlugGeneric' cn slugBase table iter = do

src/Blog/Utils.hs

 import System.Environment(getArgs)
 import Text.Regex.Base
 import Text.Regex.PCRE
-import qualified Data.ByteString.Char8 as B
+import qualified Data.ByteString.Lazy.Char8 as BL
 
 regexReplace !re !rep !source = go source []
  where go str res =
-         if B.null str
-             then B.concat . reverse $ res
-             else case (str =~~ re) :: Maybe (B.ByteString, B.ByteString, B.ByteString) of
-               Nothing -> B.concat . reverse $ (str:res)
+         if BL.null str
+             then BL.concat . reverse $ res
+             else case (str =~~ re) :: Maybe (BL.ByteString, BL.ByteString, BL.ByteString) of
+               Nothing -> BL.concat . reverse $ (str:res)
                Just (bef, _ , aft) -> go aft (rep:bef:res)
 
 split :: String -> Char -> [String]
 import qualified Blog.Post as P
 import qualified Blog.Links as Links
 import qualified Blog.Settings as Settings
-import qualified Data.ByteString.Char8 as BS
 import qualified Data.ByteString.Lazy.Char8 as BL
 import qualified Data.ByteString.Lazy.UTF8 as UTF8
 import qualified Data.Map as Map
                              return p { P.post_raw = fixed,
                                         P.post_formatted = fixed }
           -- Fix dodgy stuff, and reinterpret as UTF8
-          fixCodes txt = UTF8.toString $ BL.pack $ BS.unpack $ regexReplace (BS.pack "
") (BS.pack "\n") (BS.pack txt)
+          fixCodes txt = UTF8.toString $ regexReplace (BL.pack "
") (BL.pack "\n") (BL.pack txt)
 
 readPostCategories = makeItems "postcategories.txt" mkPostCategory
     where mkPostCategory row = (read (row !! 0),