コード例 #1
0
ファイル: xml_reader.cpp プロジェクト: purpleKarrot/Karrot
void XmlReader::pop_tag()
  {
  const Tag& tag = open_tags.back();
  pop_namespaces(tag.previous_mappings);
  current_name = tag.name;
  open_tags.pop_back();
  }
コード例 #2
0
ファイル: xmp-parse.c プロジェクト: DevMaggio/gimp
/* called from the GMarkupParser */
static void
passthrough_handler    (GMarkupParseContext  *markup_context,
                        const gchar          *passthrough_text,
                        gsize                 text_len,
                        gpointer              user_data,
                        GError              **error)
{
  XMPParseContext *context = user_data;

  switch (context->state)
    {
    case STATE_START:
    case STATE_AFTER_XPACKET:
      if ((text_len >= 21)
          && (! strncmp (passthrough_text, "<?xpacket begin=", 16)))
	context->state = STATE_INSIDE_XPACKET;
      else
	parse_error (context, error, XMP_ERROR_PARSE,
                     _("XMP packets must start with <?xpacket begin=...?>"));
      break;

    case STATE_AFTER_RDF:
      /* the x:xmpmeta element is missing */
      context->depth--;
      pop_namespaces (context, error);
      /*fallthrough*/
    case STATE_AFTER_XMPMETA:
      if ((text_len >= 19)
          && (! strncmp (passthrough_text, "<?xpacket end=", 14)))
	context->state = STATE_AFTER_XPACKET;
      else
	parse_error (context, error, XMP_ERROR_PARSE,
                     _("XMP packets must end with <?xpacket end=...?>"));
      break;

    default:
      if ((text_len >= 18)
          && (! strncmp (passthrough_text, "<?adobe-", 8)))
        ; /* ignore things like <?adobe-xap-filters esc="CRLF"?> */
      else if (! (context->flags & XMP_FLAG_NO_COMMENTS)
               && (text_len > 7)
               && (! strncmp (passthrough_text, "<!--", 4)))
        ; /* comments are not allowed in XMP, but let's ignore them */
      else
        parse_error (context, error, XMP_ERROR_INVALID_COMMENT,
                     _("XMP cannot contain XML comments or processing instructions"));
      break;
    }
}
コード例 #3
0
ファイル: xmp-parse.c プロジェクト: DevMaggio/gimp
/* called from the GMarkupParser */
static void
end_element_handler    (GMarkupParseContext  *markup_context,
                        const gchar          *element_name,
                        gpointer              user_data,
                        GError              **error)
{
  XMPParseContext *context = user_data;

#ifdef DEBUG_XMP_PARSER
  g_print ("[%25s/%17s] %d </%s>\n",
           state_names[context->state],
           (context->saved_state == STATE_ERROR
            ? "-"
            : state_names[context->saved_state]),
           context->depth, element_name);
#endif
  switch (context->state)
    {
    case STATE_INSIDE_PROPERTY:
      context->state = STATE_INSIDE_TOPLEVEL_DESC;
      if (context->property != NULL)
        {
          if (context->prop_cur_value < 0)
            {
              /* if not set yet, then property was empty */
              add_property_value (context, XMP_PTYPE_TEXT,
                                  NULL, g_strdup (""));
            }
          propagate_property (context, error);
        }
      break;

    case STATE_INSIDE_STRUCT:
      context->state = context->saved_state;
      if (context->property != NULL)
        propagate_property (context, error);
      break;

    case STATE_INSIDE_ALT:
    case STATE_INSIDE_BAG:
    case STATE_INSIDE_SEQ:
      if (context->property && context->prop_cur_value < 0)
        {
          g_free (context->property);
          context->property = NULL;
        }
      context->state = STATE_INSIDE_PROPERTY;
      break;

    case STATE_INSIDE_QDESC:
      context->state = context->saved_state;
      break;

    case STATE_INSIDE_QDESC_VALUE:
    case STATE_INSIDE_QDESC_QUAL:
      context->state = STATE_INSIDE_QDESC;
      break;

    case STATE_INSIDE_STRUCT_ELEMENT:
      context->state = STATE_INSIDE_STRUCT;
      if ((context->prop_cur_value >= 0)
          && (context->prop_value[context->prop_cur_value] == NULL))
        update_property_value (context, g_strdup (""));
      break;

    case STATE_INSIDE_ALT_LI:
      context->state = STATE_INSIDE_ALT;
      if ((context->prop_cur_value >= 0)
          && (context->prop_value[context->prop_cur_value] == NULL))
        update_property_value (context, g_strdup (""));
      break;

    case STATE_INSIDE_ALT_LI_RSC:
      context->state = STATE_INSIDE_ALT;
      break;

    case STATE_INSIDE_ALT_LI_RSC_IMG:
      context->state = STATE_INSIDE_ALT_LI_RSC;
      break;

    case STATE_INSIDE_BAG_LI:
    case STATE_INSIDE_BAG_LI_RSC:
      context->state = STATE_INSIDE_BAG;
      break;

    case STATE_INSIDE_SEQ_LI:
    case STATE_INSIDE_SEQ_LI_RSC:
      context->state = STATE_INSIDE_SEQ;
      break;

    case STATE_INSIDE_TOPLEVEL_DESC:
      g_return_if_fail (matches_rdf (element_name, context, "Description"));
      context->state = STATE_INSIDE_RDF;
      break;

    case STATE_INSIDE_RDF:
      g_return_if_fail (matches_rdf (element_name, context, "RDF"));
      context->state = STATE_AFTER_RDF;
      break;

    case STATE_AFTER_RDF:
      g_return_if_fail (! strcmp (element_name, "x:xmpmeta")
                        || ! strcmp (element_name, "x:xapmeta")
                        || matches_with_prefix (element_name,
                                                context->xmp_prefix,
                                                context->xmp_prefix_len,
                                                "xmpmeta"));
      context->state = STATE_AFTER_XMPMETA;
      break;

    case STATE_SKIPPING_UNKNOWN_ELEMENTS:
    case STATE_SKIPPING_IGNORED_ELEMENTS:
      if (context->depth == context->saved_depth)
        {
          /* resume normal processing */
          context->state = context->saved_state;
          context->saved_state = STATE_ERROR;
        }
      break;

    default:
      parse_error (context, error, XMP_ERROR_PARSE,
		       _("End of element <%s> not expected in this context"),
                         element_name);
      break;
    }
  pop_namespaces (context, error);
  context->depth--;
}