Commits

Luke Plant committed ce1e119

Use 'B' and 'LB' for ByteString/Lazy ByteString

Comments (0)

Files changed (3)

src/Blog/DBUtils.hs

 import Data.Convertible.Base (Convertible)
 import Database.HDBC
 import GHC.Unicode (toLower)
-import qualified Data.ByteString.Lazy.Char8 as BL
-import qualified Data.ByteString.Char8 as BS
+import qualified Data.ByteString.Lazy.Char8 as LB
+import qualified Data.ByteString.Char8 as B
 import qualified Data.List as List
 
-slugFromTitle title = map toLower $ BL.unpack $
-                      regexReplace (BL.pack "-+$") (BL.pack "") $
-                      regexReplace (BL.pack "[^A-Za-z0-9]+") (BL.pack "-") (BL.pack title)
+slugFromTitle title = map toLower $ LB.unpack $
+                      regexReplace (LB.pack "-+$") (LB.pack "") $
+                      regexReplace (LB.pack "[^A-Za-z0-9]+") (LB.pack "-") (LB.pack title)
 
 makeSlugGeneric cn title table = makeSlugGeneric' cn (slugFromTitle title) table 1
 makeSlugGeneric' cn slugBase table iter = do
   let slugAttempt =  (slugBase ++ makeSuffix iter);
   [[SqlByteString c]] <- quickQuery cn ("SELECT count(slug) FROM " ++ table ++ " WHERE slug = ?") [toSql slugAttempt];
-  case BS.unpack c of
+  case B.unpack c of
     "0" -> return slugAttempt
     _   -> makeSlugGeneric' cn slugBase table (iter + 1)
 
 sqlInIds ids = "(" ++ (concat $ List.intersperse "," $ map show ids) ++ ")"
 
 addLimitOffset sql limitOffset =
-    BL.unpack $ regexReplace (" \\$LIMITOFFSET") (BL.pack $ " " ++ limitOffset) (BL.pack sql)
+    LB.unpack $ regexReplace (" \\$LIMITOFFSET") (LB.pack $ " " ++ limitOffset) (LB.pack sql)
 
 -- return 'LIMIT/OFFSET' for a page (1 indexed), with an extra row
 -- which allows us to tell if there are more records

src/Blog/Utils.hs

 import System.Posix.Types
 import Text.Regex.Base
 import Text.Regex.PCRE
-import qualified Data.ByteString.Lazy.Char8 as BL
+import qualified Data.ByteString.Lazy.Char8 as LB
 
 
 -- | Replace using a regular expression. ByteString version
 regexReplace ::
     (RegexMaker Regex CompOption ExecOption source) =>
     source                 -- ^ regular expression
-    -> BL.ByteString       -- ^ replacement text
-    -> BL.ByteString       -- ^ text to operate on
-    -> BL.ByteString
+    -> LB.ByteString       -- ^ replacement text
+    -> LB.ByteString       -- ^ text to operate on
+    -> LB.ByteString
 regexReplace !regex !replacement !text = go text []
  where go str res =
-           if BL.null str
-           then BL.concat . reverse $ res
-           else case (str =~~ regex) :: Maybe (BL.ByteString, BL.ByteString, BL.ByteString) of
-                  Nothing -> BL.concat . reverse $ (str:res)
+           if LB.null str
+           then LB.concat . reverse $ res
+           else case (str =~~ regex) :: Maybe (LB.ByteString, LB.ByteString, LB.ByteString) of
+                  Nothing -> LB.concat . reverse $ (str:res)
                   Just (bef, _ , aft) -> go aft (replacement:bef:res)
 -- Could be implemented like this:
 -- > regexReplace r rep t = regexReplaceCustom r (const rep) t
 regexReplaceCustom ::
   (RegexMaker Regex CompOption ExecOption source) =>
   source                               -- ^ regular expression
-  -> (BL.ByteString -> BL.ByteString)  -- ^ transformation function applied to all matches
-  -> BL.ByteString                     -- ^ text to operate on
-  -> BL.ByteString
+  -> (LB.ByteString -> LB.ByteString)  -- ^ transformation function applied to all matches
+  -> LB.ByteString                     -- ^ text to operate on
+  -> LB.ByteString
 regexReplaceCustom !regex replacef !text = go text []
  where go str res =
-           if BL.null str
-           then BL.concat . reverse $ res
-           else case (str =~~ regex) :: Maybe (BL.ByteString, BL.ByteString, BL.ByteString) of
-                  Nothing -> BL.concat . reverse $ (str:res)
+           if LB.null str
+           then LB.concat . reverse $ res
+           else case (str =~~ regex) :: Maybe (LB.ByteString, LB.ByteString, LB.ByteString) of
+                  Nothing -> LB.concat . reverse $ (str:res)
                   Just (bef, match , aft) -> go aft (replacef(match):bef:res)
 
 
 import qualified Blog.Post as P
 import qualified Blog.Links as Links
 import qualified Blog.Settings as Settings
-import qualified Data.ByteString.Lazy.Char8 as BL
+import qualified Data.ByteString.Lazy.Char8 as LB
 import qualified Data.ByteString.Lazy.UTF8 as UTF8
 import qualified Data.Map as Map
 -- Migration script for the old data
                                        }
                                 else p
           -- Fix dodgy stuff, and reinterpret as UTF8
-          fixCodes txt = UTF8.toString $ regexReplace (BL.pack "&#10;") (BL.pack "\n") (BL.pack txt)
+          fixCodes txt = UTF8.toString $ regexReplace (LB.pack "&#10;") (LB.pack "\n") (LB.pack txt)
 
 readPostCategories = makeItems "postcategories.txt" mkPostCategory
     where mkPostCategory row = (read (row !! 0),