settings 0.2.1.0 → 0.2.2.0
raw patch · 4 files changed
+67/−6 lines, 4 files
Files
- NEWS +23/−0
- settings.cabal +2/−2
- src/Data/Settings.hs +5/−0
- src/Data/Settings/Route.hs +37/−4
NEWS view
@@ -3,6 +3,29 @@ +settings 0.2.2.0 -- 2015-12-17+==============================++General, build and documentation changes:++* (None)++New APIs, features and enhancements:++* Support arbitrary esc/sep chars in option paths, and allow escaping them.++Bug fixes:++* (None)++Dependency changes:++* (None)+++++ settings 0.2.1.0 -- 2015-10-17 ==============================
settings.cabal view
@@ -1,5 +1,5 @@ name: settings-version: 0.2.1.0+version: 0.2.2.0 synopsis: Runtime-editable program settings. description: This library aims to be a tool for constructing a settings management UI on@@ -27,7 +27,7 @@ source-repository head type: darcs- location: http://dev.rel4tion.org/fr33domlover/settings+ location: http://hub.darcs.net/fr33domlover/settings library exposed-modules: Data.Settings
src/Data/Settings.hs view
@@ -105,6 +105,11 @@ -- and to the option under it as @\"s.a\"@. And so on, we can have arbitrarily -- deep nesting of sections and options, e.g. @\"s.t.u.v.w.x.a\"@. --+-- It is possible for a section or option name to contain a period. In that+-- case, the period must be escaped using a backslash before it. To specify a+-- literal backslash, escape it too, i.e. use two backslashes. It is also+-- possible different separator characters instead of a period.+-- -- The low-level flexible way to define a settings tree is by using 'Option' -- value contructors directly. Let's define a simple flat tree with 4 options -- and no subsections.
src/Data/Settings/Route.hs view
@@ -15,7 +15,9 @@ module Data.Settings.Route ( parseRoute+ , parseRoute' , showRoute+ , showRoute' ) where @@ -25,7 +27,8 @@ -- | Split a path string into its components, if it's a valid path -- syntactically. parseRoute :: OptPath -> Maybe OptRoute-parseRoute "" = Just []+parseRoute = parseRoute' '\\' '.'+{-parseRoute "" = Just [] parseRoute s = case break (== '.') s of ("", _) -> Nothing@@ -33,9 +36,39 @@ (p, (c:cs)) -> case parseRoute cs of Nothing -> Nothing- Just ps -> Just $ p : ps+ Just ps -> Just $ p : ps-} +-- | Like 'parseRoute', but allows to choose the escape character (e.g. @'\'@)+-- and the path separator character (e.g. @'.'@).+parseRoute' :: Char -> Char -> OptPath -> Maybe OptRoute+parseRoute' esc sep = f [] ""+ where+ f [] "" "" = Just []+ f route "" "" = Nothing+ f route part "" = Just $ reverse $ reverse part : route+ f route part [c]+ | c == esc = Nothing+ | c == sep = Nothing+ | otherwise = f route (c : part) ""+ f route part (a:r@(b:s))+ | a == esc && b == esc = f route (esc : part) s+ | a == esc && b == sep = f route (sep : part) s+ | a == esc = Nothing+ | a == sep = f (reverse part : route) "" r+ | otherwise = f route (a : part) r+ -- | Create a string representation of a path, with the parts separated by--- periods.+-- periods, and literal periods escaped using backslashes. showRoute :: OptRoute -> OptPath-showRoute = intercalate "."+showRoute = showRoute' '\\' '.'++-- | Like 'showRoute', but allows to choose the escape character (e.g. @'\\'@)+-- and the path separator character (e.g. @'.'@).+showRoute' :: Char -> Char -> OptRoute -> OptPath+showRoute' esc sep = intercalate [sep] . map escape+ where+ escape = foldr f ""+ f c s+ | c == esc = esc : esc : s+ | c == sep = esc : sep : s+ | otherwise = c : s