Update a configuration file: Difference between revisions
m
→{{header|Julia}}
Line 2,056:
=={{header|Julia}}==
<lang julia>function cleansyntax(line)▼
<lang julia>stripbadchars(s) = join(filter(c -> isascii(c[1]) && !iscntrl(c[1]), split(s, "")), "")▼
▲function cleansyntax(line)
line = strip(line)
if line == ""
Line 2,069 ⟶ 2,068:
line = p == nothing ? uppercase(o) : uppercase(o) * " " * p
end
▲
end
Line 2,078 ⟶ 2,077:
the configuration files's lines prior to other function appication.
"""
cleansyntax!(lines) = (for (i, li) in enumerate(lines) lines[i] = cleansyntax(li) end; lines)
isdisabled(line) = startswith(line, [';', '#'])▼
isenabled(line) = !isdisabled(line)▼
function splitline(line)▼
arr = split(line, r"\s+", limit=2)▼
if length(arr) < 2▼
return (arr[1], nothing)▼
end
return (arr[1], arr[2])▼
end
▲isdisabled(line) = startswith(line, [';', '#'])
function disable!(lines, opt)
for (i, li) in enumerate(lines)
if isenabled(li) && splitline(li)[1] == uppercase(opt)
lines[i] =
break # note: only first one found is disabled
end
Line 2,097 ⟶ 2,100:
end
▲isenabled(line) = !isdisabled(line)
function enable!(lines, opt)
for (i, li) in enumerate(lines)
Line 2,112 ⟶ 2,113:
end
▲function splitline(line)
▲ arr = split(line, r"\s+", limit=2)
▲ if length(arr) < 2
▲ return (arr[1], nothing)
▲ return (arr[1], arr[2])
function changeparam!(lines, opt, newparam)
for (i, li) in enumerate(lines)
Line 2,162 ⟶ 2,154:
changeparam!(cfglines, "NUMBEROFSTRAWBERRIES", 62000)
for li in cfglines
if li != ""
Line 2,168 ⟶ 2,160:
li = ""
end
write(
end
end
|