-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathgatograderstring.cpp
More file actions
43 lines (36 loc) · 895 Bytes
/
gatograderstring.cpp
File metadata and controls
43 lines (36 loc) · 895 Bytes
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
#include <QStringList>
#include <QString>
#include <QList>
#include <QDebug>
#include <QRegularExpression>
#include "gatograderstring.h"
/* The setting for the searcher rule is just a comma-delimited
* set of 8-bit bytes.
*
* "3a,2b,97,6c", for example.
*/
GatoGraderString::GatoGraderString(QString setting){
QStringList settings=setting.split(QRegularExpression(",|\\s+"));
QByteArray ba;
bool okay;
for(int i=0; i<settings.length(); i++){
long l=settings[i].toLong(&okay,16);
if(okay)
ba.append((char) l);
else
qDebug()<<"Invalid hex byte:"<<l;
}
target=ba;
}
GatoGraderString::~GatoGraderString(){
}
/* 100 if we contain the string.
* 0 if we don't.
*
* Middle grounds would be useful here.
*/
int GatoGraderString::grade(QByteArray ba){
if(ba.contains(target))
return 100;
return 0;
}