annotate logparser.cpp @ 262:a7843b03b4cf easyhg_v0.3.1

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