Skip to content

Commit

Permalink
Merge branch 'staged' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Sep 2, 2024
2 parents a64dadd + ea4f45a commit 4b7ae25
Show file tree
Hide file tree
Showing 44 changed files with 195 additions and 222 deletions.
19 changes: 13 additions & 6 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
# https://clang.llvm.org/extra/clang-tidy/
---
Checks: >
-*
-*,
bugprone-*,
cert-*,
clang-analyzer-*,
clang-diagnostic-*,
concurrency-*,
cppcoreguidelines-*,
google-*,
hicpp-*,
misc-*,
modernize-*,
objc-*,
performance-*,
portability-*,
readability-*,
-bugprone-easily-swappable-parameters,
-bugprone-reserved-identifier,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-prefer-member-initializer,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-reinterpret-cast,
-google-default-arguments,
-misc-non-private-member-variables-in-classes,
-google-readability-casting,
-hicpp-deprecated-headers,
-misc-const-correctness,
-misc-non-private-member-variables-in-classes,
-modernize-avoid-c-arrays,
# -modernize-use-auto,
-modernize-deprecated-headers,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-readability-magic-numbers,
-google-readability-braces-around-statements,
-readability-braces-around-statements,
-readability-identifier-length,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-magic-numbers,
CheckOptions:
- key: modernize-loop-convert.MinConfidence
value: reasonable
Expand Down
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ b5349478cfb0dc2dd0de8c8e8aeebdd24cf7ac6b

# reformat every .js .css
534d8c2e96ef00ae03650c2185d7b240ea5a1114

# replace QVector & QPair
3273f39dd73f4dba07fa95be2be74061f2690b2c
44853544f850e1de90b341780168c04d089c37a1
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ object_script.goldendict.Release

version.txt

.gitattributes

*.dmg

.DS_Store
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ endif ()

target_compile_definitions(${GOLDENDICT} PUBLIC
CMAKE_USED_HACK # temporal hack to avoid breaking qmake build
USE_ICONV
MAKE_QTMULTIMEDIA_PLAYER
MAKE_CHINESE_CONVERSION_SUPPORT
)
Expand Down
4 changes: 2 additions & 2 deletions src/article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -998,9 +998,9 @@ void ArticleRequest::individualWordFinished()
compoundSearchNextStep( false );
}

QPair< ArticleRequest::Words, ArticleRequest::Spacings > ArticleRequest::splitIntoWords( QString const & input )
std::pair< ArticleRequest::Words, ArticleRequest::Spacings > ArticleRequest::splitIntoWords( QString const & input )
{
QPair< Words, Spacings > result;
std::pair< Words, Spacings > result;

QChar const * ptr = input.data();

Expand Down
4 changes: 2 additions & 2 deletions src/article_maker.hh
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class ArticleRequest: public Dictionary::DataRequest
typedef QList< QString > Spacings;

/// Splits the given string into words and spacings between them.
QPair< Words, Spacings > splitIntoWords( QString const & );
std::pair< Words, Spacings > splitIntoWords( QString const & );

QPair< Words, Spacings > splittedWords;
std::pair< Words, Spacings > splittedWords;
int currentSplittedWordStart;
int currentSplittedWordEnd;
QString currentSplittedWordCompound;
Expand Down
4 changes: 2 additions & 2 deletions src/article_netmgr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#define __ARTICLE_NETMGR_HH_INCLUDED__

#include <QtNetwork>

#include <QSet>
#include <QMap>
#include <QPair>
#include <QWebEngineUrlSchemeHandler>
#include <QWebEngineUrlRequestJob>
#include <QNetworkAccessManager>

#include <utility>

#include "dict/dictionary.hh"
#include "article_maker.hh"

Expand Down
6 changes: 3 additions & 3 deletions src/btreeidx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ void BtreeIndex::getAllHeadwords( QSet< QString > & headwords )
findArticleLinks( nullptr, nullptr, &headwords );
}

