Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Ini
- parseIni :: (Alternative m, MonadFail m) => String -> m Ini
- showIni :: Ini -> String
- data Key
- data SectionName
- empty :: Ini
- get :: IniValue a => Ini -> Key -> Maybe a
- set :: IniValue a => Ini -> Key -> a -> Ini
- remove :: Key -> Ini -> Ini
- modify :: (Maybe String -> Maybe String) -> Key -> Ini -> Ini
- toList :: Ini -> [(Key, String)]
- fromList :: [(Key, String)] -> Ini
- merge :: Ini -> Ini -> Ini
- readIniFile :: FilePath -> IO (Maybe Ini)
- writeIniFile :: FilePath -> Ini -> IO ()
- class IniValue a where
De/serializing INI files
An ordered, comment-preserving representation of an INI file.
parseIni :: (Alternative m, MonadFail m) => String -> m Ini Source #
Parses an INI file from the given string.
A valid INI file may contain zero or more lines, where each line is any of the following:
- A
[section header]
in square brackets; - a
key = value
pair; - a comment, starting with either
;
or#
; or - whitespace.
Note that a valid INI file must not contain duplicate section headers, and keys must be unique within their section. Section headers and keys are case-sensitive. Values must be contained on a single line. Whitespace is ignored at the start and end of each line, section header, key, and value.
Reading and modifying properties
A key into an INI file.
A valid key is either of the format "sect.prop"
or just "prop"
.
The first key will match the property prop
in section sect
,
and the second will match the property prop
outside of any section.
prop
must not begin with ;
or #
or contain a =
,
and sect
must not contain ]
. Both parts are case-sensitive.
data SectionName Source #
The name of an INI section.
Must not contain the character ']'
.
Instances
Eq SectionName Source # | |
Defined in Data.Tini.Types (==) :: SectionName -> SectionName -> Bool # (/=) :: SectionName -> SectionName -> Bool # | |
Ord SectionName Source # | |
Defined in Data.Tini.Types compare :: SectionName -> SectionName -> Ordering # (<) :: SectionName -> SectionName -> Bool # (<=) :: SectionName -> SectionName -> Bool # (>) :: SectionName -> SectionName -> Bool # (>=) :: SectionName -> SectionName -> Bool # max :: SectionName -> SectionName -> SectionName # min :: SectionName -> SectionName -> SectionName # | |
Read SectionName Source # | |
Defined in Data.Tini.Types readsPrec :: Int -> ReadS SectionName # readList :: ReadS [SectionName] # readPrec :: ReadPrec SectionName # readListPrec :: ReadPrec [SectionName] # | |
Show SectionName Source # | |
Defined in Data.Tini.Types showsPrec :: Int -> SectionName -> ShowS # show :: SectionName -> String # showList :: [SectionName] -> ShowS # | |
IsString SectionName Source # | |
Defined in Data.Tini.Types fromString :: String -> SectionName # |
get :: IniValue a => Ini -> Key -> Maybe a Source #
Returns the value at the given key, if it exists and is valid at
the function's result type.
See IniValue
for more information regarding how Haskell values are
encoded in INI files.
set :: IniValue a => Ini -> Key -> a -> Ini Source #
Sets the given key to the given value. If the key already exists, it will be overwritten.
New sections are added at the end of the given INI, and new properties are added at the end of their respective sections.
modify :: (Maybe String -> Maybe String) -> Key -> Ini -> Ini Source #
Modify the value at the given key in the given INI.
If the key exists, the given function will receive Just value
as its
argument, otherwise it will receive Nothing
.
If the given function returns Just new_value
, the given key will be
created or overwritten with new_value
. If it returns Nothing
, the
key will be deleted.
merge :: Ini -> Ini -> Ini Source #
Merge the given INIs. Values from the second INI override values from the first in cases where a key exists in both. Comments from the second INI are discarded.
Working with files
readIniFile :: FilePath -> IO (Maybe Ini) Source #
Attempt to read the given file as an INI.
Returns Nothing
if the file does not exist or can not be parsed as
an INI file.
Adding new types of INI properties
class IniValue a where Source #
Valid types for values of INI properties.
Default implementation uses show
and reads
for showValue
and readValue
respectively.
Nothing
showValue :: a -> String Source #
showValue :: Show a => a -> String Source #
Instances
IniValue Bool Source # | Valid values for booleans (case-insensitive): true, false, yes, no, t, f, y, n, 1, 0, on, off. |
IniValue Char Source # | |
IniValue Double Source # | |
IniValue Float Source # | |
IniValue Int Source # | |
IniValue Int8 Source # | |
IniValue Int16 Source # | |
IniValue Int32 Source # | |
IniValue Int64 Source # | |
IniValue Integer Source # | |
IniValue Word Source # | |
IniValue Word8 Source # | |
IniValue Word16 Source # | |
IniValue Word32 Source # | |
IniValue Word64 Source # | |
IniValue String Source # | Strings are the raw values of properties, with whitespace trimmed on both ends. They are not enclosed in quotes. |
IniValue a => IniValue [a] Source # | Lists are zero or more valid values, separated by commas.
To include a comma in a string within a list, escape it using |
IniValue a => IniValue (Maybe a) Source # |
|
(IniValue a, IniValue b) => IniValue (Either a b) Source # |
|
(IniValue a, IniValue b) => IniValue (a, b) Source # | Tuples follow the same rules as lists, but must be of the correct length. |
(IniValue a, IniValue b, IniValue c) => IniValue (a, b, c) Source # | |