summaryrefslogtreecommitdiff
path: root/src/Database/InfluxDB/Types/Internal.hs
blob: 0507cd7bbd03be51c1e575151c330254a99c4fc9 (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
{-# LANGUAGE CPP #-}
module Database.InfluxDB.Types.Internal
  ( stripPrefixOptions
  ) 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 = stripPrefix name
  }
#else
stripPrefixOptions :: String -> String -> String
stripPrefixOptions = stripPrefix
#endif

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