Merge lookup* functions with new RawIni naming
Getty Ritter
8 years ago
| 11 | 11 | -- * serializing and deserializing |
| 12 | 12 | , parseRawIni |
| 13 | 13 | , printRawIni |
| 14 | -- * inspection | |
| 15 | , lookupInSection | |
| 16 | , lookupSection | |
| 17 | , lookupValue | |
| 14 | 18 | ) where |
| 15 | 19 | |
| 16 | 20 | import Control.Monad (void) |
| 213 | 217 | Builder.fromText (vValue val) <> |
| 214 | 218 | Builder.singleton '\n' |
| 215 | 219 | |
| 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 | ||
| 216 | 254 | {- $main |
| 217 | 255 | |
| 218 | 256 | __Warning!__ This module is subject to change in the future, and therefore should |