void BtreeIndex::findAllArticleLinks( QVector< WordArticleLink > & articleLinks )
void BtreeIndex::findAllArticleLinks( QList< WordArticleLink > & articleLinks )
{
if ( !idxFile )
throw exIndexWasNotOpened();
Expand All @@ -1038,7 +1038,7 @@ void BtreeIndex::findAllArticleLinks( QVector< WordArticleLink > & articleLinks
findArticleLinks( &articleLinks, &offsets, nullptr );
}

void BtreeIndex::findArticleLinks( QVector< WordArticleLink > * articleLinks,
void BtreeIndex::findArticleLinks( QList< WordArticleLink > * articleLinks,
QSet< uint32_t > * offsets,
QSet< QString > * headwords,
QAtomicInt * isCancelled )
Expand Down Expand Up @@ -1217,7 +1217,7 @@ QList< uint32_t > BtreeIndex::findNodes()
}

void BtreeIndex::getHeadwordsFromOffsets( QList< uint32_t > & offsets,
QVector< QString > & headwords,
QList< QString > & headwords,
QAtomicInt * isCancelled )
{
uint32_t currentNodeOffset = rootOffset;
Expand Down
8 changes: 4 additions & 4 deletions src/btreeidx.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <QFuture>
#include <QList>
#include <QSet>
#include <QVector>
#include <QList>


/// A base for the dictionary which creates a btree index to look up
Expand Down Expand Up @@ -89,13 +89,13 @@ public:
vector< WordArticleLink > findArticles( wstring const &, bool ignoreDiacritics = false, uint32_t maxMatchCount = -1 );

/// Find all unique article links in the index
void findAllArticleLinks( QVector< WordArticleLink > & articleLinks );
void findAllArticleLinks( QList< WordArticleLink > & articleLinks );

/// Retrieve all unique headwords from index
void getAllHeadwords( QSet< QString > & headwords );

/// Find all article links and/or headwords in the index
void findArticleLinks( QVector< WordArticleLink > * articleLinks,
void findArticleLinks( QList< WordArticleLink > * articleLinks,
QSet< uint32_t > * offsets,
QSet< QString > * headwords,
QAtomicInt * isCancelled = 0 );
Expand All @@ -106,7 +106,7 @@ public:

/// Retrieve headwords for presented article addresses
void
getHeadwordsFromOffsets( QList< uint32_t > & offsets, QVector< QString > & headwords, QAtomicInt * isCancelled = 0 );
getHeadwordsFromOffsets( QList< uint32_t > & offsets, QList< QString > & headwords, QAtomicInt * isCancelled = 0 );

protected:

Expand Down
37 changes: 15 additions & 22 deletions src/common/iconv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,20 @@ char const * const Iconv::GdWchar = "UTF-32LE";
char const * const Iconv::Utf16Le = "UTF-16LE";
char const * const Iconv::Utf8 = "UTF-8";

using gd::wchar;

Iconv::Iconv( char const * from )
#ifdef USE_ICONV
// the to encoding must be UTF8
:
Iconv::Iconv( char const * from ):
state( iconv_open( Utf8, from ) )
#endif
{
#ifdef USE_ICONV
if ( state == (iconv_t)-1 )
throw exCantInit( strerror( errno ) );
#else
codec = QTextCodec::codecForName( from );
#endif
}

Iconv::~Iconv()
{
#ifdef USE_ICONV
iconv_close( state );
#endif
}

QString Iconv::convert( void const *& inBuf, size_t & inBytesLeft )
{
#ifdef USE_ICONV
size_t dsz = inBytesLeft;
//avoid most realloc
std::vector< char > outBuf( dsz + 32 );
Expand Down Expand Up @@ -90,12 +77,6 @@ QString Iconv::convert( void const *& inBuf, size_t & inBytesLeft )
size_t datasize = outBuf.size() - outBufLeft;
// QByteArray ba( &outBuf.front(), datasize );
return QString::fromUtf8( &outBuf.front(), datasize );
#else
if ( codec )
return codec->toUnicode( static_cast< const char * >( inBuf ), inBytesLeft );
QByteArray ba( static_cast< const char * >( inBuf ), inBytesLeft );
return QString( ba );
#endif
}

gd::wstring Iconv::toWstring( char const * fromEncoding, void const * fromData, size_t dataSize )
Expand All @@ -104,8 +85,9 @@ gd::wstring Iconv::toWstring( char const * fromEncoding, void const * fromData,
/// Special-case the dataSize == 0 to avoid any kind of iconv-specific
/// behaviour in that regard.

if ( !dataSize )
if ( dataSize == 0 ) {
return {};
}

Iconv ic( fromEncoding );

Expand All @@ -118,11 +100,22 @@ std::string Iconv::toUtf8( char const * fromEncoding, void const * fromData, siz
{
// Similar to toWstring

if ( !dataSize )
if ( dataSize == 0 ) {
return {};
}

Iconv ic( fromEncoding );

const QString outStr = ic.convert( fromData, dataSize );
return outStr.toStdString();
}

QString Iconv::toQString( char const * fromEncoding, void const * fromData, size_t dataSize )
{
if ( dataSize == 0 ) {
return {};
}

Iconv ic( fromEncoding );
return ic.convert( fromData, dataSize );
}
24 changes: 9 additions & 15 deletions src/common/iconv.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@
#ifndef __ICONV_HH_INCLUDED__
#define __ICONV_HH_INCLUDED__

#include <QTextCodec>
#include <QString>

#include "wstring.hh"
#include "ex.hh"

#ifdef USE_ICONV
#include <iconv.h>
#endif
#include <iconv.h>


/// A wrapper for the iconv() character set conversion functions
/// "Internationalization conversion" for char encoding conversion, currently implemented with iconv()
/// Only supports converting from a known "from" to UTF8
class Iconv
{
#ifdef USE_ICONV
iconv_t state;
#else
QTextCodec * codec;

#endif

public:

Expand All @@ -34,7 +29,7 @@ public:
static char const * const Utf16Le;
static char const * const Utf8;

Iconv( char const * from );
explicit Iconv( char const * from );

~Iconv();

Expand All @@ -47,11 +42,10 @@ public:
// string.
static std::string toUtf8( char const * fromEncoding, void const * fromData, size_t dataSize );

private:
static QString toQString( char const * fromEncoding, void const * fromData, size_t dataSize );

// Copying/assigning not supported
Iconv( Iconv const & );
Iconv & operator=( Iconv const & );
// Copying/assigning isn't supported
Q_DISABLE_COPY_MOVE( Iconv );
};

#endif
2 changes: 1 addition & 1 deletion src/common/utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ inline void removeQueryItem( QUrl & url, QString const & key )
url.setQuery( urlQuery );
}

inline void setQueryItems( QUrl & url, QList< QPair< QString, QString > > const & query )
inline void setQueryItems( QUrl & url, QList< std::pair< QString, QString > > const & query )
{
QUrlQuery urlQuery( url );
urlQuery.setQueryItems( query );
Expand Down
4 changes: 2 additions & 2 deletions src/common/wstring_qt.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "wstring_qt.hh"
#include <QVector>
#include <QList>

namespace gd {
wstring toWString( QString const & in )
Expand All @@ -19,7 +19,7 @@ wstring removeTrailingZero( wstring const & v )

wstring removeTrailingZero( QString const & in )
{
QVector< unsigned int > v = in.toUcs4();
QList< unsigned int > v = in.toUcs4();

int n = v.size();
while ( n > 0 && v[ n - 1 ] == 0 )
Expand Down
Loading

0 comments on commit 4b7ae25

Please sign in to comment.