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@244
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@244
|
9 Copyright (c) 2011 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@408
|
20 #include "common.h"
|
Chris@74
|
21 #include "debug.h"
|
Chris@74
|
22
|
Chris@43
|
23 #include <QStringList>
|
Chris@43
|
24 #include <QRegExp>
|
Chris@43
|
25
|
Chris@74
|
26 LogParser::LogParser(QString text, QString separator) :
|
Chris@74
|
27 m_text(text), m_sep(separator)
|
Chris@43
|
28 {
|
Chris@43
|
29 m_text.replace("\r\n", "\n");
|
Chris@43
|
30 }
|
Chris@43
|
31
|
Chris@43
|
32 QStringList LogParser::split()
|
Chris@43
|
33 {
|
Chris@43
|
34 return m_text.split("\n\n", QString::SkipEmptyParts);
|
Chris@43
|
35 }
|
Chris@43
|
36
|
Chris@43
|
37 LogList LogParser::parse()
|
Chris@43
|
38 {
|
Chris@43
|
39 LogList results;
|
Chris@108
|
40 QRegExp re(QString("^(\\w+)\\s*%1\\s+([^\\s].*)$").arg(m_sep));
|
Chris@43
|
41 QStringList entries = split();
|
Chris@43
|
42 foreach (QString entry, entries) {
|
Chris@43
|
43 LogEntry dictionary;
|
Chris@43
|
44 QStringList lines = entry.split('\n');
|
Chris@43
|
45 foreach (QString line, lines) {
|
Chris@43
|
46 if (re.indexIn(line) == 0) {
|
Chris@43
|
47 QString key = re.cap(1);
|
Chris@43
|
48 QString value = re.cap(2);
|
Chris@408
|
49 dictionary[key.trimmed()] = uniDecode(value);
|
Chris@43
|
50 }
|
Chris@43
|
51 }
|
Chris@43
|
52 results.push_back(dictionary);
|
Chris@43
|
53 }
|
Chris@43
|
54 return results;
|
Chris@43
|
55 }
|