Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/util/dpinyin.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "dpinyin.h"

Check warning on line 5 in src/util/dpinyin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dpinyin.h" not found.

#include <QDebug>

Check warning on line 7 in src/util/dpinyin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFile>

Check warning on line 8 in src/util/dpinyin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMap>

Check warning on line 9 in src/util/dpinyin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMap> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSet>

Check warning on line 10 in src/util/dpinyin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSet> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTextStream>

Check warning on line 11 in src/util/dpinyin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTextStream> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMap>
#include <QDebug>

#include <mutex>

Check warning on line 13 in src/util/dpinyin.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <mutex> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DCORE_BEGIN_NAMESPACE

static QHash<uint, QString> dict = {};
static std::once_flag dictInitFlag;
const char kDictFile[] = ":/dpinyin/resources/dpinyin.dict";

static void InitDict() {
if (!dict.isEmpty()) {
return;
}

static void initDictImpl()
{
dict.reserve(25333);

QFile file(kDictFile);
Expand All @@ -46,6 +46,11 @@
}
}

static void InitDict()
{
std::call_once(dictInitFlag, initDictImpl);
}

static void initToneTable(QMap<QChar, QString> &toneTable)
{
if (toneTable.size() > 0)
Expand All @@ -71,7 +76,7 @@

QString newStr = str;
QString toneNum = "";

// First pass: find tone number and remove tone marks
for (QChar c : str) {
if (toneTable.contains(c)) {
Expand All @@ -89,12 +94,12 @@
}
}
}

// For TS_ToneNum, append tone number at the end
if (ts == TS_ToneNum && !toneNum.isEmpty()) {
newStr += toneNum;
}

return newStr;
}

Expand Down
Loading