summaryrefslogtreecommitdiff
path: root/doc/todo/File.containsConfPair___38___LightDM.autoLogin_properties/comment_3_92c583f883fae2b447c1598356efade2._comment
blob: a45bc9214eed9b71fc8a0053b8da72844e3716ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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, == "<Foo>")
	type SectionEnd = String -> Bool -- ^ find a line that is within the section, but that indicates the end of the section (eg == "</Foo>")
	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
"""]]