TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

filter.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
  2. /*
  3. * filter.h
  4. *
  5. * Copyright (C) 2004 Zack Rusin <zack@kde.org>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. */
  22. #ifndef TDESPELL_FILTER_H
  23. #define TDESPELL_FILTER_H
  24. #include <tqstring.h>
  25. #include <tdelibs_export.h>
  26. namespace KSpell2
  27. {
  28. class Settings;
  29. /**
  30. * Structure abstracts the word and its position in the
  31. * parent text.
  32. *
  33. * @author Zack Rusin <zack@kde.org>
  34. * @short struct represents word
  35. */
  36. struct Word
  37. {
  38. Word() : start( 0 ), end( true )
  39. {}
  40. Word( const TQString& w, int st, bool e = false )
  41. : word( w ), start( st ), end( e )
  42. {}
  43. Word( const Word& other )
  44. : word( other.word ), start( other.start ),
  45. end( other.end )
  46. {}
  47. TQString word;
  48. uint start;
  49. bool end;
  50. };
  51. /**
  52. * Filter is used to split text into words which
  53. * will be spell checked.
  54. *
  55. * @author Zack Rusin <zack@kde.org>
  56. * @short used to split text into words
  57. */
  58. class KDE_EXPORT Filter
  59. {
  60. public:
  61. static Filter *defaultFilter();
  62. public:
  63. Filter();
  64. virtual ~Filter();
  65. static Word end();
  66. /**
  67. * Sets the Settings object for this Filter
  68. */
  69. void setSettings( Settings* );
  70. /**
  71. * Returns currently used Settings object
  72. */
  73. Settings *settings() const;
  74. bool atEnd() const;
  75. void setBuffer( const TQString& buffer );
  76. TQString buffer() const;
  77. void restart();
  78. virtual Word nextWord() const;
  79. virtual Word previousWord() const;
  80. virtual Word wordAtPosition( unsigned int pos ) const;
  81. virtual void setCurrentPosition( int );
  82. virtual int currentPosition() const;
  83. virtual void replace( const Word& w, const TQString& newWord );
  84. /**
  85. * Should return the sentence containing the current word
  86. */
  87. virtual TQString context() const;
  88. protected:
  89. bool trySkipLinks() const;
  90. bool ignore( const TQString& word ) const;
  91. TQChar skipToLetter( uint &fromPosition ) const;
  92. bool shouldBeSkipped( bool wordWasUppercase, bool wordWasRunTogether,
  93. const TQString& foundWord ) const;
  94. protected:
  95. TQString m_buffer;
  96. mutable uint m_currentPosition;
  97. private:
  98. class Private;
  99. Private *d;
  100. };
  101. }
  102. #endif