File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 4242 * @return the constructor of Config.
4343]]
4444function Config :newConfigFromText (text )
45-
45+ local c = {}
46+ setmetatable (c ,self )
47+ self .__index = self
48+ c .data = {}
49+ local lines = {}
50+ string.gsub (text , ' [^' .. " \r\n " .. ' ]+' , function (w ) table.insert (lines , w ) end )
51+ c :parseBuffer (lines )
52+ return c
4653end
4754
4855-- addConfig adds a new section->key:value to the configuration.
@@ -76,7 +83,7 @@ function Config:parseBuffer(lines)
7683 local lineNum = 0
7784 local canWrite = false
7885 local line = " "
79-
86+
8087 while true do
8188 if canWrite then
8289 if self :write (section , lineNum , buf ) == true then
@@ -109,7 +116,7 @@ function Config:parseBuffer(lines)
109116 end
110117
111118 section = string.sub (line , 2 , - 2 )
112- else
119+ else
113120 local p = " "
114121
115122 if self .DEFAULT_MULTI_LINE_SEPARATOR == string.sub (line , - 2 , - 1 ) then
@@ -216,12 +223,12 @@ function Config:get(key)
216223 else
217224 option = keys [1 ]
218225 end
219-
226+
220227 if self .data [section ] == nil then
221228 return " "
222229 elseif self .data [section ][option ] == nil then
223230 return " "
224231 else
225232 return self .data [section ][option ]
226233 end
227- end
234+ end
You can’t perform that action at this time.
0 commit comments