decodeMap method
Decode a map
Implementation
Properties decodeMap(dynamic src) {
GsonParsable p = src is GsonParsable
? src
: src is String
? new GsonParsable(src)
: throw ("The src is not a valid input to decode an Array from");
Properties map = new Properties([]);
int lastpos = -1;
while (p.hasNext()) {
if(p.position == lastpos) {
throw p.error("Ooups, nothing is happening");
}
lastpos = p.position;
map.contents.addAll(parseIgnoredIncludingComments(p));
String key = "";
if (p.actual() == "\"" || p.actual() == "'") {
key = decodeString(src).toString();
} else {
while (_KEY_CHARACTERS.hasMatch(p.actual())) {
key += p.actual();
if(p.hasNext()) {
p.skip();
}
else {
break;
}
}
}
if(key == "") {
throw p.error('Key must not be ""');
}
_skipIgnored(p);
if (p.actual() != "=") {
throw p.error('Expected "="');
}
p.skip();
_skipIgnored(p);
if (p.actual() == "\"" || p.actual() == "'" || _PURE_STRING.hasMatch(p.actual())) {
dynamic value = decodeString(p);
map.contents.add(new PropertiesEntry(key, value));
} else if (p.actual() == "\r" || p.actual() == "\n") {
map.contents.add(new PropertiesEntry(key, null));
} else {
throw p.error('Expected "\\"", "\\\'" or a number');
}
map.contents.addAll(parseIgnoredIncludingComments(p));
}
if (!p.ended) p.skip();
return map;
}