-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgreputil.cpp
More file actions
64 lines (58 loc) · 2.03 KB
/
greputil.cpp
File metadata and controls
64 lines (58 loc) · 2.03 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
62
63
/***************************************************************************
* Copyright 2010 Julien Desgats <julien.desgats@gmail.com> *
* *
* 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 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "greputil.h"
#include <algorithm>
#include <QChar>
#include <QComboBox>
static int const MAX_LAST_SEARCH_ITEMS_COUNT = 15;
QString substitudePattern(const QString& pattern, const QString& searchString)
{
QString subst = searchString;
QString result;
bool expectEscape = false;
foreach(const QChar &ch, pattern)
{
if(expectEscape)
{
expectEscape = false;
if(ch == '%')
result.append('%');
else if(ch == 's')
result.append(subst);
else
result.append('%').append(ch);
}
else if(ch == '%')
expectEscape = true;
else
result.append(ch);
}
return result;
}
QStringList qCombo2StringList( QComboBox* combo, bool allowEmpty )
{
QStringList list;
if (!combo) {
return list;
}
int skippedItem = -1;
if (!combo->currentText().isEmpty() || allowEmpty) {
list << combo->currentText();
}
if (combo->currentIndex() != -1 && !combo->itemText(combo->currentIndex()).isEmpty()) {
skippedItem = combo->currentIndex();
}
for (int i = 0; i < std::min(MAX_LAST_SEARCH_ITEMS_COUNT, combo->count()); ++i) {
if (i != skippedItem && !combo->itemText(i).isEmpty()) {
list << combo->itemText(i);
}
}
return list;
}