Chris@57
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@57
|
2
|
Chris@57
|
3 /*
|
Chris@57
|
4 EasyMercurial
|
Chris@57
|
5
|
Chris@57
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@57
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@57
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@57
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@57
|
10
|
Chris@57
|
11 This program is free software; you can redistribute it and/or
|
Chris@57
|
12 modify it under the terms of the GNU General Public License as
|
Chris@57
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@57
|
14 License, or (at your option) any later version. See the file
|
Chris@57
|
15 COPYING included with this distribution for more information.
|
Chris@57
|
16 */
|
Chris@57
|
17
|
Chris@43
|
18 #include "logparser.h"
|
Chris@43
|
19
|
Chris@43
|
20 #include <QStringList>
|
Chris@43
|
21 #include <QRegExp>
|
Chris@43
|
22
|
Chris@43
|
23 LogParser::LogParser(QString text) : m_text(text)
|
Chris@43
|
24 {
|
Chris@43
|
25 m_text.replace("\r\n", "\n");
|
Chris@43
|
26 }
|
Chris@43
|
27
|
Chris@43
|
28 QStringList LogParser::split()
|
Chris@43
|
29 {
|
Chris@43
|
30 return m_text.split("\n\n", QString::SkipEmptyParts);
|
Chris@43
|
31 }
|
Chris@43
|
32
|
Chris@43
|
33 LogList LogParser::parse()
|
Chris@43
|
34 {
|
Chris@43
|
35 LogList results;
|
Chris@43
|
36 QRegExp re("^(\\w+):\\s+(.*)$");
|
Chris@43
|
37 QStringList entries = split();
|
Chris@43
|
38 foreach (QString entry, entries) {
|
Chris@43
|
39 LogEntry dictionary;
|
Chris@43
|
40 QStringList lines = entry.split('\n');
|
Chris@43
|
41 foreach (QString line, lines) {
|
Chris@43
|
42 if (re.indexIn(line) == 0) {
|
Chris@43
|
43 QString key = re.cap(1);
|
Chris@43
|
44 QString value = re.cap(2);
|
Chris@43
|
45 dictionary[key] = value;
|
Chris@43
|
46 }
|
Chris@43
|
47 }
|
Chris@43
|
48 results.push_back(dictionary);
|
Chris@43
|
49 }
|
Chris@43
|
50 return results;
|
Chris@43
|
51 }
|