| 540 | } |
| 541 | |
| 542 | std::string |
| 543 | HelpSource::get_css (const std::string &u) |
| 544 | { |
| 545 | std::ifstream t (tl::to_string (QDir (tl::to_qstring (lay::ApplicationBase::instance()->inst_path ())).absoluteFilePath (QString::fromUtf8 ("help_format.css"))).c_str ()); |
| 546 | if (t.good ()) { |
| 547 | std::string c; |
| 548 | while (t.good ()) { |
| 549 | std::string l; |
| 550 | std::getline (t, l); |
| 551 | c += l + "\n"; |
| 552 | } |
| 553 | return c; |
| 554 | } |
| 555 | |
| 556 | QResource res (resource_url (QUrl::fromEncoded (u.c_str ()).path ())); |
| 557 | if (res.size () == 0) { |
| 558 | throw tl::Exception (tl::to_string (QObject::tr ("No data found for resource ")) + u); |
| 559 | } |
| 560 | |
| 561 | QByteArray data; |
| 562 | #if QT_VERSION >= 0x60000 |
| 563 | if (res.compressionAlgorithm () == QResource::ZlibCompression) { |
| 564 | #else |
| 565 | if (res.isCompressed ()) { |
| 566 | #endif |
| 567 | data = qUncompress ((const unsigned char *)res.data (), (int)res.size ()); |
| 568 | } else { |
| 569 | data = QByteArray ((const char *)res.data (), (int)res.size ()); |
| 570 | } |
| 571 | |
| 572 | return std::string (data.constData (), data.size ()); |
| 573 | } |
| 574 | |
| 575 | std::string |
| 576 | HelpSource::get (const std::string &u) |
| 577 | { |
| 578 | BrowserOutline ol; |
| 579 | return process (get_dom (u), u, ol); |
| 580 | } |
| 581 | |
| 582 | BrowserOutline |
| 583 | HelpSource::get_outline (const std::string &u) |
| 584 | { |
| 585 | BrowserOutline ol; |
| 586 | process (get_dom (u), u, ol); |
| 587 | return ol; |
| 588 | } |
| 589 | |
| 590 | void |
| 591 | HelpSource::search_completers (const std::string &string, std::list<std::string> &completers) |
| 592 | { |
| 593 | size_t n = 0; |
| 594 | const size_t max_completers = 100; |
| 595 | |
| 596 | // first produce all hits with match |
| 597 | for (std::vector <IndexEntry>::const_iterator i = m_index.begin (); i < m_index.end () && n < max_completers; ++i) { |
| 598 | if (i->normalized_key.find (string) != std::string::npos) { |
| 599 | completers.push_back (i->key); |
nothing calls this directly
no test coverage detected