+ -- * Used for changing CamelCase names into something else.
import Control.DeepSeq (NFData(..))
+import Data.Char (toLower, isUpper)
import Data.Scientific (Scientific)
import Data.Hashable (Hashable(..))
, contentsFieldName = "contents"
+-- | Converts from CamelCase to another lower case, interspersing
+-- the character between all capital letters and their previous
+-- entries, except those capital letters that appear together,
+-- For use by Aeson template haskell calls.
+-- > camelTo '_' 'CamelCaseAPI' == "camel_case_api"
+camelTo :: Char -> String -> String
+camelTo c = lastWasCap True
+ lastWasCap :: Bool -- ^ Previous was a capital letter
+ -> String -- ^ The remaining string
+ lastWasCap prev (x : xs) = if isUpper x
+ then toLower x : lastWasCap True xs
+ else c : toLower x : lastWasCap True xs
+ else x : lastWasCap False xs