Ejemplo n.º 1
0
QString get_help_topic(QString help_file, QString help_topic)
{
    bool use_text = FALSE;

    QString return_string;
    return_string.clear();

    help_file.prepend(QString("%1/") .arg(npp_dir_help.path()));
    help_file.append(".txt");

    QFile topic_file;
    topic_file.setFileName(help_file);

    /* Handle file failure */
    if (!topic_file.open(QIODevice::ReadOnly))
    {
        return (" ");
    }

    QTextStream text_in(&topic_file);
    while (!text_in.atEnd())
    {
        QString line = text_in.readLine();

        if (line.contains(QString("*****")))
        {
            line.remove(QChar('*'));
            // We are at the end of the topic.. Quit appending
            if (line.contains(QString("<end>"), Qt::CaseInsensitive))
            {
                if (use_text) break;
            }

            // We found the topic.  Begin appending.
            if (line.contains(help_topic,  Qt::CaseInsensitive))
            {
                use_text = TRUE;
            }
        }
        // Add the text if we are mid-topic
        if (use_text)
        {
            // bold the topic
            if (!return_string.length()) return_string.append(QString("<b>%1</b>") .arg(line));
            else return_string.append(line);
            return_string.append("<br>");
        }
    }

    topic_file.close();

    // We never found a topic
    if (!return_string.length()) return(QString("topic not found"));

    return (return_string);
}
Ejemplo n.º 2
0
void
xtr_usf_c::finish_track() {
  auto subtitles = m_doc->document_element().append_child("subtitles");
  subtitles.append_child("language").append_attribute("code").set_value(m_language.c_str());

  for (auto &entry : m_entries) {
    std::string text = std::string{"<subtitle>"} + entry.m_text + "</subtitle>";
    strip(text, true);

    std::stringstream text_in(text);
    pugi::xml_document subtitle_doc;
    if (!subtitle_doc.load(text_in, pugi::parse_default | pugi::parse_declaration | pugi::parse_doctype | pugi::parse_pi | pugi::parse_comments)) {
      mxwarn(boost::format(Y("Track %1%: An USF subtitle entry starting at timecode %2% is not well-formed XML and will be skipped.\n")) % m_tid % format_timecode(entry.m_start * 1000000, 3));
      continue;
    }

    auto subtitle = subtitles.append_child("subtitle");
    subtitle.append_attribute("start").set_value(format_timecode(entry.m_start * 1000000, 3).c_str());
    subtitle.append_attribute("stop"). set_value(format_timecode(entry.m_end   * 1000000, 3).c_str());

    for (auto child : subtitle_doc.document_element())
      subtitle.append_copy(child);
  }
}