Mercurial > hg > easyhg
annotate 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 |
rev | line source |
---|---|
Chris@43 | 1 #include "logparser.h" |
Chris@43 | 2 |
Chris@43 | 3 #include <QStringList> |
Chris@43 | 4 #include <QRegExp> |
Chris@43 | 5 |
Chris@43 | 6 LogParser::LogParser(QString text) : m_text(text) |
Chris@43 | 7 { |
Chris@43 | 8 m_text.replace("\r\n", "\n"); |
Chris@43 | 9 } |
Chris@43 | 10 |
Chris@43 | 11 QStringList LogParser::split() |
Chris@43 | 12 { |
Chris@43 | 13 return m_text.split("\n\n", QString::SkipEmptyParts); |
Chris@43 | 14 } |
Chris@43 | 15 |
Chris@43 | 16 LogList LogParser::parse() |
Chris@43 | 17 { |
Chris@43 | 18 LogList results; |
Chris@43 | 19 QRegExp re("^(\\w+):\\s+(.*)$"); |
Chris@43 | 20 QStringList entries = split(); |
Chris@43 | 21 foreach (QString entry, entries) { |
Chris@43 | 22 LogEntry dictionary; |
Chris@43 | 23 QStringList lines = entry.split('\n'); |
Chris@43 | 24 foreach (QString line, lines) { |
Chris@43 | 25 if (re.indexIn(line) == 0) { |
Chris@43 | 26 QString key = re.cap(1); |
Chris@43 | 27 QString value = re.cap(2); |
Chris@43 | 28 dictionary[key] = value; |
Chris@43 | 29 } |
Chris@43 | 30 } |
Chris@43 | 31 results.push_back(dictionary); |
Chris@43 | 32 } |
Chris@43 | 33 return results; |
Chris@43 | 34 } |