comparison logparser.cpp @ 43:c32067cd19f8

* Some experiments towards a graph history view
author Chris Cannam
date Sun, 07 Nov 2010 19:59:54 +0000
parents
children f583e44d9d31
comparison
equal deleted inserted replaced
42:9a89dedf260a 43:c32067cd19f8
1 #include "logparser.h"
2
3 #include <QStringList>
4 #include <QRegExp>
5
6 LogParser::LogParser(QString text) : m_text(text)
7 {
8 m_text.replace("\r\n", "\n");
9 }
10
11 QStringList LogParser::split()
12 {
13 return m_text.split("\n\n", QString::SkipEmptyParts);
14 }
15
16 LogList LogParser::parse()
17 {
18 LogList results;
19 QRegExp re("^(\\w+):\\s+(.*)$");
20 QStringList entries = split();
21 foreach (QString entry, entries) {
22 LogEntry dictionary;
23 QStringList lines = entry.split('\n');
24 foreach (QString line, lines) {
25 if (re.indexIn(line) == 0) {
26 QString key = re.cap(1);
27 QString value = re.cap(2);
28 dictionary[key] = value;
29 }
30 }
31 results.push_back(dictionary);
32 }
33 return results;
34 }