34 using namespace KPIMUtils;
41 class KPIMUtils::SpellingFilter::Private
53 SpellingFilter::SpellingFilter(
const QString &text,
54 const QString "ePrefix,
55 UrlFiltering filterUrls,
56 EmailAddressFiltering filterEmailAddresses,
57 const QStringList &filterStrings )
58 : d( new KPIMUtils::SpellingFilter::Private )
63 if ( !quotePrefix.isEmpty() ) {
64 c.censorQuotations( quotePrefix );
71 if ( filterEmailAddresses ) {
72 c.censorEmailAddresses();
75 QStringList::const_iterator iter = filterStrings.begin();
76 QStringList::const_iterator endIter = filterStrings.end();
77 while ( iter != endIter ) {
78 c.censorString( *iter );
82 d->mFiltered = c.censoredText();
85 SpellingFilter::~SpellingFilter()
90 QString SpellingFilter::originalText()
const
95 QString SpellingFilter::filteredText()
const
104 SpellingFilter::TextCensor::TextCensor(
const QString &s )
109 void SpellingFilter::TextCensor::censorQuotations(
const QString "ePrefix )
112 while ( mPos < mText.length() ) {
114 findQuotation( quotePrefix );
115 if ( mPos < mText.length() ) {
117 skipQuotation( quotePrefix );
120 int len = mPos - start;
122 spaces.fill(
' ', len );
123 mText.replace( start, len, spaces );
128 void SpellingFilter::TextCensor::censorUrls()
131 while ( mPos < mText.length() ) {
134 while ( mPos < mText.length() && url.isEmpty() ) {
139 if ( mPos < mText.length() && !url.isEmpty() ) {
140 int start = mPos - url.length();
144 mText.replace( start, url.length(), url );
149 void SpellingFilter::TextCensor::censorEmailAddresses()
152 while ( mPos < mText.length() ) {
155 if ( mPos < mText.length() ) {
156 QString address = getEmailAddress();
158 if ( !address.isEmpty() ) {
159 int start = mPos - address.length();
163 mText.replace( start, address.length(), address );
169 void SpellingFilter::TextCensor::censorString(
const QString &s )
172 while ( mPos != -1 ) {
174 mPos = mText.indexOf( s, mPos );
178 spaces.fill(
' ', s.length() );
179 mText.replace( mPos, s.length(), spaces );
185 QString SpellingFilter::TextCensor::censoredText()
const
194 bool SpellingFilter::TextCensor::atLineStart()
const
197 ( mPos == 0 && mText.length() > 0 ) ||
198 ( mText[mPos - 1] ==
'\n' );
201 void SpellingFilter::TextCensor::skipLine()
203 mPos = mText.indexOf(
'\n', mPos );
205 mPos = mText.length();
211 bool SpellingFilter::TextCensor::atQuotation(
const QString "ePrefix )
const
213 return atLineStart() &&
214 mText.mid( mPos, quotePrefix.length() ) == quotePrefix;
217 void SpellingFilter::TextCensor::skipQuotation(
const QString "ePrefix )
219 while ( atQuotation( quotePrefix ) ) {
224 void SpellingFilter::TextCensor::findQuotation(
const QString "ePrefix )
226 while ( mPos < mText.length() &&
227 !atQuotation( quotePrefix ) ) {
232 void SpellingFilter::TextCensor::findEmailAddress()
234 while ( mPos < mText.length() && mText[mPos] != QLatin1Char(
'@' ) ) {
LinkLocator assists in identifying sections of text that can usefully be converted in hyperlinks in H...
This file is part of the KDEPIM Utilities library and provides the SpellingFilter class...