summaryrefslogtreecommitdiff
path: root/src/Database/InfluxDB/Types/Internal.hs
blob: 95d4f5d71e562979d01d654733ae20e379ec6def (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# LANGUAGE CPP #-}
module Database.InfluxDB.Types.Internal
  ( stripPrefixOptions
  , stripPrefixLower
  ) where
import Data.Char (toLower)

-------------------------------------------------
-- Conditional imports

#if MIN_VERSION_aeson(0, 6, 2)
import Data.Aeson.TH (Options(..), defaultOptions)
#endif

-------------------------------------------------

#if MIN_VERSION_aeson(0, 6, 2)
stripPrefixOptions :: String -> Options
stripPrefixOptions name = defaultOptions
  { fieldLabelModifier = stripPrefixLower name
  }
#else
stripPrefixOptions :: String -> String -> String
stripPrefixOptions = stripPrefixLower
#endif

stripPrefixLower :: String -> String -> String
stripPrefixLower prefix xs = case drop (length prefix) xs of
  [] -> error "Insufficient length of field name"
  c:cs -> toLower c : cs