File: quickfindpattern.h

package info (click to toggle)
glogg 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 832 kB
  • sloc: cpp: 6,649; sh: 66; perl: 32; sed: 25; makefile: 11
file content (90 lines) | stat: -rw-r--r-- 2,660 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (C) 2010 Nicolas Bonnefon and other contributors
 *
 * This file is part of glogg.
 *
 * glogg 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 3 of the License, or
 * (at your option) any later version.
 *
 * glogg 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with glogg.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef QUICKFINDPATTERN_H
#define QUICKFINDPATTERN_H

#include <QObject>
#include <QString>
#include <QRegExp>
#include <QList>

// Represents a match result for QuickFind
class QuickFindMatch
{
  public:
    // Construct a match (must be initialised)
    QuickFindMatch( int start_column, int length )
    { startColumn_ = start_column; length_ = length; }

    // Accessor functions
    int startColumn() const { return startColumn_; }
    int length() const { return length_; }

  private:
    int startColumn_;
    int length_;
};

// Represents a search pattern for QuickFind (without its results)
class QuickFindPattern : public QObject
{
  Q_OBJECT

  public:
    // Construct an empty search
    QuickFindPattern();

    // Set the search to a new pattern
    void changeSearchPattern( const QString& pattern );

    // Returns whether the search is active (i.e. valid and non empty regexp)
    bool isActive() const { return active_; }

    // Returns whether the passed line match the quick find search.
    // If so, it populate the passed list with the list of matches
    // within this particular line.
    bool matchLine( const QString& line,
            QList<QuickFindMatch>& matches ) const;

    // Returns whether there is a match in the passed line, starting at
    // the passed column.
    // Results are stored internally.
    bool isLineMatching( const QString& line, int column = 0 ) const;

    // Same as isLineMatching but search backward
    bool isLineMatchingBackward( const QString& line, int column = -1 ) const;

    // Must be called when isLineMatching returns 'true', returns
    // the position of the first match found.
    void getLastMatch( int* start_col, int* end_col ) const;

  signals:
    // Sent when the pattern is changed
    void patternUpdated();

  private:
    bool active_;
    QRegExp regexp_;

    mutable int lastMatchStart_;
    mutable int lastMatchEnd_;
};

#endif