@@ -27,10 +27,9 @@ namespace LyricFA {
2727 MatchLyric::~MatchLyric () = default ;
2828
2929 static QString get_lyrics_from_txt (const QString &lyricPath) {
30- QFile lyricFile (lyricPath);
31- if (lyricFile.open (QIODevice::ReadOnly | QIODevice::Text)) {
30+ if (QFile lyricFile (lyricPath); lyricFile.open (QIODevice::ReadOnly | QIODevice::Text)) {
3231 auto words = QString::fromUtf8 (lyricFile.readAll ());
33- words.remove (QRegularExpression (u8" [^\u4E00 -\u9FFF\u3400 -\u4DBF\uF900 -\uFAFF ]" ));
32+ words.remove (QRegularExpression (u8" [^\u4E00 -\u9FFF\u3400 -\u4DBF\uF900 -\uFAFF a-zA-Z ]" ));
3433 return words;
3534 }
3635 return {};
@@ -43,9 +42,8 @@ namespace LyricFA {
4342 }
4443
4544 const QJsonDocument jsonDoc (jsonObject);
46- const QByteArray jsonData = jsonDoc.toJson ();
4745
48- if (file.write (jsonData) == -1 ) {
46+ if (const QByteArray jsonData = jsonDoc. toJson (); file.write (jsonData) == -1 ) {
4947 return false ;
5048 }
5149
@@ -72,21 +70,20 @@ namespace LyricFA {
7270
7371 std::vector<std::string> textList, pinyinList;
7472 for (const auto &item : g2pRes) {
75- textList.push_back (item.hanzi .c_str ());
76- pinyinList.push_back (item.pinyin .c_str ());
73+ textList.emplace_back (item.hanzi .c_str ());
74+ pinyinList.emplace_back (item.pinyin .c_str ());
7775 }
7876 m_lyricDict[lyricName] = lyricInfo{textList, pinyinList};
7977 }
8078 }
8179
8280 bool MatchLyric::match (const QString &filename, const QString &labPath, const QString &jsonPath, QString &msg,
8381 const bool &asr_rectify) const {
84- const auto lyricName = filename.left (filename.lastIndexOf (' _' ));
8582
86- if (m_lyricDict.contains (lyricName)) {
83+ if (const auto lyricName = filename. left (filename. lastIndexOf ( ' _ ' )); m_lyricDict.contains (lyricName)) {
8784 const auto asr_list = get_lyrics_from_txt (labPath).toUtf8 ().toStdString ();
8885 if (asr_list.empty ()) {
89- msg = " filename : Asr res is empty." ;
86+ msg = QString ( " %1 : Asr result is empty." ). arg (lyricName) ;
9087 return false ;
9188 }
9289 const auto textList = m_lyricDict[lyricName].text ;
@@ -106,7 +103,7 @@ namespace LyricFA {
106103
107104 std::vector<std::string> asrPinyins;
108105 for (const auto &item : asrG2pRes)
109- asrPinyins.push_back (item.pinyin .c_str ());
106+ asrPinyins.emplace_back (item.pinyin .c_str ());
110107
111108 if (!asrPinyins.empty ()) {
112109 auto [match_text, match_pinyin, text_step, pinyin_step] =
@@ -117,14 +114,13 @@ namespace LyricFA {
117114 for (int i = 0 ; i < asrPinyins.size (); i++) {
118115 const auto asrPinyin = asrPinyins[i];
119116 const auto text = match_text[i];
120- const auto matchPinyin = match_pinyin[i];
121117
122- if (asrPinyin != matchPinyin) {
118+ if (const auto matchPinyin = match_pinyin[i]; asrPinyin != matchPinyin) {
123119 const std::vector<std::string> candidates =
124120 m_mandarin->getDefaultPinyin (text, Pinyin::ManTone::NORMAL, true );
125- const auto it = std::find (candidates.begin (), candidates.end (), asrPinyin);
126121
127- if (it != candidates.end ()) {
122+ if (const auto it = std::find (candidates.begin (), candidates.end (), asrPinyin);
123+ it != candidates.end ()) {
128124 asr_rect_list.push_back (asrPinyin);
129125 asr_rect_diff.push_back (" (" + matchPinyin + " ->" + asrPinyin + " , " + static_cast <char >(i) +
130126 " )" );
0 commit comments