summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitsutoshiAoe <>2014-04-22 08:21:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2014-04-22 08:21:00 (GMT)
commit9034f717248275df59b53d4d3234fc35b5838881 (patch)
treeb5c49bec04cef772c64a6c465d66c5d7840da5a6
parentdce47b05bd9c64d2e398248eb4b4940606d3ea3c (diff)
version 0.2.10.2.1
-rw-r--r--CHANGELOG.md4
-rw-r--r--influxdb.cabal4
-rw-r--r--src/Database/InfluxDB/TH.hs3
-rw-r--r--src/Database/InfluxDB/Types/Internal.hs23
4 files changed, 29 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8303369..6731572 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## v0.2.1 - 2014-04-22
+
+* Add `stripPrefixSnake`
+
## v0.2.0.1 - 2014-04-17
* Drop unnecessary dependency on `scientific` when using old `aeson`.
diff --git a/influxdb.cabal b/influxdb.cabal
index d51f3c3..48491c4 100644
--- a/influxdb.cabal
+++ b/influxdb.cabal
@@ -1,5 +1,5 @@
name: influxdb
-version: 0.2.0.1
+version: 0.2.1
synopsis: Haskell client library for InfluxDB
description: Haskell client library for InfluxDB
homepage: https://github.com/maoe/influxdb-haskell
@@ -113,5 +113,5 @@ source-repository head
source-repository this
type: git
- tag: v0.2.0.1
+ tag: v0.2.1
location: https://github.com/maoe/influxdb-haskell.git
diff --git a/src/Database/InfluxDB/TH.hs b/src/Database/InfluxDB/TH.hs
index b3527f0..840db7d 100644
--- a/src/Database/InfluxDB/TH.hs
+++ b/src/Database/InfluxDB/TH.hs
@@ -12,6 +12,7 @@ module Database.InfluxDB.TH
, deriveFromSeriesData
, stripPrefixLower
+ , stripPrefixSnake
) where
import Control.Applicative
import Language.Haskell.TH
@@ -21,7 +22,7 @@ import qualified Data.Vector as V
import Database.InfluxDB.Decode
import Database.InfluxDB.Encode
-import Database.InfluxDB.Types.Internal (stripPrefixLower)
+import Database.InfluxDB.Types.Internal
data Options = Options
{ fieldLabelModifier :: String -> String
diff --git a/src/Database/InfluxDB/Types/Internal.hs b/src/Database/InfluxDB/Types/Internal.hs
index 95d4f5d..0707d93 100644
--- a/src/Database/InfluxDB/Types/Internal.hs
+++ b/src/Database/InfluxDB/Types/Internal.hs
@@ -2,8 +2,9 @@
module Database.InfluxDB.Types.Internal
( stripPrefixOptions
, stripPrefixLower
+ , stripPrefixSnake
) where
-import Data.Char (toLower)
+import Data.Char (isUpper, toLower)
-------------------------------------------------
-- Conditional imports
@@ -24,7 +25,25 @@ stripPrefixOptions :: String -> String -> String
stripPrefixOptions = stripPrefixLower
#endif
-stripPrefixLower :: String -> String -> String
+-- | Strip the prefix then convert to 'lowerCamelCase'.
+stripPrefixLower
+ :: String -- ^ Prefix to be stripped
+ -> String -- ^ Input string
+ -> String
stripPrefixLower prefix xs = case drop (length prefix) xs of
[] -> error "Insufficient length of field name"
c:cs -> toLower c : cs
+
+-- | Strip the prefix then convert to 'snake_case'.
+stripPrefixSnake
+ :: String -- ^ Prefix to be stripped
+ -> String -- ^ Input string
+ -> String
+stripPrefixSnake prefix xs = case drop (length prefix) xs of
+ [] -> error "Insufficient length of field name"
+ cs -> toSnake cs
+ where
+ toSnake = dropWhile (== '_') . foldr f []
+ f c cs
+ | isUpper c = '_':toLower c:cs
+ | otherwise = c:cs