blob: 4e2542ecd38479ead673dcef6a53f352f88e9506 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/***************************************************************************
ksfilereader.cpp - description
-------------------
begin : Tue Jan 28 2003
copyright : (C) 2003 by Heiko Evermann
email : heiko@evermann.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <tqfile.h>
#include <tqstring.h>
#include "ksfilereader.h"
KSFileReader::KSFileReader(TQFile& file) {
// read the whole file at once. This works well at least for the smaller files.
TQByteArray data = file.readAll();
TQString sAll = TQString::fromUtf8( data.data(), data.size() );
// split into list of lines
lines = TQStringList::split( "\n", sAll );
// how many lines did we get?
numLines = lines.size();
// set index to start
curLine = 0;
// we do not need the file any more
file.close();
}
KSFileReader::~KSFileReader(){
}
bool KSFileReader::hasMoreLines() {
return (curLine < numLines);
}
TQString& KSFileReader::readLine(){
// hint: use curLine as index, after that increment curLine
// This means that the programming language c++ should better be renamed to ++c,
// otherwise the name means: improve the c programming language, but use it the
// way it was before the improvements...
return lines[curLine++];
}
bool KSFileReader::setLine(int i) {
if (i <= numLines) {
curLine = i;
return true;
} else {
return false;
}
}
#include "ksfilereader.moc"
|