gdritter repos config-ini / 60070c0
Raw: modify lookup functions to drop the normalized names since they can be recovered anyway Jonathan Daugherty 6 years ago
1 changed file(s) with 9 addition(s) and 10 deletion(s). Collapse all Expand all
207207 normalizeKey :: Text -> Text
208208 normalizeKey = normalizeSectionName
209209
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.
212212 lookupInSection :: Text
213213 -- ^ The section name. Will be normalized prior to
214214 -- comparison.
218218 -- ^ The Ini to search.
219219 -> Seq.Seq Text
220220 lookupInSection sec opt ini =
221 vValue <$> snd <$> (F.asum (lookupValue opt <$> snd <$> lookupSection sec ini))
221 vValue <$> (F.asum (lookupValue opt <$> lookupSection sec ini))
222222
223223 -- | Look up an Ini section by name. Returns a sequence of all matching
224 -- section records along with their normalized names.
224 -- section records.
225225 lookupSection :: Text
226226 -- ^ The section name. Will be normalized prior to
227227 -- comparison.
228228 -> Ini
229229 -- ^ The Ini to search.
230 -> Seq.Seq (Text, IniSection)
230 -> Seq.Seq IniSection
231231 lookupSection name ini =
232 Seq.filter ((== normalizeSectionName name) . fst) $ fromIni ini
232 snd <$> (Seq.filter ((== normalizeSectionName name) . fst) $ fromIni ini)
233233
234234 -- | 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.
237236 lookupValue :: Text
238237 -- ^ The key. Will be normalized prior to comparison.
239238 -> IniSection
240239 -- ^ The section to search.
241 -> Seq.Seq (Text, IniValue)
240 -> Seq.Seq IniValue
242241 lookupValue name section =
243 Seq.filter ((== normalizeKey name) . fst) (isVals section)
242 snd <$> Seq.filter ((== normalizeKey name) . fst) (isVals section)
244243
245244 {- $main
246245