decodeMap method

Map<String, dynamic> decodeMap (dynamic src)

Decode a map

Implementation

Map<String,dynamic> 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");
  Map<String,dynamic> map = {};
  bool foundComma = true;
  if(p.next() != "{") { throw("Array has to start with a ["); }
  while(p.actual() != "}") {
    if(!foundComma) { throw p.error("Expected \"}\" or \",\""); }
    foundComma = false;
    _skipIgnored(p);
    String key = "";
    if(p.actual() == "\"" || p.actual() == "'") { key = decodeString(src); }
    else while(_KEY_CHARACTERS.hasMatch(p.actual())) { key += p.next(); }

    _skipIgnored(p);

    if(p.actual() != ":") { throw p.error('Expected ":"'); }
    p.skip();

    _skipIgnored(p);

    if(new RegExp(r'''[\\[\\{\\\"\\\'0-9]''').hasMatch(p.actual()) || _PURE_STRING.hasMatch(p.actual())) { map[key] = decode(p); }
    else { throw p.error('Expected "[", "\\"","\\\'", "{" or a number'); }

    _skipIgnored(p);

    if(p.actual() == ",") {
      foundComma = true;
      p.skip();
    }
    _skipIgnored(p);
  }
  if(!p.ended)p.skip();
  return map;
}