libkmime

kqcstringsplitter.cpp

00001 /*
00002     kqcstringsplitter.cpp
00003 
00004     KNode, the KDE newsreader
00005     Copyright (c) 1999-2001 the KNode authors.
00006     See file AUTHORS for details
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012     You should have received a copy of the GNU General Public License
00013     along with this program; if not, write to the Free Software Foundation,
00014     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
00015 */
00016 
00017 #include "kqcstringsplitter.h"
00018 
00019 KQCStringSplitter::KQCStringSplitter()
00020 {
00021   reset();
00022 }
00023 
00024 
00025 
00026 
00027 KQCStringSplitter::~KQCStringSplitter()
00028 {
00029 }
00030 
00031 
00032 
00033 void KQCStringSplitter::init(const QCString &str, const char *s)
00034 {
00035   sep=s;
00036   src=str;
00037 }
00038 
00039 
00040 
00041 void KQCStringSplitter::init(const char *str, const char *s)
00042 {
00043   sep=s;
00044   src=str;
00045 }
00046 
00047 bool KQCStringSplitter::first()
00048 {
00049   /*int plus;
00050   if(incSep) plus=sep.length();
00051   else plus=0;  */
00052   
00053   start=0;
00054   
00055   end=src.find(sep, start);
00056   
00057   if(end!=-1) {
00058     dst=src.mid(start, end);
00059     return true;
00060   }
00061   else {
00062     start=src.length();
00063     end=start;
00064     return false;
00065   }
00066     
00067 }
00068 
00069 
00070 
00071 bool KQCStringSplitter::last()
00072 {
00073   /*int startplus, endplus;
00074   
00075   if(incSep) {
00076     startplus=0;
00077     endplus=sep.length();
00078   }
00079   else {
00080     startplus=sep.length();
00081     endplus=0;
00082   }*/
00083     
00084   end=src.length();
00085     
00086   start=src.findRev(sep,end);
00087   
00088   if(start!=-1) {
00089     dst=src.mid(start, end-start);
00090     return true;
00091   }
00092   else return false;
00093   
00094 
00095 }
00096 
00097 
00098 
00099 bool KQCStringSplitter::next()
00100 {
00101   /*int plus;
00102   if(incSep) plus=sep.length();
00103   else plus=0;*/
00104   
00105   start=end+1;
00106   
00107   if(start< (int) src.length()) {
00108     
00109     end=src.find(sep, start);
00110     
00111     if(end!=-1) {
00112       dst=src.mid(start, end-start);
00113     }
00114     else {
00115       dst=src.mid(start, src.length()-start);
00116       start=src.length();
00117       end=src.length();
00118     }
00119     
00120     return true;
00121   }
00122   else return false;
00123   
00124 }
00125 
00126 
00127 
00128 bool KQCStringSplitter::prev()
00129 {
00130   /*int startplus, endplus;
00131   
00132   if(incSep) {
00133     startplus=0;
00134     endplus=sep.length();
00135   }
00136   else {
00137     startplus=sep.length();
00138     endplus=0;
00139   }*/
00140   
00141   end=start-1;
00142   
00143   if(end>0) {
00144     
00145     start=src.findRev(sep,end);
00146     
00147     if(start!=-1)
00148       dst=src.mid(start, end-start);
00149     
00150     else {
00151       dst=src.mid(0, end+1);
00152       end=0;
00153       start=0;
00154     }
00155   
00156     return true;
00157   }
00158   else return false;
00159 
00160 }
00161 
KDE Home | KDE Accessibility Home | Description of Access Keys