-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlirc.cpp
More file actions
54 lines (47 loc) · 1.35 KB
/
lirc.cpp
File metadata and controls
54 lines (47 loc) · 1.35 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
#include "lirc.h"
#include <QRegExp>
#include <QStringList>
const QString Lirc::CommandSeparator = "begin remote";
Lirc::Lirc():
m_name(""), m_isBroken(false)
{
}
bool Lirc::Parse(QString rawString)
{
int pos = 0;
QRegExp rxName("(name\\s+)(\\w+)");
pos = rxName.indexIn(rawString, pos) + rxName.matchedLength();
m_name = rxName.cap(2);
if (m_name.isEmpty())
{
m_isBroken = true;
return false;
}
QRegExp rxRawCodesBegin("(begin\\s+raw_codes)");
int rawCodesPos = rxRawCodesBegin.indexIn(rawString, pos);
if (rawCodesPos != -1)
{
pos = rawCodesPos;
QRegExp rxCodeName("(name\\s+)(\\w+)");
while ((pos = rxCodeName.indexIn(rawString, pos, QRegExp::CaretAtOffset) +
rxCodeName.captureCount()) > rxName.pos())
m_codes.append(rxCodeName.cap(2));
}
else
{
QRegExp rxBeginCodes("(begin\\s+codes)");
pos = rxBeginCodes.indexIn(rawString, pos);
QRegExp rxCodeName("(\\s)(\\w+)(\\s+)(0x[\\d\\w]+)");
while ((pos = rxCodeName.indexIn(rawString, pos, QRegExp::CaretAtOffset) +
rxCodeName.captureCount()) > rxName.pos())
m_codes.append(rxCodeName.cap(2));
}
return true;
}
QStringList Lirc::GetCommands()
{
QStringList list;
foreach(QString lirc, m_codes)
list << lirc;
return list;
}