Prepare 1.0 alpha3 release.
[tagua/yd.git] / src / decoratedmove.cpp
blob89ae911a1d5a62777a1d3003921171672c8fc102
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include "decoratedmove.h"
13 #include <iostream>
14 #include <QRegExp>
16 #include "common.h"
18 DecoratedMove::DecoratedMove() { }
20 DecoratedMove::DecoratedMove(const QString& str) {
21 load(str);
24 void DecoratedMove::load(const QString& str) {
25 static QRegExp figurine("\\{[^}]*\\}");
26 int offset = 0;
27 int begin;
28 while ((begin = figurine.indexIn(str, offset)) != -1) {
29 if (begin > offset) {
30 m_elements.push_back(str.mid(offset, begin - offset));
32 m_elements.push_back(MovePart(str.mid(begin + 1, figurine.matchedLength() - 2), MovePart::Figurine));
33 offset = begin + figurine.matchedLength();
36 if (offset < str.length())
37 m_elements.push_back(str.mid(offset));
40 void DecoratedMove::push_back(const MovePart& part) {
41 m_elements.push_back(part);
44 MovePart DecoratedMove::operator[](int index) const {
45 return m_elements[index];
48 unsigned int DecoratedMove::size() const {
49 return m_elements.size();