gdritter repos config-ini / 87208af
Merge lookup* functions with new RawIni naming Getty Ritter 6 years ago
1 changed file(s) with 38 addition(s) and 0 deletion(s). Collapse all Expand all
1111 -- * serializing and deserializing
1212 , parseRawIni
1313 , printRawIni
14 -- * inspection
15 , lookupInSection
16 , lookupSection
17 , lookupValue
1418 ) where
1519
1620 import Control.Monad (void)
213217 Builder.fromText (vValue val) <>
214218 Builder.singleton '\n'
215219
220 -- | Look up an Ini value by section name and key. Returns the sequence
221 -- of matches.
222 lookupInSection :: Text
223 -- ^ The section name. Will be normalized prior to
224 -- comparison.
225 -> Text
226 -- ^ The key. Will be normalized prior to comparison.
227 -> RawIni
228 -- ^ The Ini to search.
229 -> Seq.Seq Text
230 lookupInSection sec opt ini =
231 vValue <$> (F.asum (lookupValue opt <$> lookupSection sec ini))
232
233 -- | Look up an Ini section by name. Returns a sequence of all matching
234 -- section records.
235 lookupSection :: Text
236 -- ^ The section name. Will be normalized prior to
237 -- comparison.
238 -> RawIni
239 -- ^ The Ini to search.
240 -> Seq.Seq IniSection
241 lookupSection name ini =
242 snd <$> (Seq.filter ((== normalize name) . fst) $ fromRawIni ini)
243
244 -- | Look up an Ini key's value in a given section by the key. Returns
245 -- the sequence of matches.
246 lookupValue :: Text
247 -- ^ The key. Will be normalized prior to comparison.
248 -> IniSection
249 -- ^ The section to search.
250 -> Seq.Seq IniValue
251 lookupValue name section =
252 snd <$> Seq.filter ((== normalize name) . fst) (isVals section)
253
216254 {- $main
217255
218256 __Warning!__ This module is subject to change in the future, and therefore should