filter.h
00001 // -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 /* 00003 * filter.h 00004 * 00005 * Copyright (C) 2004 Zack Rusin <zack@kde.org> 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00020 * 02110-1301 USA 00021 */ 00022 00023 #ifndef KSPELL_FILTER_H 00024 #define KSPELL_FILTER_H 00025 00026 #include <tqstring.h> 00027 #include <kdelibs_export.h> 00028 00029 namespace KSpell2 00030 { 00031 class Settings; 00032 00040 struct Word 00041 { 00042 Word() : start( 0 ), end( true ) 00043 {} 00044 00045 Word( const TQString& w, int st, bool e = false ) 00046 : word( w ), start( st ), end( e ) 00047 {} 00048 Word( const Word& other ) 00049 : word( other.word ), start( other.start ), 00050 end( other.end ) 00051 {} 00052 00053 TQString word; 00054 uint start; 00055 bool end; 00056 }; 00057 00065 class KDE_EXPORT Filter 00066 { 00067 public: 00068 static Filter *defaultFilter(); 00069 public: 00070 Filter(); 00071 virtual ~Filter(); 00072 00073 static Word end(); 00074 00078 void setSettings( Settings* ); 00079 00083 Settings *settings() const; 00084 00085 bool atEnd() const; 00086 00087 void setBuffer( const TQString& buffer ); 00088 TQString buffer() const; 00089 00090 void restart(); 00091 00092 virtual Word nextWord() const; 00093 virtual Word previousWord() const; 00094 virtual Word wordAtPosition( unsigned int pos ) const; 00095 00096 virtual void setCurrentPosition( int ); 00097 virtual int currentPosition() const; 00098 virtual void replace( const Word& w, const TQString& newWord ); 00099 00103 virtual TQString context() const; 00104 protected: 00105 bool trySkipLinks() const; 00106 bool ignore( const TQString& word ) const; 00107 TQChar skipToLetter( uint &fromPosition ) const; 00108 bool shouldBeSkipped( bool wordWasUppercase, bool wordWasRunTogether, 00109 const TQString& foundWord ) const; 00110 00111 protected: 00112 TQString m_buffer; 00113 mutable uint m_currentPosition; 00114 00115 private: 00116 class Private; 00117 Private *d; 00118 }; 00119 00120 } 00121 00122 #endif