libkmime

kqcstringsplitter.cpp
1/*
2 kqcstringsplitter.cpp
3
4 KNode, the KDE newsreader
5 Copyright (c) 1999-2001 the KNode authors.
6 See file AUTHORS for details
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software Foundation,
14 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15*/
16
17#include "kqcstringsplitter.h"
18
19KTQCStringSplitter::KTQCStringSplitter()
20{
21 reset();
22}
23
24
25
26
27KTQCStringSplitter::~KTQCStringSplitter()
28{
29}
30
31
32
33void KTQCStringSplitter::init(const TQCString &str, const char *s)
34{
35 sep=s;
36 src=str;
37}
38
39
40
41void KTQCStringSplitter::init(const char *str, const char *s)
42{
43 sep=s;
44 src=str;
45}
46
47bool KTQCStringSplitter::first()
48{
49 /*int plus;
50 if(incSep) plus=sep.length();
51 else plus=0; */
52
53 start=0;
54
55 end=src.find(sep.data(), start);
56
57 if(end!=-1) {
58 dst=src.mid(start, end);
59 return true;
60 }
61 else {
62 start=src.length();
63 end=start;
64 return false;
65 }
66
67}
68
69
70
71bool KTQCStringSplitter::last()
72{
73 /*int startplus, endplus;
74
75 if(incSep) {
76 startplus=0;
77 endplus=sep.length();
78 }
79 else {
80 startplus=sep.length();
81 endplus=0;
82 }*/
83
84 end=src.length();
85
86 start=src.findRev(sep.data(),end);
87
88 if(start!=-1) {
89 dst=src.mid(start, end-start);
90 return true;
91 }
92 else return false;
93
94
95}
96
97
98
99bool KTQCStringSplitter::next()
100{
101 /*int plus;
102 if(incSep) plus=sep.length();
103 else plus=0;*/
104
105 start=end+1;
106
107 if(start< (int) src.length()) {
108
109 end=src.find(sep.data(), start);
110
111 if(end!=-1) {
112 dst=src.mid(start, end-start);
113 }
114 else {
115 dst=src.mid(start, src.length()-start);
116 start=src.length();
117 end=src.length();
118 }
119
120 return true;
121 }
122 else return false;
123
124}
125
126
127
128bool KTQCStringSplitter::prev()
129{
130 /*int startplus, endplus;
131
132 if(incSep) {
133 startplus=0;
134 endplus=sep.length();
135 }
136 else {
137 startplus=sep.length();
138 endplus=0;
139 }*/
140
141 end=start-1;
142
143 if(end>0) {
144
145 start=src.findRev(sep.data(),end);
146
147 if(start!=-1)
148 dst=src.mid(start, end-start);
149
150 else {
151 dst=src.mid(0, end+1);
152 end=0;
153 start=0;
154 }
155
156 return true;
157 }
158 else return false;
159
160}
161