File: firstmatchline.cpp

package info (click to toggle)
recoll 1.43.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,512 kB
  • sloc: cpp: 104,170; python: 9,500; xml: 7,248; ansic: 6,447; sh: 1,212; perl: 130; makefile: 72
file content (72 lines) | stat: -rw-r--r-- 2,171 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Copyright (C) 2025 J.F.Dockes
 *
 * License: GPL 2.1
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "firstmatchline.h"

#include <string>

#include "log.h"
#include "rclconfig.h"
#include "rcldoc.h"
#include "textsplit.h"
#include "unacpp.h"

class TermLineSplitter : public TextSplit {
public:
    TermLineSplitter(const std::string& term)
        : TextSplit(), m_term(term) {
        LOGDEB1("TermLineSplitter: m_term " << m_term << "\n");
    }
    bool takeword(const std::string& _term, size_t, size_t, size_t) override {
        std::string term;
        if (o_index_stripchars) {
            if (!unacmaybefold(_term, term, UNACOP_UNACFOLD)) {
                LOGINFO("PlainToRich::takeword: unac failed for [" << term << "]\n");
                return true;
            }
        }
        LOGDEB1("TermLineSplitter: checking term " << term << "\n");
        if (term == m_term) {
            return false;
        }
        return true;
    }
    void newline(size_t) override {
        m_line++;
    }
    int getline() {
        return m_line;
    }
private:
    int m_line{1};
    std::string m_term;
};

int getFirstMatchLine(const Rcl::Doc &doc, const std::string& term)
{
    int line = 1;
    TermLineSplitter splitter(term);
    bool ret = splitter.text_to_words(doc.text);
    // The splitter takeword() breaks by returning false as soon as the term is found
    if (ret == false) {
        line = splitter.getline();
    }
    return line;
}