diff options
author | Joris | 2021-01-03 13:40:40 +0100 |
---|---|---|
committer | Joris | 2021-01-03 13:54:20 +0100 |
commit | 11052951b74b9ad4b6a9412ae490086235f9154b (patch) | |
tree | 64526ac926c1bf470ea113f6cac8a33158684e8d /common/src/Common/Validation/Atomic.hs | |
parent | 371449b0e312a03162b78797b83dee9d81706669 (diff) | |
download | budget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.gz budget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.bz2 budget-11052951b74b9ad4b6a9412ae490086235f9154b.zip |
Rewrite in Rust
Diffstat (limited to 'common/src/Common/Validation/Atomic.hs')
-rw-r--r-- | common/src/Common/Validation/Atomic.hs | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/common/src/Common/Validation/Atomic.hs b/common/src/Common/Validation/Atomic.hs deleted file mode 100644 index 9c21e14..0000000 --- a/common/src/Common/Validation/Atomic.hs +++ /dev/null @@ -1,61 +0,0 @@ -module Common.Validation.Atomic - ( color - , day - , minLength - , nonEmpty - , nonNullNumber - , number - , password - ) where - -import qualified Data.Char as Char -import Data.Text (Text) -import qualified Data.Text as T -import Data.Time.Calendar (Day) -import Data.Validation (Validation) -import qualified Data.Validation as V -import qualified Text.Read as T - -import qualified Common.Msg as Msg -import qualified Common.Util.Time as Time - -minLength :: Int -> Text -> Validation Text Text -minLength l = - V.validate - (Msg.get (Msg.Form_MinChars l)) - (\t -> if T.length t >= l then Just t else Nothing) - -nonEmpty :: Text -> Validation Text Text -nonEmpty = - V.validate - (Msg.get Msg.Form_NonEmpty) - (\t -> if (not . T.null $ t) then Just t else Nothing) - -number :: Text -> Validation Text Int -number input = - case (T.readMaybe . T.unpack $ input) of - Just n -> V.Success n - _ -> V.Failure (Msg.get Msg.Form_InvalidInt) - -nonNullNumber :: Int -> Validation Text Int -nonNullNumber = - V.validate - (Msg.get Msg.Form_NonNullNumber) - (\n -> if n /= 0 then Just n else Nothing) - -day :: Text -> Validation Text Day -day str = - case Time.parseDay str of - Just d -> V.Success d - Nothing -> V.Failure $ Msg.get Msg.Form_InvalidDate - -color :: Text -> Validation Text Text -color str = - if T.take 1 str == "#" && T.all Char.isHexDigit (T.drop 1 str) then - V.Success str - - else - V.Failure (Msg.get Msg.Form_InvalidColor) - -password :: Text -> Validation Text Text -password = minLength 8 |