moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kvoctrain / kvoctrain / kvt-core / LineList.cpp
blob9141d40ce5a00d6bcb7e03d9d104425971bfaf01
1 /***************************************************************************
3 $Id$
5 maintain list of lines from QMultiLineEdit
7 -----------------------------------------------------------------------
9 begin : Sun Aug 13 10:00:53 MET 2000
11 copyright : (C) 1999-2001 Ewald Arnold
12 (C) 2001 The KDE-EDU team
14 email : kvoctrain@ewald-arnold.de
16 -----------------------------------------------------------------------
18 ***************************************************************************
20 ***************************************************************************
21 * *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
26 * *
27 ***************************************************************************/
29 #include "LineList.h"
31 #include <kdebug.h>
33 LineList::LineList (const QString &multilines)
35 setLines (multilines);
39 void LineList::setLines(const QString &the_lines )
41 multilines.clear();
42 QString lines = the_lines;
43 int pos;
44 if ((pos = lines.find ('\n')) >= 0) {
45 while (pos >= 0) {
46 multilines.push_back(lines.left(pos));
47 lines.remove (0, pos+1);
48 pos = lines.find ('\n');
52 if (lines.length() > 0) // empty string at end ==> not an entry!
53 multilines.push_back(lines);
55 normalizeWS();
59 void LineList::normalizeWS()
61 for (int i = 0; i < (int) multilines.size(); i++) {
62 multilines[i] = multilines[i].stripWhiteSpace();
63 // FIXME: more tolerance with WS? 2*SPC = 1*SPC...
68 int LineList::count() const
70 return multilines.size();
74 QString LineList::getLine (int index) const
76 if (index < (int) multilines.size())
77 return multilines[index];
78 else {
79 kdError() << "LineList::getLine: index too big";
80 return "";
85 QString LineList::allLines() const
87 QString ret;
88 if (multilines.size() > 0)
89 ret = multilines[0];
91 if (multilines.size() > 1) {
92 for (int i = 1; i < (int) multilines.size(); i++)
93 ret += "\n" + multilines[i];
95 return ret;