From 4feb31a804a091cda2fbf9d80938c47feddcab66 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 6 Aug 2015 11:24:18 -0400 Subject: comment --- ...ent_3_92c583f883fae2b447c1598356efade2._comment | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 doc/todo/File.containsConfPair___38___LightDM.autoLogin_properties/comment_3_92c583f883fae2b447c1598356efade2._comment (limited to 'doc/todo/File.containsConfPair___38___LightDM.autoLogin_properties') diff --git a/doc/todo/File.containsConfPair___38___LightDM.autoLogin_properties/comment_3_92c583f883fae2b447c1598356efade2._comment b/doc/todo/File.containsConfPair___38___LightDM.autoLogin_properties/comment_3_92c583f883fae2b447c1598356efade2._comment new file mode 100644 index 00000000..a45bc921 --- /dev/null +++ b/doc/todo/File.containsConfPair___38___LightDM.autoLogin_properties/comment_3_92c583f883fae2b447c1598356efade2._comment @@ -0,0 +1,41 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 3""" + date="2015-08-06T14:54:14Z" + content=""" +I'd suggest making it take some helper functions. + +Something like these: + + type SectionStart = String -> Bool -- ^ find the line that is the start of the wanted section (eg, == "") + type SectionEnd = String -> Bool -- ^ find a line that is within the section, but that indicates the end of the section (eg == "") + type SectionPast = String -> Bool -- ^ find a line that indicates we are past the section (eg, a new section header) + type AdjustSection = [String] -> [String] -- ^ run on all lines in the section, including the SectionStart line and any SectionEnd line; can add/delete/modify lines, or even delete entire section + type InsertSection = [String] -> [String] -- ^ if SectionStart does not find the section in the file, this is used to insert the section somewhere within it + + adjustSection :: SectionStart -> SectionEnd -> AdjustSection -> InsertSection -> FilePath -> Property + +Which seems sufficiently generic; it can even be used to delete entire sections! + +Let's see.. + + iniHeader header = '[':header++"]" + + adjustIniSection :: String -> AdjustSection -> InsertSection -> Property + adjustIniSection header = adjustSection + (== iniHeader header) + (const False) + ("[" `isPrefixOf`) + + containsConfPair header key value = adjustIniSection header + go + (++ [confheader, confline]) -- add missing section at end + where + confheader = iniHeader header + confline = key ++ "=" ++ value + go ls = undefined -- TODO find key= line and change it, or add confline + + removeSection header = adjustIniSection header + (const []) -- remove all lines of section + id -- add no lines if section is missing +"""]] -- cgit v1.2.3