Skip to content

Commit

Permalink
clean: reduce compiler warning implicit int -> qsizetype conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying committed Feb 7, 2025
1 parent 8e7f707 commit 264781d
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[src/**.{cc,hh}]
indent_style = space
indent_size = 2
8 changes: 4 additions & 4 deletions src/article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,13 @@ void ArticleRequest::altSearchFinished()
int ArticleRequest::findEndOfCloseDiv( const QString & str, int pos )
{
for ( ;; ) {
const int n1 = str.indexOf( "</div>", pos );
const auto n1 = str.indexOf( "</div>", pos );
if ( n1 <= 0 ) {
return n1;
}

// will there be some custom tags starts with <div but not <div> ,such as <divider>
const int n2 = str.indexOf( RX::Html::startDivTag, pos );
const auto n2 = str.indexOf( RX::Html::startDivTag, pos );
if ( n2 <= 0 || n2 > n1 ) {
return n1 + 6;
}
Expand Down Expand Up @@ -569,7 +569,7 @@ bool ArticleRequest::isCollapsable( Dictionary::DataRequest & req, QString const
if ( !needExpandOptionalParts ) {
// Strip DSL optional parts
for ( ;; ) {
const int pos = text.indexOf( "<div class=\"dsl_opt\"" );
const auto pos = text.indexOf( "<div class=\"dsl_opt\"" );
if ( pos > 0 ) {
const int endPos = findEndOfCloseDiv( text, pos + 1 );
if ( endPos > pos ) {
Expand Down Expand Up @@ -795,7 +795,7 @@ int ArticleRequest::htmlTextSize( QString html )
html.remove( QRegularExpression( "<link\\s*[^>]*>", QRegularExpression::CaseInsensitiveOption ) )
.remove( QRegularExpression( R"(<script[\s\S]*?>[\s\S]*?<\/script>)",
QRegularExpression::CaseInsensitiveOption | QRegularExpression::MultilineOption ) );
int size = QTextDocumentFragment::fromHtml( stripStyleSheet ).toPlainText().length();
auto size = QTextDocumentFragment::fromHtml( stripStyleSheet ).toPlainText().length();

return size;
}
Expand Down
14 changes: 5 additions & 9 deletions src/common/utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ inline bool isCJKChar( ushort ch )
*/
inline QString rstrip( const QString & str )
{
int n = str.size() - 1;
for ( ; n >= 0; --n ) {
for ( auto n = str.size() - 1; n >= 0; --n ) {
if ( !str.at( n ).isSpace() ) {
return str.left( n + 1 );
}
Expand Down Expand Up @@ -64,17 +63,15 @@ bool endsWithIgnoreCase( QByteArrayView str, QByteArrayView extension );
inline QString trimNonChar( const QString & str )
{
QString remain;
int n = str.size() - 1;
for ( ; n >= 0; --n ) {
for ( auto n = str.size() - 1; n >= 0; --n ) {
auto c = str.at( n );
if ( !c.isSpace() && !c.isSymbol() && !c.isNonCharacter() && !c.isPunct() && !c.isNull() ) {
remain = str.left( n + 1 );
break;
}
}

n = 0;
for ( ; n < remain.size(); n++ ) {
for ( auto n = 0; n < remain.size(); n++ ) {
auto c = remain.at( n );
if ( !c.isSpace() && !c.isSymbol() && !c.isNonCharacter() && !c.isPunct() ) {
return remain.mid( n );
Expand All @@ -92,8 +89,7 @@ inline QString trimNonChar( const QString & str )
*/
inline QString rstripnull( const QString & str )
{
int n = str.size() - 1;
for ( ; n >= 0; --n ) {
for ( auto n = str.size() - 1; n >= 0; --n ) {
auto c = str.at( n );
if ( !c.isSpace() && !c.isNull() ) {
return str.left( n + 1 );
Expand Down Expand Up @@ -298,7 +294,7 @@ inline QString getHostBase( QString const & host )
{
QStringList domains = host.split( '.' );

int left = domains.size();
auto left = domains.size();

// Skip last <=3-letter domain name
if ( left && domains[ left - 1 ].size() <= 3 )
Expand Down
2 changes: 1 addition & 1 deletion src/dict/bgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ void BglDictionary::replaceCharsetEntities( string & text )

QRegularExpression oneValueExp( "\\s*([0-9a-fA-F]+)\\s*;" );
QString result;
int pos = 0;
qsizetype pos = 0;

QRegularExpressionMatchIterator it = charsetExp.globalMatch( str );
while ( it.hasNext() ) {
Expand Down
2 changes: 1 addition & 1 deletion src/dict/dictdfiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ sptr< Dictionary::DataRequest > DictdDictionary::getArticle( std::u32string cons
.replace( refs, R"(<a href="gdlookup://localhost/\1">\1</a>)" );
convertedText.erase();

int pos = 0;
qsizetype pos = 0;

QString articleNewString;
QRegularExpressionMatchIterator it = links.globalMatch( articleString );
Expand Down
12 changes: 6 additions & 6 deletions src/dict/dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ void Class::isolateCSS( QString & css, QString const & wrapperSelector )
QRegularExpression reg3( "[,;\\{]" );


int currentPos = 0;
qsizetype currentPos = 0;
QString newCSS;
QString prefix( "#gdfrom-" );
prefix += QString::fromLatin1( getId().c_str() );
Expand All @@ -402,14 +402,14 @@ void Class::isolateCSS( QString & css, QString const & wrapperSelector )
if ( ch == '@' ) {
// @ rules

int n = currentPos;
qsizetype n = currentPos;
if ( css.mid( currentPos, 7 ).compare( "@import", Qt::CaseInsensitive ) == 0
|| css.mid( currentPos, 10 ).compare( "@font-face", Qt::CaseInsensitive ) == 0
|| css.mid( currentPos, 10 ).compare( "@namespace", Qt::CaseInsensitive ) == 0
|| css.mid( currentPos, 8 ).compare( "@charset", Qt::CaseInsensitive ) == 0 ) {
// Copy rule as is.
n = css.indexOf( ';', currentPos );
int n2 = css.indexOf( '{', currentPos );
auto n2 = css.indexOf( '{', currentPos );
if ( n2 > 0 && n > n2 ) {
n = n2 - 1;
}
Expand Down Expand Up @@ -447,7 +447,7 @@ void Class::isolateCSS( QString & css, QString const & wrapperSelector )
// Selector declaration block.
// We copy it up to '}' as is.

int n = css.indexOf( '}', currentPos );
auto n = css.indexOf( '}', currentPos );
newCSS.append( css.mid( currentPos, n == -1 ? n : n - currentPos + 1 ) );
if ( n < 0 ) {
break;
Expand All @@ -460,7 +460,7 @@ void Class::isolateCSS( QString & css, QString const & wrapperSelector )
if ( ch.isLetter() || ch == '*' ) {
// Check for namespace prefix
QChar chr;
for ( int i = currentPos; i < css.length(); i++ ) {
for ( auto i = currentPos; i < css.length(); i++ ) {
chr = css[ i ];
if ( chr.isLetterOrNumber() || chr.isMark() || chr == '_' || chr == '-'
|| ( chr == '*' && i == currentPos ) ) {
Expand All @@ -482,7 +482,7 @@ void Class::isolateCSS( QString & css, QString const & wrapperSelector )
// This is some selector.
// We must to add the isolate prefix to it.

int n = css.indexOf( reg2, currentPos + 1 );
auto n = css.indexOf( reg2, currentPos + 1 );
QString s = css.mid( currentPos, n < 0 ? n : n - currentPos );
if ( n < 0 ) {
newCSS.append( s );
Expand Down
18 changes: 9 additions & 9 deletions src/dict/dictserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DictServerImpl: public QObject

void run( std::function< void() > callback )
{
int pos = url.indexOf( "://" );
auto pos = url.indexOf( "://" );
if ( pos < 0 ) {
url = "dict://" + url;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ class DictServerImpl: public QObject
QString authCommand = QString( "AUTH " );
QString authString = msgId;

int pos = serverUrl.userInfo().indexOf( QRegularExpression( "[:;]" ) );
auto pos = serverUrl.userInfo().indexOf( QRegularExpression( "[:;]" ) );
if ( pos > 0 ) {
authCommand += serverUrl.userInfo().left( pos );
authString += serverUrl.userInfo().mid( pos + 1 );
Expand Down Expand Up @@ -202,7 +202,7 @@ class DictServerDictionary: public Dictionary::Class

dictionaryName = name_;

int pos = url.indexOf( "://" );
auto pos = url.indexOf( "://" );
if ( pos < 0 ) {
url = "dict://" + url;
}
Expand Down Expand Up @@ -242,7 +242,7 @@ class DictServerDictionary: public Dictionary::Class

if ( reply.left( 3 ) == "110" ) {
state = DictServerState::DB_DATA;
int countPos = reply.indexOf( ' ', 4 );
auto countPos = reply.indexOf( ' ', 4 );
// Get databases count
int count = reply.mid( 4, countPos > 4 ? countPos - 4 : -1 ).toInt();

Expand Down Expand Up @@ -525,7 +525,7 @@ void DictServerWordSearchRequest::readMatchData( QByteArray & reply )
continue;
}

int pos = reply.indexOf( ' ' );
auto pos = reply.indexOf( ' ' );
if ( pos >= 0 ) {
QString word = reply.mid( pos + 1 );
if ( word.endsWith( '\"' ) ) {
Expand Down Expand Up @@ -654,7 +654,7 @@ class DictServerArticleRequest: public Dictionary::DataRequest
}

_articleText = QString::fromUtf8( articleStr.c_str(), articleStr.size() );
int pos;
qsizetype pos;
if ( !contentInHtml ) {
_articleText = _articleText.replace( refs, R"(<a href="gdlookup://localhost/\1">\1</a>)" );

Expand Down Expand Up @@ -784,7 +784,7 @@ void DictServerArticleRequest::run()
auto code = reply.left( 3 );
if ( reply.left( 3 ) == "150" ) {
// Articles found
int countPos = reply.indexOf( ' ', 4 );
auto countPos = reply.indexOf( ' ', 4 );
// Get articles count,
// todo ,how to use this count?
int count = reply.mid( 4, countPos > 4 ? countPos - 4 : -1 ).toInt();
Expand Down Expand Up @@ -818,8 +818,8 @@ void DictServerArticleRequest::readData( QByteArray reply )
}

if ( reply.left( 3 ) == "151" ) {
int pos = 4;
int endPos;
qsizetype pos = 4;
qsizetype endPos;

// Skip requested word
if ( reply[ pos ] == '\"' ) {
Expand Down
14 changes: 7 additions & 7 deletions src/dict/dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,9 @@ string DslDictionary::getNodeLink( ArticleDom::Node const & node )
string link;
if ( !node.tagAttrs.empty() ) {
QString attrs = QString::fromStdU32String( node.tagAttrs );
int n = attrs.indexOf( "target=\"" );
auto n = attrs.indexOf( "target=\"" );
if ( n >= 0 ) {
int n_end = attrs.indexOf( '\"', n + 8 );
auto n_end = attrs.indexOf( '\"', n + 8 );
QString target = attrs.mid( n + 8, n_end > n + 8 ? n_end - ( n + 8 ) : -1 );
link = Html::escape( Filetype::simplifyString( string( target.toUtf8().data() ), false ) );
}
Expand Down Expand Up @@ -916,7 +916,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
// Find ISO 639-1 code
string langcode;
QString attr = QString::fromStdU32String( node.tagAttrs );
int n = attr.indexOf( "id=" );
auto n = attr.indexOf( "id=" );
if ( n >= 0 ) {
int id = attr.mid( n + 3 ).toInt();
if ( id ) {
Expand All @@ -926,7 +926,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
else {
n = attr.indexOf( "name=\"" );
if ( n >= 0 ) {
int n2 = attr.indexOf( '\"', n + 6 );
auto n2 = attr.indexOf( '\"', n + 6 );
if ( n2 > 0 ) {
quint32 id = dslLanguageToId( attr.mid( n + 6, n2 - n - 6 ).toStdU32String() );
langcode = LangCoder::intToCode2( id ).toStdString();
Expand All @@ -950,7 +950,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
url.setPath( Utils::Url::ensureLeadingSlash( QString::fromStdU32String( nodeStr ) ) );
if ( !node.tagAttrs.empty() ) {
QString attr = QString::fromStdU32String( node.tagAttrs ).remove( '\"' );
int n = attr.indexOf( '=' );
auto n = attr.indexOf( '=' );
if ( n > 0 ) {
QList< std::pair< QString, QString > > query;
query.append( std::pair< QString, QString >( attr.left( n ), attr.mid( n + 1 ) ) );
Expand Down Expand Up @@ -1295,7 +1295,7 @@ void DslDictionary::getArticleText( uint32_t articleAddress, QString & headword,
static QString stripTags[ stripTagsNumber ] = { "s", "url", "!trs", "video", "preview" };
static QString stripEndTags[ stripTagsNumber ] = { "[/s]", "[/url]", "[/!trs]", "[/video]", "[/preview]" };

int pos = 0;
qsizetype pos = 0;
while ( pos >= 0 ) {
pos = text.indexOf( '[', pos, Qt::CaseInsensitive );
if ( pos >= 0 ) {
Expand All @@ -1305,7 +1305,7 @@ void DslDictionary::getArticleText( uint32_t articleAddress, QString & headword,
continue;
}

int pos2 = text.indexOf( ']', pos + 1, Qt::CaseInsensitive );
auto pos2 = text.indexOf( ']', pos + 1, Qt::CaseInsensitive );
if ( pos2 < 0 ) {
break;
}
Expand Down
5 changes: 3 additions & 2 deletions src/dict/gls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ QString & GlsDictionary::filterResource( QString & article )
QRegularExpression linksReg( R"(<a(\s+[^>]*)href\s*=\s*['"](bword://)?([^'"]+)['"])",
QRegularExpression::CaseInsensitiveOption );

int pos = 0;
qsizetype pos = 0;
QString articleNewText;
QRegularExpressionMatchIterator it = linksReg.globalMatch( article );
while ( it.hasNext() ) {
Expand Down Expand Up @@ -1119,7 +1119,8 @@ void GlsResourceRequest::run()
// Correct some url's

QString id = QString::fromUtf8( dict.getId().c_str() );
int pos = 0;

qsizetype pos = 0;

QRegularExpression links( R"(url\(\s*(['"]?)([^'"]*)(['"]?)\s*\))", QRegularExpression::CaseInsensitiveOption );

Expand Down
6 changes: 3 additions & 3 deletions src/dict/hunspell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ QList< std::u32string > suggest( std::u32string & word, QMutex & hunspellMutex,
QString suggestion = QString::fromStdU32String( decodeFromHunspell( hunspell, x.c_str() ) );

// Strip comments
int n = suggestion.indexOf( '#' );
auto n = suggestion.indexOf( '#' );
if ( n >= 0 ) {
suggestion.chop( suggestion.length() - n );
}
Expand Down Expand Up @@ -544,11 +544,11 @@ void getSuggestionsForExpression( std::u32string const & expression,
}
else {
QList< std::u32string > sugg = suggest( word, hunspellMutex, hunspell );
int suggNum = sugg.size() + 1;
auto suggNum = sugg.size() + 1;
if ( suggNum > 3 ) {
suggNum = 3;
}
int resNum = results.size();
auto resNum = results.size();
std::u32string resultStr;

if ( resNum == 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/dict/mdictparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ QString & MdictParser::substituteStylesheet( QString & article, MdictParser::Sty
QString articleNewText;

QString endStyle;
int pos = 0;
qsizetype pos = 0;

QRegularExpressionMatchIterator it = rx.globalMatch( article );
while ( it.hasNext() ) {
Expand Down
11 changes: 6 additions & 5 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ QByteArray MddResourceRequest::isolate_css()

QString css = QString::fromUtf8( data.data(), data.size() );

int pos = 0;
qsizetype pos = 0;

QString newCSS;
QRegularExpressionMatchIterator it = RX::Mdx::links.globalMatch( css );
Expand Down Expand Up @@ -877,7 +877,7 @@ QString & MdxDictionary::filterResource( QString & article )
void MdxDictionary::replaceLinks( QString & id, QString & article )
{
QString articleNewText;
int linkPos = 0;
qsizetype linkPos = 0;
QRegularExpressionMatchIterator it = RX::Mdx::allLinksRe.globalMatch( article );
while ( it.hasNext() ) {
QRegularExpressionMatch allLinksMatch = it.next();
Expand Down Expand Up @@ -1044,7 +1044,7 @@ void MdxDictionary::replaceStyleInHtml( QString & id, QString & article )
{
//article = article.replace( RX::Mdx::fontFace, "src:url(\"bres://" + id + "/" + "\\1\")" );
QString articleNewText;
int linkPos = 0;
qsizetype linkPos = 0;
QRegularExpressionMatchIterator it = RX::Mdx::styleElement.globalMatch( article );
while ( it.hasNext() ) {
QRegularExpressionMatch allLinksMatch = it.next();
Expand Down Expand Up @@ -1074,7 +1074,8 @@ void MdxDictionary::replaceFontLinks( QString & id, QString & article )
{
//article = article.replace( RX::Mdx::fontFace, "src:url(\"bres://" + id + "/" + "\\1\")" );
QString articleNewText;
int linkPos = 0;
qsizetype linkPos = 0;

QRegularExpressionMatchIterator it = RX::Mdx::fontFace.globalMatch( article );
while ( it.hasNext() ) {
QRegularExpressionMatch allLinksMatch = it.next();
Expand Down Expand Up @@ -1118,7 +1119,7 @@ QString MdxDictionary::getCachedFileName( QString filename )
QString name = filename;
name.replace( '/', '\\' );
QStringList list = name.split( '\\' );
int subFolders = list.size() - 1;
qsizetype subFolders = list.size() - 1;
if ( subFolders > 0 ) {
QString dirName = cacheDirName;
for ( int i = 0; i < subFolders; i++ ) {
Expand Down
Loading

0 comments on commit 264781d

Please sign in to comment.