mirror of
https://github.com/typeable/inflections-hs.git
synced 2024-09-11 06:05:33 +03:00
Merge pull request #3 from mecampbellsoup/hlinting
Refactoring/style changes according to HLint.
This commit is contained in:
commit
20f56d25e6
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Ignore compiled dist directory
|
||||
/dist
|
@ -8,7 +8,7 @@ import Data.Char (toUpper, toLower)
|
||||
camelize
|
||||
:: [Word] -- ^ Input Words to separate with underscores
|
||||
-> String -- ^ The camelized String
|
||||
camelize ws = camelizeCustom True ws
|
||||
camelize = camelizeCustom True
|
||||
|
||||
-- |Turns an input Word List into a CamelCase String.
|
||||
camelizeCustom
|
||||
|
@ -10,7 +10,7 @@ import Data.Char (toUpper)
|
||||
humanize
|
||||
:: [Word] -- ^ List of Words, first of which will be capitalized
|
||||
-> String -- ^ The humanized output
|
||||
humanize = intercalate " " . map caseForWord . isFirstList
|
||||
humanize = unwords . map caseForWord . isFirstList
|
||||
|
||||
-- |Returns list with Bool indicating if an element is first.
|
||||
isFirstList :: [a] -> [(a, Bool)]
|
||||
|
@ -11,4 +11,4 @@ import Text.Inflections.Parse.Types
|
||||
import Control.Applicative ((<$>))
|
||||
|
||||
acronym :: P.Stream s m Char => [String] -> P.ParsecT s u m Word
|
||||
acronym as = Acronym <$> (P.choice $ map (Prim.try . C.string) as)
|
||||
acronym as = Acronym <$> P.choice (map (Prim.try . C.string) as)
|
||||
|
@ -15,9 +15,9 @@ parseSnakeCase acronyms = parse (parser acronyms) "(unknown)"
|
||||
|
||||
parser :: Stream s m Char => [String] -> ParsecT s u m [Word]
|
||||
parser acronyms = do
|
||||
ws <- (acronym acronyms <|> word) `sepBy` (char '_')
|
||||
ws <- (acronym acronyms <|> word) `sepBy` char '_'
|
||||
eof
|
||||
return ws
|
||||
|
||||
word :: Stream s m Char => ParsecT s u m Word
|
||||
word = Word <$> ((many1 lower) <|> (many1 digit))
|
||||
word = Word <$> (many1 lower <|> many1 digit)
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Text.Inflections.Parse.Types ( Word(..) ) where
|
||||
|
||||
-- |A 'String' that should be kept whole through applied inflections
|
||||
-- | A 'String' that should be kept whole through applied inflections
|
||||
data Word
|
||||
|
||||
-- | A word that may be transformed by inflection
|
||||
|
@ -9,7 +9,7 @@ import Data.Char (toUpper)
|
||||
titleize
|
||||
:: [Word] -- ^ List of Words, first of which will be capitalized
|
||||
-> String -- ^ The titleized String
|
||||
titleize s = intercalate " " $ map upperCaseWord s
|
||||
titleize s = unwords $ map upperCaseWord s
|
||||
|
||||
upperCaseWord :: Word -> String
|
||||
upperCaseWord (Word (c:cs)) = toUpper c : cs
|
||||
|
@ -8,6 +8,7 @@ import Text.Inflections.Parameterize ( Transliterations )
|
||||
import Text.Inflections.Data (defaultMap)
|
||||
|
||||
import Data.Char (isAscii)
|
||||
import Data.Maybe(fromMaybe)
|
||||
|
||||
import qualified Data.Map as Map
|
||||
|
||||
@ -26,6 +27,4 @@ transliterateCustom replacement ts = concatMap lookupCharTransliteration
|
||||
if isAscii c then -- Don't bother looking up Chars in ASCII range
|
||||
[c]
|
||||
else
|
||||
case Map.lookup c ts of
|
||||
Nothing -> replacement
|
||||
Just val -> val
|
||||
fromMaybe replacement (Map.lookup c ts)
|
||||
|
@ -30,6 +30,6 @@ tests = [ testGroup "humanize"
|
||||
----------------------------------------------------
|
||||
|
||||
test_humanize1 = "Employee salary" @?=
|
||||
(humanize [Word "employee", Word "salary"])
|
||||
humanize [Word "employee", Word "salary"]
|
||||
|
||||
test_humanize2 = "Underground" @?= (humanize [Word "underground"])
|
||||
test_humanize2 = "Underground" @?= humanize [Word "underground"]
|
||||
|
@ -64,7 +64,7 @@ isRight (Left _) = False
|
||||
isRight (Right _) = True
|
||||
|
||||
|
||||
test_dasherize1 = "foo-bar" @?= (dasherize [Word "foo", Word "bar"])
|
||||
test_dasherize1 = "foo-bar" @?= dasherize [Word "foo", Word "bar"]
|
||||
|
||||
prop_parameterize1 :: String -> Bool
|
||||
prop_parameterize1 sf = all (`elem` (alphaNumerics ++ "-_")) $
|
||||
|
@ -30,5 +30,5 @@ tests = [ testGroup "titleize"
|
||||
----------------------------------------------------
|
||||
|
||||
test_titleize1 = "Employee Salary" @?=
|
||||
(titleize [Word "Employee", Word "Salary"])
|
||||
test_titleize2 = "Underground" @?= (titleize [Word "underground"])
|
||||
titleize [Word "Employee", Word "Salary"]
|
||||
test_titleize2 = "Underground" @?= titleize [Word "underground"]
|
||||
|
@ -27,4 +27,4 @@ tests = [testGroup "underscore"
|
||||
]
|
||||
]
|
||||
|
||||
test_underscore = "test_this" @?= (underscore [Word "test", Word "this"])
|
||||
test_underscore = "test_this" @?= underscore [Word "test", Word "this"]
|
||||
|
Loading…
Reference in New Issue
Block a user