Software /
code /
prosody
Comparison
util/datamapper.lua @ 11466:c098d07e6717
util.datamapper: Finally implement support for parsing arrays
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 20 Mar 2021 20:45:06 +0100 |
parent | 11465:19a88b61ab4e |
child | 11467:88792dd2bee9 |
comparison
equal
deleted
inserted
replaced
11465:19a88b61ab4e | 11466:c098d07e6717 |
---|---|
25 local value_goes = {} | 25 local value_goes = {} |
26 | 26 |
27 local function unpack_propschema(propschema, propname, current_ns) | 27 local function unpack_propschema(propschema, propname, current_ns) |
28 | 28 |
29 local proptype = "string" | 29 local proptype = "string" |
30 local value_where = "in_text_tag" | 30 local value_where = propname and "in_text_tag" or "in_text" |
31 local name = propname | 31 local name = propname |
32 local namespace = current_ns | 32 local namespace = current_ns |
33 local prefix | 33 local prefix |
34 local single_attribute | 34 local single_attribute |
35 local enums | 35 local enums |
156 | 156 |
157 return out | 157 return out |
158 end | 158 end |
159 | 159 |
160 function parse_array(schema, s) | 160 function parse_array(schema, s) |
161 local proptype, value_where, child_name, namespace = unpack_propschema(schema.items, nil, s.attr.xmlns) | 161 local proptype, value_where, child_name, namespace, prefix, single_attribute, enums = unpack_propschema(schema.items, nil, s.attr.xmlns) |
162 local attr_name | |
163 if value_where == "in_single_attribute" then | |
164 value_where = "in_attribute"; | |
165 attr_name = single_attribute; | |
166 end | |
162 local out = {} | 167 local out = {} |
163 for c in s:childtags(child_name, namespace) do | 168 for c in s:childtags(child_name, namespace) do |
164 local value; | 169 local value = extract_value(c, value_where, proptype, attr_name or child_name, namespace, prefix, single_attribute, enums) |
165 if value_where == "in_text_tag" then | 170 |
166 value = c:get_text(); | 171 table.insert(out, totype(proptype, value)); |
167 else | |
168 error("NYI") | |
169 end | |
170 | |
171 value = totype(proptype, value) | |
172 | |
173 if value ~= nil then | |
174 table.insert(out, value); | |
175 end | |
176 end | 172 end |
177 return out | 173 return out |
178 end | 174 end |
179 | 175 |
180 local function parse(schema, s) | 176 local function parse(schema, s) |