102 if(str.isEmpty() || (str.length() == 1 && !str[0].isLetter())) {
105 const int length = str.length();
106 for(
int i = 0; i < length; ++i) {
107 if(!str[i].isNumber()) {
118 QTextBoundaryFinder::BoundaryReasons boundary = finder.boundaryReasons();
119 int start = finder.position(), end = finder.position();
120 bool inWord = (boundary & QTextBoundaryFinder::StartWord) != 0;
121 while (finder.toNextBoundary() > 0) {
122 boundary = finder.boundaryReasons();
123 if ((boundary & QTextBoundaryFinder::EndWord) && inWord) {
124 end = finder.position();
125 QString str = finder.string().mid(start, end - start);
130 kDebug() <<
"Word at " << start <<
" word = '"
131 << str <<
"', len = " << str.length();
137 if ((boundary & QTextBoundaryFinder::StartWord)) {
138 start = finder.position();
147 QString &word,
int &bufferStart)
149 int oldPosition = finder.position();
151 finder.setPosition(at);
152 if (!finder.isAtBoundary() || (finder.boundaryReasons() & QTextBoundaryFinder::EndWord)) {
153 if (finder.toPreviousBoundary() <= 0) {
157 if (at > 0 && finder.string().length() > 0) {
164 finder.setPosition(oldPosition);
172 bool allUppercase =
false;
173 bool runTogether =
false;
178 allUppercase = ( foundWord == foundWord.toUpper() );
185 return Word( foundWord, start );
194 return Word( foundWord, start );
217 int oldLen = w.
word.length();
221 m_finder = QTextBoundaryFinder(QTextBoundaryFinder::Word,
231 int signedPosition =
m_finder.position();
232 bool begin = (signedPosition - len/2)<=0;
237 buffer = buffer.replace( word.
start, word.
word.length(),
238 QString::fromLatin1(
"<b>%1</b>" ).arg( word.
word ) );
242 context = QString::fromLatin1(
"%1...")
243 .arg( buffer.mid( 0, len ) );
245 context = QString::fromLatin1(
"...%1...")
246 .arg( buffer.mid(
m_finder.position() - 20, len ) );
248 context.replace( QLatin1Char(
'\n'), QLatin1Char(
' ') );
258 if (currentPosition < 0 || currentPosition >=
m_buffer.length())
260 currentChar =
m_buffer.at( currentPosition );
264 if ( currentChar == QLatin1Char(
':')
265 && (currentPosition+1 < length)
266 && (
m_buffer.at( ++currentPosition ) == QLatin1Char(
'/') || ( currentPosition + 1 ) >= length ) ) {
269 while ( !
m_buffer.at( currentPosition++ ).isSpace() && currentPosition < length )
271 m_finder.setPosition(currentPosition);
276 if ( currentChar == QLatin1Char(
'@')) {
277 while ( ++currentPosition < length && !
m_buffer.at( currentPosition ).isSpace() )
279 m_finder.setPosition(currentPosition);
288 return d->settings && d->settings->ignore( word );
292 const QString& foundWord )
const
294 bool checkUpper = ( d->settings ) ?
295 d->settings->checkUppercase () :
true;
297 bool skipRunTogether = ( d->settings ) ?
298 d->settings->skipRunTogether() :
true;
303 if ( wordWasUppercase && !checkUpper )
306 if ( wordWasRunTogether && skipRunTogether )
309 return ignore( foundWord );
QTextBoundaryFinder m_finder
static bool isValidWord(const QString &str)
virtual Word wordAtPosition(unsigned int pos) const
Filter is used to split text into words which will be spell checked.
virtual Word nextWord() const
Settings * settings() const
Returns currently used Settings object.
virtual void setCurrentPosition(int)
virtual int currentPosition() const
Structure abstracts the word and its position in the parent text.
static bool finderWordAt(QTextBoundaryFinder &finder, int at, QString &word, int &bufferStart)
bool shouldBeSkipped(bool wordWasUppercase, bool wordWasRunTogether, const QString &foundWord) const
void setSettings(Settings *)
Sets the Settings object for this Filter.
virtual QString context() const
Should return the sentence containing the current word.
virtual void replace(const Word &w, const QString &newWord)
static Filter * defaultFilter()
static bool finderNextWord(QTextBoundaryFinder &finder, QString &word, int &bufferStart)
bool trySkipLinks() const
bool ignore(const QString &word) const
void setBuffer(const QString &buffer)