24 #include "spellingfilter.h"
30 SpellingFilter::SpellingFilter(
const TQString& text,
const TQString& quotePrefix,
31 UrlFiltering filterUrls, EmailAddressFiltering filterEmailAddresses,
32 const TQStringList& filterStrings)
37 if(!quotePrefix.isEmpty())
38 c.censorQuotations(quotePrefix);
43 if(filterEmailAddresses)
44 c.censorEmailAddresses();
46 TQStringList::const_iterator iter = filterStrings.begin();
47 while(iter != filterStrings.end())
49 c.censorString(*iter);
53 mFiltered = c.censoredText();
56 TQString SpellingFilter::originalText()
const
61 TQString SpellingFilter::filteredText()
const
70 SpellingFilter::TextCensor::TextCensor(
const TQString& s)
76 void SpellingFilter::TextCensor::censorQuotations(
const TQString& quotePrefix)
79 while(mPos <
static_cast<int>(mText.length()))
82 findQuotation(quotePrefix);
83 if(mPos <
static_cast<int>(mText.length()))
86 skipQuotation(quotePrefix);
89 int len = mPos - start;
91 spaces.fill(
' ', len);
92 mText.replace(start, len, spaces);
100 void SpellingFilter::TextCensor::censorUrls()
103 while(mPos <
static_cast<int>(mText.length()))
107 while(mPos <
static_cast<int>(mText.length()) && url.isEmpty())
113 if(mPos <
static_cast<int>(mText.length()) && !url.isEmpty())
115 int start = mPos - url.length();
119 mText.replace(start, url.length(), url);
127 void SpellingFilter::TextCensor::censorEmailAddresses()
130 while(mPos <
static_cast<int>(mText.length()))
134 if(mPos <
static_cast<int>(mText.length()))
136 TQString address = getEmailAddress();
138 if(!address.isEmpty())
140 int start = mPos - address.length();
144 mText.replace(start, address.length(), address);
153 void SpellingFilter::TextCensor::censorString(
const TQString& s)
159 mPos = mText.find(s, mPos);
164 spaces.fill(
' ', s.length());
165 mText.replace(mPos, s.length(), spaces);
174 TQString SpellingFilter::TextCensor::censoredText()
const
183 bool SpellingFilter::TextCensor::atLineStart()
const
185 return (mPos == 0 &&
static_cast<int>(mText.length()) > 0) || (mText[mPos - 1] ==
'\n');
188 void SpellingFilter::TextCensor::skipLine()
190 mPos = mText.find(
'\n', mPos);
192 mPos =
static_cast<int>(mText.length());
197 bool SpellingFilter::TextCensor::atQuotation(
const TQString& quotePrefix)
const
199 return atLineStart() &&
200 mText.mid(mPos, quotePrefix.length()) == quotePrefix;
203 void SpellingFilter::TextCensor::skipQuotation(
const TQString& quotePrefix)
205 while(atQuotation(quotePrefix))
209 void SpellingFilter::TextCensor::findQuotation(
const TQString& quotePrefix)
211 while(mPos <
static_cast<int>(mText.length()) && !atQuotation(quotePrefix))
215 void SpellingFilter::TextCensor::findEmailAddress()
217 while(mPos <
static_cast<int>(mText.length()) && mText[mPos] !=
'@')
LinkLocator assists in identifying sections of text that can usefully be converted in hyperlinks in h...