15 | 15 |
Ini
|
16 | 16 |
, ini
|
17 | 17 |
, getIniValue
|
| 18 |
, getRawIni
|
18 | 19 |
-- ** Parsing INI files
|
19 | 20 |
, parseIni
|
20 | 21 |
-- ** Serializing INI files
|
21 | |
, getIniText
|
| 22 |
, serializeIni
|
22 | 23 |
-- ** Updating INI Files
|
23 | 24 |
, updateIni
|
24 | 25 |
, setIniUpdatePolicy
|
25 | 26 |
, UpdatePolicy(..)
|
26 | 27 |
, UpdateCommentPolicy(..)
|
27 | 28 |
, defaultUpdatePolicy
|
28 | |
|
29 | 29 |
-- * Bidirectional Parser Types
|
30 | 30 |
-- $types
|
31 | 31 |
, IniSpec
|
|
156 | 156 |
-- value was created directly from a value and a specification, then
|
157 | 157 |
-- it will pretty-print an initial version of the file with the
|
158 | 158 |
-- comments and placeholder text specified in the spec.
|
159 | |
getIniText :: Ini s -> Text
|
160 | |
getIniText = printRawIni . getRawIni
|
| 159 |
serializeIni :: Ini s -> Text
|
| 160 |
serializeIni = printRawIni . getRawIni
|
161 | 161 |
|
162 | 162 |
-- | Get the underlying 'RawIni' value for the file.
|
163 | 163 |
getRawIni :: Ini s -> RawIni
|
|
247 | 247 |
allOptional :: (Seq (Field s)) -> Bool
|
248 | 248 |
allOptional = all isOptional
|
249 | 249 |
where isOptional (Field _ fd) = fdSkipIfMissing fd
|
250 | |
isOptional (FieldMb _ fd) = fdSkipIfMissing fd
|
| 250 |
isOptional (FieldMb _ _) = True
|
251 | 251 |
|
252 | 252 |
data Section s = Section NormalizedText (Seq (Field s)) Bool
|
253 | 253 |
|
|
352 | 352 |
-- values associated with that field.
|
353 | 353 |
field :: Text -> FieldValue a -> FieldDescription a
|
354 | 354 |
field name value = FieldDescription
|
355 | |
{ fdName = normalize name
|
| 355 |
{ fdName = normalize (name <> " ")
|
356 | 356 |
, fdValue = value
|
357 | 357 |
, fdComment = Seq.empty
|
358 | 358 |
, fdDummy = Nothing
|
|
510 | 510 |
, vDelimiter = '='
|
511 | 511 |
}
|
512 | 512 |
)
|
513 | |
toVal (Field l descr) =
|
514 | |
mkIniValue (fvEmit (fdValue descr) (get l s)) descr False
|
515 | |
toVal (FieldMb l descr) =
|
516 | |
case get l s of
|
517 | |
Nothing ->
|
| 513 |
toVal (Field l descr)
|
| 514 |
| Just dummy <- fdDummy descr =
|
| 515 |
mkIniValue dummy descr False
|
| 516 |
| otherwise =
|
| 517 |
mkIniValue (fvEmit (fdValue descr) (get l s)) descr False
|
| 518 |
toVal (FieldMb l descr)
|
| 519 |
| Just dummy <- fdDummy descr =
|
| 520 |
mkIniValue dummy descr True
|
| 521 |
| Just v <- get l s =
|
| 522 |
mkIniValue (fvEmit (fdValue descr) v) descr True
|
| 523 |
| otherwise =
|
518 | 524 |
mkIniValue "" descr True
|
519 | |
Just v ->
|
520 | |
mkIniValue (fvEmit (fdValue descr) v) descr True
|
521 | 525 |
|
522 | 526 |
-- | An 'UpdatePolicy' describes how to
|
523 | 527 |
data UpdatePolicy = UpdatePolicy
|
|
584 | 588 |
--doUpdateIni :: s -> s -> Spec s -> RawIni -> UpdatePolicy -> Either String (Ini s)
|
585 | 589 |
doUpdateIni :: s -> Ini s -> Either String (Ini s)
|
586 | 590 |
doUpdateIni s i@Ini { iniSpec = spec
|
587 | |
, iniDef = def
|
| 591 |
, iniDef = def
|
588 | 592 |
, iniPol = pol
|
589 | 593 |
} = do -- spec (RawIni ini) pol = do
|
590 | 594 |
let RawIni ini' = getRawIni i
|
|
756 | 760 |
mkComments cs
|
757 | 761 |
val = IniValue
|
758 | 762 |
{ vLineNo = 0
|
759 | |
, vName = actualText t <> " "
|
| 763 |
, vName = actualText t
|
760 | 764 |
, vValue = ""
|
761 | 765 |
, vComments = comments
|
762 | 766 |
, vCommentedOut = False
|