GValue*                
_midgard_object_reference_get_id_value (MidgardModelReference *iface, GError **error)
{
	MidgardObjectReference *self = MIDGARD_OBJECT_REFERENCE(iface);

	const gchar *id = self->priv->id;
	GValue *id_value = g_new0(GValue, 1);

	/* GUID */
	if (midgard_is_guid(id)) {
		g_value_init (id_value, G_TYPE_STRING);
		g_value_set_string (id_value, id);
	/* integer */
	} else if (_is_int(id)) {
		g_value_init (id_value, G_TYPE_UINT);
		g_value_set_uint (id_value, atoi(id));
	/* undefined TODO: UUID */	
	} else {
		g_free (id_value);
		g_set_error (error, MIDGARD_VALIDATION_ERROR, MIDGARD_VALIDATION_ERROR_TYPE_INVALID, 
				"Invalid ID value type. Expected guid, uuid or integer id. Got '%s'.",
				G_VALUE_TYPE_NAME (id_value));
		return NULL;
	}	

	return id_value;
}
Exemple #2
0
token * lex_next(lexer * lex) {
  switch(lex->state) {
    case LEX_DEF:
      _lex_adv(lex);
      if(EOF == lex->current_char) { return lex_next(_lex_set_state(lex, LEX_DONE)); }
      else if(_is_int(lex->current_char)) { return lex_next(_lex_set_state(lex, LEX_IN_INT)); }
      else if(_is_space(lex->current_char)) { return lex_next(lex); }
      else if(_is_str_end(lex->current_char)) { return lex_next(_lex_adv(_lex_set_state(lex, LEX_IN_STR))); }
      else if(_is_id_start(lex->current_char)) { return lex_next(_lex_set_state(lex, LEX_IN_ID)); }
      else if(_is_ctrl_char(lex->current_char)) { return _token_ctrl_char(lex->current_char); }
      else { return lex_next(_lex_set_state(lex, LEX_ERR)); }
    case LEX_IN_INT:
      if(_is_int(lex->current_char)) {
        if(0 == str_add(lex->tok_buf, lex->current_char)) { return lex_next(_lex_set_state(lex, LEX_ERR)); }
        return lex_next(_lex_adv(lex));
      }
      return _tok_new(lex, TOK_INT, LEX_DEF);
    case LEX_IN_ID:
      if(_is_id(lex->current_char)) {
        if(0 == str_add(lex->tok_buf, lex->current_char)) { return lex_next(_lex_set_state(lex, LEX_ERR)); }
        return lex_next(_lex_adv(lex));
      }
      if(_is_keyword(lex->tok_buf)) { return _tok_new(lex, TOK_KEY, LEX_DEF); }
      return _tok_new(lex, TOK_ID, LEX_DEF);
    case LEX_IN_STR:
      if(!_is_str_end(lex->current_char)) {
        if(_is_escape(lex->current_char)) { return lex_next(_lex_adv(_lex_set_state(lex, LEX_IN_ESC))); }
        if(0 == str_add(lex->tok_buf, lex->current_char)) { return lex_next(_lex_set_state(lex, LEX_ERR)); }
        return lex_next(_lex_adv(lex));
      }
      return _tok_new(lex, TOK_STR, LEX_DEF);
    case LEX_IN_ESC:
      if(_is_escapable(lex->current_char)) {
        _lex_set_char(lex, _make_escape(lex->current_char));
        if(0 == str_add(lex->tok_buf, lex->current_char)) { return lex_next(_lex_set_state(lex, LEX_ERR)); }
        return lex_next(_lex_adv(_lex_set_state(lex, LEX_IN_STR)));
      }
      return lex_next(_lex_set_state(lex, LEX_ERR));
    case LEX_ERR: return _tok_new(lex, TOK_ERR, LEX_DEF);
    case LEX_DONE:
    default: return _tok_new(lex, TOK_EOF, LEX_DONE);
  }
}
Exemple #3
0
static int _is_id(char c) {
  return (_is_id_start(c) || _is_int(c));
}