-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchstring.cpp
More file actions
61 lines (54 loc) · 1.31 KB
/
Copy pathsearchstring.cpp
File metadata and controls
61 lines (54 loc) · 1.31 KB
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
#include "searchstring.h"
#include <QRegularExpression>
#include <QDebug>
SearchString::SearchString(QString searchStr, const QString &t)
{
searchString = searchStr;
text = t;
}
int SearchString::beginSearch(){
QRegularExpression pattern = QRegularExpression(searchString);
QRegularExpressionMatchIterator matchIterator = pattern.globalMatch(text);
while(matchIterator.hasNext()){
QRegularExpressionMatch match = matchIterator.next();
searchList.append(match.capturedStart());
}
if(searchList.count() >= 1){
return searchList.at(0);
}else{
return -1;
}
}
int SearchString::searchPrevious(){
if(searchNow == 0){
return -1;
}else{
int res = searchList.at(--searchNow);
qDebug() << res;
return res;
}
}
int SearchString::searchNext(){
if(searchNow == searchList.count() - 1){
return -1;
}else{
int res = searchList.at(++searchNow);
qDebug() << res;
return res;
}
}
int SearchString::cursorNow(){
if(searchList.count() == 0){
return -1;
}
return searchList.at(searchNow);
}
int SearchString::count(){
return searchList.count();
}
int SearchString::cursorI(int i){
if(i < 0 || i >= searchList.count()){
return -1;
}
return searchList.at(i);
}