comparison src/logparser.cpp @ 370:b9c153e00e84

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