@@ -3,6 +3,7 @@ module Data.Aeson.Inflections
3 , defaultFieldLabelModifier'
3 , defaultFieldLabelModifier'
4 , dropPrefix
4 , dropPrefix
5 , dropPrefixLower
5 , dropPrefixLower
6 , cutPrefix
7 , cutPrefix
7 , toUnderscore
8 , toUnderscore
@@ -12,7 +13,8 @@ module Data.Aeson.Inflections
12import Control.Lens
13import Control.Lens
13import Control.Monad
14import Control.Monad
14import Data.Char
15import Data.Char
15−import Data.Text as T (Text, pack, unpack)
16+import Data.Text (Text)
17+import qualified Data.Text as T (length, pack, unpack)
16import Data.Void
18import Data.Void
17import qualified Text.Inflections as I
19import qualified Text.Inflections as I
18import Text.Megaparsec.Error
20import Text.Megaparsec.Error
@@ -30,6 +32,12 @@ defaultFieldLabelModifier' = T.pack . defaultFieldLabelModifier . T.unpack
30dropPrefix :: String -> String
32dropPrefix :: String -> String
31dropPrefix = dropWhile (not . isUpper)
33dropPrefix = dropWhile (not . isUpper)
35+-- | The same as @Prelude.drop@, but takes a string, instead of a length.
36+-- This makes code more explicit (easier to see what exactly we are expecting to
38+dropByPrefixLength :: Text -> (String -> String)
39+dropByPrefixLength t = drop (T.length t)
33-- | Cuts the prefix or throws error if prefix does not match. For TH
41-- | Cuts the prefix or throws error if prefix does not match. For TH
34-- modifiers only
42-- modifiers only
35cutPrefix :: String -> String -> String
43cutPrefix :: String -> String -> String