Пример #1
0
void TextParser::setState(unsigned code, bool bSet)
{
    if (bSet) {
        if ((m_state & code) == code)
            return;
        m_state |= code;
    } else {
        if ((m_state & code) == 0)
            return;
        m_state &= ~code;
    }
    QString tag;
    switch (code) {
    case 1:
        tag = "b";
        break;
    case 2:
        tag = "i";
        break;
    case 4:
        tag = "u";
        break;
    default:
        return;
    }
    if (bSet) {
        push_tag(tag);
    } else {
        pop_tag(tag);
    }
}
Пример #2
0
/* Sacha thinks we should omit the element name, but this is more in line with SAX */
hcerr_t end_element (xml_writer *xml_writer,
		     char *element_name){
  hc_simple_xml_writer_t *writer = (hc_simple_xml_writer_t*) xml_writer;
  char *current_open_element = writer->tag_stack->tag;

  require_ok(pretty_print(writer, FALSE));
  if (strcmp(current_open_element, element_name) != 0)
    HC_ERR_LOG(("expected '%s', closing '%s'\n", current_open_element, element_name));

  require_ok(hc_write(writer, "</"));
  require_ok(hc_write(writer, element_name));
  require_ok(hc_write(writer, ">"));
  pop_tag (&writer->tag_stack);
  return HCERR_OK;
}
Пример #3
0
void TextParser::put_style()
{
    if (!m_bChanged)
        return;
    m_bChanged = false;
    QString style;
    if (!color.isEmpty())
        style = color;
    if (!face.isEmpty()) {
        if (!style.isEmpty())
            style += ";";
        style += face;
    }
    if (!size.isEmpty()) {
        if (!style.isEmpty())
            style += ";";
        style += size;
    }
    QString tag("span style=\"");
    tag += style;
    tag += "\"";
    pop_tag(tag);
    push_tag(tag);
}
Пример #4
0
void xml_pop(void)
{
    xprintf("</%s>", pop_tag());
}
Пример #5
0
void xml_tag_end_pop(void)
{
    pop_tag();
    xputs("/>");
}
Пример #6
0
void reader::implementation::parse_pi()
  {
  parse_name(current_name);
  attributes.clear();
  token_ = xml::token::pi;
instruction:
  /*!re2c
  space* "?>"
    {
    return;
    }
  space+
    {
    Attribute attr;
    parse_attribute(attr);
    attributes.push_back(attr);
    goto instruction;
    }
  else
    {
    throw_error();
    }
  */
  }

void reader::implementation::parse_comment()
  {
  token_ = xml::token::comment;
comment:
  /*!re2c
  "-->"
    {
    return;
    }
  "--" | [^]
    {
    goto comment;
    }
  */
  }

void reader::implementation::parse_element()
  {
  parse_name(current_name);
  token_ = xml::token::element;
  attributes.clear();
attribute:
  /*!re2c
  space* "/>"
    {
    is_empty_element = true;
    pop_namespaces(push_namespaces());
    return;
    }
  space* ">"
    {
    is_empty_element = false;
    push_tag();
    return;
    }
  space+
    {
    Attribute attr;
    parse_attribute(attr);
    attributes.push_back(attr);
    goto attribute;
    }
  else
    {
    throw_error();
    }
  */
  }

void reader::implementation::parse_end_element()
  {
  const Name& expected = open_tags.back().name;
  parse_name(current_name);
  /*!re2c
  space* ">"
    {
    }
  else
    {
    throw_error();
    }
  */
  if (open_tags.empty())
    {
    throw_error();
    }
  if (current_name.prefix != expected.prefix || current_name.local != expected.local)
    {
    std::stringstream error;
    error << "Expected end tag: '";
    if (!expected.prefix.empty())
      {
      error << expected.prefix << ':';
      }
    error << expected.local << "'.\n";
    throw_error(error.str());
    }
  token_ = xml::token::end_element;
  is_empty_element = false;
  pop_tag();
  }

bool reader::implementation::parse_text()
  {
  do
    {
    ++cursor;
    if (cursor == end)
      {
      return false;
      }
    }
  while (*cursor != '<');
  token_ = xml::token::text;
  return true;
  }

bool reader::implementation::read()
  {
  if (cursor == end)
    {
    return false;
    }
  /*!re2c
  "<?"
    {
    parse_pi();
    return true;
    }
  "<!--"
    {
    parse_comment();
    return true;
    }
  "<"
    {
    parse_element();
    return true;
    }
  "</"
    {
    parse_end_element();
    return true;
    }
  else
    {
    return parse_text();
    }
  */
  }