Exemple #1
0
int MIValue::ParseTuple(String const &s, int i)
{
	Clear();
	type = MITuple;
	
	// drop opening delimiter
	if(!expect("ParseTuple", '{', i, s))
		return s.GetCount();
	i++;
	while(s[i] && s[i] != '}')
	{
		while(s[i] && isspace(s[i]))
			i++;
		String name;
		MIValue val;
		i = ParsePair(name, val, s, i);
		tuple.AddPick(name, pick(val));
		while(s[i] && isspace(s[i]))
			i++;
		if(s[i] == '}')
			break;
		if(!expect("ParseTuple", ',', i, s))
			return s.GetCount();
		i++;
	}

	return i + 1;
}
Exemple #2
0
		//create a JsonObject object while object found
		sgdm::StackGuard<JsonValue>&& JsonParser::ParseObject(){
			if(currentTok != '{'){
				return Error("Expecting { at entity beginning");
			}
			else{
				sgdm::StackGuard<JsonValue> resObject(new JsonObject());
				getNextTok();                     //eat {
				while(currentTok != '}'){
					if(currentTok == ',')
					    getNextTok();             //eat ,
					resObject->push(std::move(ParsePair()));
				}
				getNextTok();                     //eat }
				return std::move(resObject);
			}
		}
Exemple #3
0
Json* Json::Parser::ParseObject(){
	NextChar();
	Object obj;
	Json* p;
	while(ch != '}'){
		BackCharIndex();
		p = ParsePair();

		if(p) {
			if(p->_kind == kObject)
				obj.insert(*(Pair*)(p->_data));
			else 
				JSON_ASSERT("json of object expected");
		}
		NextChar(true);
		if(ch == ',') NextChar();
	}
	return new Json(new Object(obj));
}
Exemple #4
0
static bool ParseObject(ParserT *parser, JsonNodeT *node) {
  int i = 0;

  if (ParserMatch(parser, TOK_RBRACE) && node->u.object.num == 0)
    return true;

  while (true) {
    if (!ParsePair(parser, &node->u.object.item[i++]))
      return false;

    if (ParserMatch(parser, TOK_RBRACE))
      break;

    if (!ParserMatch(parser, TOK_COMMA)) {
      parser->errmsg = "',' or '}' expected";
      return false;
    }
  }

  return true;
}
Exemple #5
0
int MIValue::ParseArray(String const &s, int i)
{
	Clear();
	type = MIArray;
	
	// drop opening delimiter
	if(!expect("ParseArray", '[', i, s))
		return s.GetCount();
	i++;
	while(s[i] && isspace(s[i]))
		i++;
	while(s[i] && s[i] != ']')
	{
		while(s[i] && isspace(s[i]))
			i++;
		String name;
		MIValue val;
		if(s[i] == '[')
			i = val.ParseArray(s, i);
		else if(s[i] == '{')
			i = val.ParseTuple(s, i);
		else if(s[i] == '"')
			i = val.ParseString(s, i);
		else if(s[i] == '<')
			i = val.ParseAngle(s, i);
		else
			i = ParsePair(name, val, s, i);
		array.Add() = pick(val);
		while(s[i] && isspace(s[i]))
			i++;
		if(s[i] == ']')
			break;
		if(!expect("ParseArray", ',', i, s))
			return s.GetCount();
		i++;
	}
	return i + 1;
}
Exemple #6
0
int MIValue::Parse(String const &s, int i)
{
	// if starts with '"', it's a string
	// if starts with '[', it's an array
	// if starts with '{', it's a tuple
	// otherwise, it can be a sequence of pair name="value" which is stored like a tuple
	// latter case is an example o bad design of MI interface....
	Clear();
	while(s[i] && isspace(s[i]))
		i++;
	if(s[i] == '"')
		return ParseString(s, i);
	else if(s[i] == '<')
		return ParseAngle(s, i);
	else if(s[i] == '[')
		return ParseArray(s, i);
	else if(s[i] == '{')
		return ParseTuple(s, i);
	else
	{
		String name;
		MIValue val;
		type = MITuple;
		while(s[i])
		{
			i = ParsePair(name, val, s, i);
			tuple.AddPick(name, pick(val));
			while(s[i] && isspace(s[i]))
				i++;
			if(s[i] != ',')
				break;
			i++;
		}

		return i;
	}
}
void RDCddbLookup::readyReadData()
{
  QString line;
  QString tag;
  QString value;
  int index;
  int code;
  char buffer[2048];
  char offset[256];
  int hex;
  int start;

  while(lookup_socket->canReadLine()) {
    line=lookup_socket->readLine();
    Profile("recevied from server: \""+line+"\"");
    sscanf((const char *)line,"%d",&code);
    switch(lookup_state) {
    case 0:    // Login Banner
      if((code==200)||(code==201)) {
	sprintf(buffer,"cddb hello %s %s %s %s",
		(const char *)lookup_username,
		(const char *)lookup_hostname,
		(const char *)lookup_appname,
		(const char *)lookup_appver);
	SendToServer(buffer);
	lookup_state=1;
      }
      else {
	FinishCddbLookup(RDCddbLookup::ProtocolError);
      }
      break;

    case 1:    // Handshake Response
      if((code==200)||(code==402)) {
	sprintf(buffer,"cddb query %08x %d",
		lookup_record->discId(),lookup_record->tracks());
	for(int i=0;i<lookup_record->tracks();i++) {
	  sprintf(offset," %d",lookup_record->trackOffset(i));
	  strcat(buffer,offset);
	}
	sprintf(offset," %d",lookup_record->discLength()/75);
	strcat(buffer,offset);
	SendToServer(buffer);
	lookup_state=2;
      }
      else {
	FinishCddbLookup(RDCddbLookup::ProtocolError);
      }
      break;

    case 2:    // Query Response
      switch(code) {
      case 200:   // Exact Match
	start=4;
	if(sscanf((const char *)line+start,"%s",offset)==1) {
	  lookup_record->setDiscGenre(offset);
	  start+=lookup_record->discGenre().length()+1;
	}
	if(sscanf((const char *)line+start,"%x",&hex)==1) {
	  lookup_record->setDiscId(hex);
	  start+=9;
	}
	lookup_record->setDiscTitle((const char *)line+start);
	sprintf(buffer,"cddb read %s %08x\n",
		(const char *)lookup_record->discGenre(),
		lookup_record->discId());
	SendToServer(buffer);
	lookup_state=3;		
	break;

      case 211:   // Inexact Match
	FinishCddbLookup(RDCddbLookup::PartialMatch);
	break;

      default:
	FinishCddbLookup(RDCddbLookup::ProtocolError);
	break;
      }
      break;

    case 3:    // Read Response
      if((code==210)) {
	lookup_state=4;
      }
      else {
	FinishCddbLookup(RDCddbLookup::ProtocolError);
      }
      break;
	  
    case 4:    // Record Lines
      if(line[0]!='#') {   // Ignore Comments
	if(line[0]=='.') {  // Done
	  FinishCddbLookup(RDCddbLookup::ExactMatch);
	}
	ParsePair(&line,&tag,&value,&index);
	if(tag=="DTITLE") {
	  lookup_record->setDiscTitle(value.left(value.length()-1));
	}
	if(tag=="DYEAR") {
	  lookup_record->setDiscYear(value.toUInt());
	}
	if(tag=="EXTD") {
	  lookup_record->
	    setDiscExtended(lookup_record->discExtended()+
			    DecodeString(value));
	}
	if(tag=="PLAYORDER") {
	  lookup_record->setDiscPlayOrder(value);
	}
	if((tag=="TTITLE")&&(index!=-1)) {
	  lookup_record->setTrackTitle(index,value.left(value.length()-1));
	}
	if((tag=="EXTT")&&(index!=-1)) {
	  lookup_record->
	    setTrackExtended(index,
			     lookup_record->trackExtended(index)+value);
	}
      }
      break;
    }
  }
}