Esempio n. 1
0
int FindBar::highlight_all(const unicode& string, std::vector<Gtk::TextBuffer::iterator>& start_iters) {
    auto buf = window_.current_buffer()->buffer();
    auto start = buf->begin();
    auto end_of_file = buf->end();
    auto end = start;

    bool case_sensitive = case_sensitive_->get_active();

    //Remove any existing highlights
    buf->remove_tag_by_name(SEARCH_HIGHLIGHT_TAG, start, end_of_file);

    if(string.empty()) {
        return 0;
    }

    int highlighted = 0;
    while(start.forward_search(
              string.encode(), (case_sensitive) ? Gtk::TextSearchFlags(0) : Gtk::TEXT_SEARCH_CASE_INSENSITIVE,
              start, end)) {
        start_iters.push_back(start);
        buf->apply_tag_by_name(SEARCH_HIGHLIGHT_TAG, start, end);
        start = buf->get_iter_at_offset(end.get_offset());
        ++highlighted;
    }
    return highlighted;
}
Esempio n. 2
0
        gapped_search_result
        search(const gapped_pattern& pat) const
        {
            gapped_search_result res;
            const vector<string_type>& s = pat.subpatterns;
            size_type min_gap;
            size_type max_gap;

            std::cerr << "REGEX ::: " << pat.raw_regexp << std::endl;

            min_gap = s[0].size() + pat.gaps[0].first;
            max_gap = s[0].size() + pat.gaps[0].second;

            auto last_size = s[s.size() - 1].size();

            // get ranges
            vector<sdsl::int_vector_const_iterator<sdsl::int_vector<0>>::const_iterator> its;
            vector<sdsl::int_vector_const_iterator<sdsl::int_vector<0>>::const_iterator> its2;

            for (auto sx : s) {
                size_type sp, ep;
                forward_search(m_text.begin(), m_text.end(), m_sa, 0, m_sa.size()-1, sx.begin(), sx.end(), sp, ep);
                its.push_back(m_sa.begin() + sp);
                its2.push_back(m_sa.begin() + ep + 1);
            }

            vector<pii> spans1, spans2;
            for (auto it = its[0]; it != its2[0]; ++it)
		spans1.emplace_back(*it, *it);

            auto pspan1 = &spans1;
            auto pspan2 = &spans2;

            // incremental search
            for (size_t i = 1; i < its.size(); ++i) {
                std::sort(pspan1->begin(), pspan1->end());
                pspan2->clear();
                for (auto it = its[i]; it != its2[i]; ++it) {
                    auto pos = *it;
                    for (auto pot_match = lower_bound(pspan1->begin(), pspan1->end(), make_pair(pos - max_gap, pos));
                         pot_match != pspan1->end() && pot_match->first <= pos - min_gap;
                         ++pot_match)
                        pspan2->emplace_back(pos, pot_match->second);
                }
                std::swap(pspan1, pspan2);
            }
            std::sort(pspan1->begin(), pspan1->end(), [](const pii &left, const pii &right) { return left.second < right.second; });
            
            for (auto it = pspan1->begin(); it != pspan1->end(); ++it) {
                res.positions.push_back(it->second);
                auto end = it->first + last_size;
                while (it != pspan1->end() && it->second < end)
                    ++it;
            }

            return res;
        }
Esempio n. 3
0
        std::string info(const gapped_pattern& pat) const
        {
            // output SA-ranges (gives a good estimation about potential matches)
            index_type::size_type total_range = 0, sp = 0, ep = 0;

            for (size_t i = 0; i < pat.subpatterns.size(); ++i)
                total_range += forward_search(index.text.begin(), index.text.end(), index.wt, 0, index.wt.size()-1, pat.subpatterns[i].begin(), pat.subpatterns[i].end(), sp, ep);

            return std::to_string(total_range);
        }
Esempio n. 4
0
        wild_card_match_iterator3(const type_index& index,
                                  const std::vector<string_type>& s,
                                  size_t min_gap,
                                  size_t max_gap)
            : min_gap(min_gap), max_gap(max_gap), size3(s[s.size() - 1].size())
        {
            
            auto root_node = node_cache<type_index>(index.wt.root(), index);
            size_type sp = 1, ep = 0;

            for (auto sx : s) {
                forward_search(index.text.begin(), index.text.end(), index.wt, 0, index.wt.size()-1, sx.begin(), sx.end(), sp, ep);
                lex_ranges.emplace_back(index, sdsl::range_type(sp, ep), root_node);
                //std::cerr << std::string(sx.begin(), sx.end()) << ": " << sp << " " << ep << std::endl;
            }
if (valid())
            next();
        }
Esempio n. 5
0
void FindBar::locate_matches(const unicode& string) {
    matches_.clear();
    last_selected_match_ = -1;

    auto buf = window_.current_buffer()->buffer();
    auto start = buf->begin();
    Gtk::TextIter end;

    bool case_sensitive = case_sensitive_->get_active();

    while(start.forward_search(
              string.encode(), (case_sensitive) ? Gtk::TextSearchFlags(0) : Gtk::TEXT_SEARCH_CASE_INSENSITIVE,
              start, end)) {

        matches_.push_back(std::make_pair(start, end));
        start = buf->get_iter_at_offset(end.get_offset());
    }

}
Esempio n. 6
0
typename t_cst::size_type
forward_search(const t_cst& cst,
               typename t_cst::node_type& v,
               typename t_cst::size_type d,
               t_pat_iter begin,
               t_pat_iter end,
               typename t_cst::size_type& char_pos,
               SDSL_UNUSED typename std::enable_if<std::is_same<cst_tag, typename t_cst::index_category>::value, cst_tag>::type x = cst_tag()
              )
{
    if (begin==end)
        return cst.size(v);
    typename t_cst::size_type size=0;
    t_pat_iter it = begin;
    while (it != end and (size=forward_search(cst, v, d, *it, char_pos))) {
        ++d;
        ++it;
    }
    return size;
}