Skip to content

Commit

Permalink
clean: reduce implicit int -> (q)sizetype conversion warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying committed Feb 7, 2025
1 parent 8e7f707 commit e4192a1
Show file tree
Hide file tree
Showing 29 changed files with 112 additions and 107 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
7 changes: 3 additions & 4 deletions src/dict/bgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void trimWs( string & word )
word.clear();
}
else {
unsigned end = word.size();
auto end = word.size();

// Doesn't consist of ws entirely, so must end with just isspace()
// condition.
Expand Down Expand Up @@ -613,8 +613,7 @@ void BglArticleRequest::fixHebString( string & hebStr ) // Hebrew support - conv

void BglArticleRequest::fixHebArticle( string & hebArticle ) // Hebrew support - remove extra chars at the end
{
unsigned nulls;

std::size_t nulls;
for ( nulls = hebArticle.size(); nulls > 0
&& ( ( hebArticle[ nulls - 1 ] <= 32 && hebArticle[ nulls - 1 ] >= 0 )
|| ( hebArticle[ nulls - 1 ] >= 65 && hebArticle[ nulls - 1 ] <= 90 ) );
Expand Down Expand Up @@ -940,7 +939,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
10 changes: 5 additions & 5 deletions src/dict/btreeidx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void BtreeWordSearchRequest::findMatches()
}
}

int initialFoldedSize = folded.size();
auto initialFoldedSize = folded.size();

int charsLeftToChop = 0;

Expand Down Expand Up @@ -637,7 +637,7 @@ char const * BtreeIndex::findChainOffsetExactOrPrefix( std::u32string const & ta
// string lands.

char const ** window = &chainOffsets.front();
unsigned windowSize = chainOffsets.size();
auto windowSize = chainOffsets.size();

for ( ;; ) {
//qDebug( "window = %u, ws = %u", window - &chainOffsets.front(), windowSize );
Expand Down Expand Up @@ -762,7 +762,7 @@ void BtreeIndex::antialias( std::u32string const & str, vector< WordArticleLink
caseFolded = Folding::trimWhitespaceOrPunct( caseFolded );
}

for ( unsigned x = chain.size(); x--; ) {
for ( auto x = chain.size(); x--; ) {
// If after applying case folding to each word they wouldn't match, we
// drop the entry.
std::u32string entry =
Expand Down Expand Up @@ -896,7 +896,7 @@ static uint32_t buildBtreeNode( IndexedWords::const_iterator & nextIndex,
abort();
}

uint32_t offset = file.tell();
auto offset = file.tell();

file.write< uint32_t >( uncompressedData.size() );
file.write< uint32_t >( compressedSize );
Expand All @@ -908,7 +908,7 @@ static uint32_t buildBtreeNode( IndexedWords::const_iterator & nextIndex,

file.write( (uint32_t)0 );

uint32_t here = file.tell();
auto here = file.tell();

if ( lastLeafLinkOffset ) {
// Update the previous leaf to have the offset of this one.
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
20 changes: 10 additions & 10 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 Expand Up @@ -1840,17 +1840,17 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
idxHeader.hasAbrv = 1;
idxHeader.abrvAddress = chunks.startNewBlock();

uint32_t sz = abrv.size();
uint32_t sz = (uint32_t)abrv.size();

chunks.addToBlock( &sz, sizeof( uint32_t ) );

for ( const auto & i : abrv ) {
// qDebug( "%s:%s", i->first.c_str(), i->second.c_str() );

sz = i.first.size();
sz = (uint32_t)i.first.size();
chunks.addToBlock( &sz, sizeof( uint32_t ) );
chunks.addToBlock( i.first.data(), sz );
sz = i.second.size();
sz = (uint32_t)i.second.size();
chunks.addToBlock( &sz, sizeof( uint32_t ) );
chunks.addToBlock( i.second.data(), sz );
}
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
Loading

0 comments on commit e4192a1

Please sign in to comment.