@@ -31,7 +31,7 @@ module Text.Inflections.Types
33import Control.Monad.Catch
33import Control.Monad.Catch
34−import Data.Char (isSpace)
34+import Data.Char (isAlphaNum)
35import Data.Data (Data)
35import Data.Data (Data)
36import Data.Text (Text)
36import Data.Text (Text)
37import Data.Typeable (Typeable)
37import Data.Typeable (Typeable)
@@ -43,28 +43,30 @@ import qualified Data.Text as T
43import Prelude hiding (Word)
43import Prelude hiding (Word)
46−-- | Create a word from given 'Text'. The input should not contain spaces or
46+-- | Create a word from given 'Text'. The input should consist of only
47+-- alpha-numeric characters (no white spaces or punctuation)
47-- 'InflectionInvalidWord' will be thrown.
48-- 'InflectionInvalidWord' will be thrown.
49-- /since 0.3.0.0/
50-- /since 0.3.0.0/
51mkWord :: MonadThrow m => Text -> m (Word 'Normal)
52mkWord :: MonadThrow m => Text -> m (Word 'Normal)
52mkWord txt =
53mkWord txt =
53− if T.any isSpace txt
54+ if T.all isAlphaNum txt
55+ then return (Word txt)
54− then throwM (InflectionInvalidWord txt)
56+ else throwM (InflectionInvalidWord txt)
55− else return (Word txt)
57+
57−-- | Create an acronym from given 'Text'. The input should not contain
58+-- | Create an acronym from given 'Text'. The input should consist of only
58−-- spaces or 'InflectionInvalidAcronym' will be thrown. Acronym is different
59+-- alpha-numeric characters 'InflectionInvalidAcronym' will be thrown.
59−-- from normal word by that it may not be transformed by inflections.
60+-- Acronym is different from normal word by that it may not be transformed
61+-- by inflections (also see 'unSomeWord').
61-- /since 0.3.0.0/
63-- /since 0.3.0.0/
63mkAcronym :: MonadThrow m => Text -> m (Word 'Acronym)
65mkAcronym :: MonadThrow m => Text -> m (Word 'Acronym)
64mkAcronym txt =
66mkAcronym txt =
65− if T.any isSpace txt
67+ if T.all isAlphaNum txt
68+ then return (Word txt)
66− then throwM (InflectionInvalidAcronym txt)
69+ else throwM (InflectionInvalidAcronym txt)
67− else return (Word txt)
69-- | A 'Text' value that should be kept whole through applied inflections.
71-- | A 'Text' value that should be kept whole through applied inflections.