Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Incrementor = {}
- Incrementor.start = 0
- Incrementor.stop = 0
- Incrementor.key =""
- Incrementor.prop = ""
- Incrementor.skip = 0
- Incrementor.is_prop = false
- Incrementor.reset = function()
- self.key = ""
- self.prop = ""
- self.start = 0
- self.stop = 0
- self.is_prop = false
- end function
- Incrementor.reset_start_stop = function()
- self.start = 0
- self.stop = 0
- end function
- Incrementor.skip_dec = function()
- if self.skip > 0 then
- self.skip = self.skip -1
- return true
- end if
- return false
- end function
- Incrementor.find_obj_close_index=function(start, txt)
- if txt[start].code == 123 then self.prop = {}
- if txt[start].code == 91 then self.prop = []
- self.start = start
- skip = 0
- for i in range(start+1, txt.len()-1)
- if txt[i].code == txt[start].code then
- skip=skip+1
- continue
- end if
- if txt[i].code == txt[start].code+2 then
- if skip > 0 then skip=skip-1 continue
- self.stop = i
- self.skip = self.stop-start-1
- return
- end if
- end for
- end function
- Incrementor.find_int_close_index=function(start, txt)
- self.prop = 0
- self.start = start
- for i in range(start, txt.len()-1)
- if txt[i].code >= 48 and txt[i].code <=57 then continue
- self.stop = i
- self.skip = self.stop - start
- break
- end for
- end function
- json_parse_array=function(txt)
- out = []
- vals = txt.split(",")
- for val in vals
- val = val.replace(" ", "")
- if txt[0].code == 34 then out.push(val.trim()[1:val.len()-1])
- if txt[0].code == 123 then out.push(json_parse(val))
- end for
- return out
- end function
- json_parse=function(txt)
- if not txt then return
- if txt[0].code == 123 and txt[txt.len()-1].code == 125 then return json_parse(txt[1:txt.len()-1])
- out = {}
- inc = new Incrementor
- for c in range(0, txt.len()-1)
- if inc.skip_dec then continue end if
- if txt[c].code == 34 and inc.start == 0 then inc.start = c+1 continue
- if txt[c].code == 34 and inc.start != 0 and c-inc.start >= 0 then inc.stop = c continue
- if txt[c].code == 58 and inc.start == 0 and inc.key != "" then inc.is_prop = true continue
- if txt[c].code == 44 then inc.is_prop = false
- if txt[c].code >= 48 and txt[c].code <=57 and inc.is_prop and inc.start == 0 then
- inc.find_int_close_index(c, txt)
- end if
- if (txt[c].code == 123 or txt[c].code == 91) and inc.key != "" then
- inc.find_obj_close_index(c, txt)
- continue
- end if
- if inc.start != 0 and inc.stop != 0 and inc.key == "" then
- inc.key = txt[inc.start:inc.stop]
- inc.reset_start_stop
- continue
- end if
- if inc.start != 0 and inc.stop != 0 and inc.key != "" then
- if typeof("") == typeof(inc.prop) then
- out[inc.key] = txt[inc.start:inc.stop]
- inc.reset
- continue
- end if
- if typeof({}) == typeof(inc.prop) then
- out[inc.key] = json_parse(txt[inc.start:inc.stop])
- inc.reset
- end if
- if typeof([]) == typeof(inc.prop) then
- out[inc.key] = json_parse_array(txt[inc.start+1:inc.stop])
- inc.reset
- end if
- if typeof(0) == typeof(inc.prop) and inc.is_prop then
- out[inc.key] = txt[inc.start:inc.stop].to_int
- inc.reset
- end if
- end if
- end for
- return out
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement