34using namespace KPIMUtils;
41class KPIMUtils::SpellingFilter::Private
54 const QString "ePrefix,
55 UrlFiltering filterUrls,
56 EmailAddressFiltering filterEmailAddresses,
57 const QStringList &filterStrings )
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();
85SpellingFilter::~SpellingFilter()
90QString SpellingFilter::originalText()
const
95QString SpellingFilter::filteredText()
const
104SpellingFilter::TextCensor::TextCensor(
const QString &s )
109void 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( QLatin1Char(
' '), len );
123 mText.replace( start, len, spaces );
128void 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();
143 url.fill( QLatin1Char(
' ') );
144 mText.replace( start, url.length(), url );
149void 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();
162 address.fill( QLatin1Char(
' ') );
163 mText.replace( start, address.length(), address );
169void SpellingFilter::TextCensor::censorString(
const QString &s )
172 while ( mPos != -1 ) {
174 mPos = mText.indexOf( s, mPos );
178 spaces.fill( QLatin1Char(
' '), s.length() );
179 mText.replace( mPos, s.length(), spaces );
185QString SpellingFilter::TextCensor::censoredText()
const
194bool SpellingFilter::TextCensor::atLineStart()
const
197 ( mPos == 0 && mText.length() > 0 ) ||
198 ( mText[mPos - 1] == QLatin1Char(
'\n') );
201void SpellingFilter::TextCensor::skipLine()
203 mPos = mText.indexOf( QLatin1Char(
'\n'), mPos );
205 mPos = mText.length();
211bool SpellingFilter::TextCensor::atQuotation(
const QString "ePrefix )
const
213 return atLineStart() &&
214 mText.mid( mPos, quotePrefix.length() ) == quotePrefix;
217void SpellingFilter::TextCensor::skipQuotation(
const QString "ePrefix )
219 while ( atQuotation( quotePrefix ) ) {
224void SpellingFilter::TextCensor::findQuotation(
const QString "ePrefix )
226 while ( mPos < mText.length() &&
227 !atQuotation( quotePrefix ) ) {
232void 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...
SpellingFilter(const QString &text, const QString "ePrefix, UrlFiltering filterUrls=FilterUrls, EmailAddressFiltering filterEmailAddresses=FilterEmailAddresses, const QStringList &filterStrings=QStringList())
Private class that helps to provide binary compatibility between releases.
This file is part of the KDEPIM Utilities library and provides the SpellingFilter class.