Raw: modify lookup functions to drop the normalized names since they can be recovered anyway
Jonathan Daugherty
8 years ago
| 207 | 207 | normalizeKey :: Text -> Text |
| 208 | 208 | normalizeKey = normalizeSectionName |
| 209 | 209 | |
| 210 | -- | Look up an Ini value by section name and key. Returns Nothing if | |
| 211 | -- either the section or key could not be found. | |
| 210 | -- | Look up an Ini value by section name and key. Returns the sequence | |
| 211 | -- of matches. | |
| 212 | 212 | lookupInSection :: Text |
| 213 | 213 | -- ^ The section name. Will be normalized prior to |
| 214 | 214 | -- comparison. |
| 218 | 218 | -- ^ The Ini to search. |
| 219 | 219 | -> Seq.Seq Text |
| 220 | 220 | lookupInSection sec opt ini = |
| 221 |
vValue <$> |
|
| 221 | vValue <$> (F.asum (lookupValue opt <$> lookupSection sec ini)) | |
| 222 | 222 | |
| 223 | 223 | -- | Look up an Ini section by name. Returns a sequence of all matching |
| 224 |
-- section records |
|
| 224 | -- section records. | |
| 225 | 225 | lookupSection :: Text |
| 226 | 226 | -- ^ The section name. Will be normalized prior to |
| 227 | 227 | -- comparison. |
| 228 | 228 | -> Ini |
| 229 | 229 | -- ^ The Ini to search. |
| 230 |
-> Seq.Seq |
|
| 230 | -> Seq.Seq IniSection | |
| 231 | 231 | lookupSection name ini = |
| 232 |
|
|
| 232 | snd <$> (Seq.filter ((== normalizeSectionName name) . fst) $ fromIni ini) | |
| 233 | 233 | |
| 234 | 234 | -- | Look up an Ini key's value in a given section by the key. Returns |
| 235 | -- Nothing if the key could not be found. Otherwise returns the IniValue | |
| 236 | -- and its normalized name. | |
| 235 | -- the sequence of matches. | |
| 237 | 236 | lookupValue :: Text |
| 238 | 237 | -- ^ The key. Will be normalized prior to comparison. |
| 239 | 238 | -> IniSection |
| 240 | 239 | -- ^ The section to search. |
| 241 |
-> Seq.Seq |
|
| 240 | -> Seq.Seq IniValue | |
| 242 | 241 | lookupValue name section = |
| 243 |
|
|
| 242 | snd <$> Seq.filter ((== normalizeKey name) . fst) (isVals section) | |
| 244 | 243 | |
| 245 | 244 | {- $main |
| 246 | 245 | |