Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a titleCase function

  • Loading branch information...
commit 54ff4c80e8759c6def2381dd8c51836a537cea85 1 parent 07d97e9
@mightybyte mightybyte authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/Snap/Extras/TextUtils.hs
View
14 src/Snap/Extras/TextUtils.hs
@@ -5,13 +5,15 @@ module Snap.Extras.TextUtils
, showT
, readBS
, showBS
+ , titleCase
) where
-------------------------------------------------------------------------------
import qualified Data.ByteString.Char8 as B
-import Data.ByteString.Char8
+import Data.ByteString.Char8 (ByteString)
+import Data.Char
import qualified Data.Text as T
-import Data.Text
+import Data.Text (Text)
import Safe
-------------------------------------------------------------------------------
@@ -33,4 +35,10 @@ readBS :: (Read a) => ByteString -> a
readBS = readNote "Can't read value in readBS" . B.unpack
maybeEither (Left e) = Nothing
-maybeEither (Right x) = Just x
+maybeEither (Right x) = Just x
+
+
+titleCase :: Text -> Text
+titleCase = T.unwords . map upFirst . T.words
+ where
+ upFirst str = T.cons (toUpper $ T.head str) (T.tail str)
Please sign in to comment.
Something went wrong with that request. Please try again.