Skip to content

Commit

Permalink
修复载入别处来源的LRC歌词乱码问题
Browse files Browse the repository at this point in the history
  • Loading branch information
BensonLaur committed Mar 1, 2020
1 parent 8c70c35 commit e62cc8d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Entities/LrcProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/////////////////////////////////////////////////////////////////////////////

#include "LrcProcessor.h"
#include "UnicodeReader.h"
#include <QRegExp>
#include <QFile>

bool LrcProcessor::LoadFromFile(QString lyricFilePath)
Expand All @@ -16,23 +18,21 @@ bool LrcProcessor::LoadFromFile(QString lyricFilePath)
bIsLrcLyric = false;
bIsNeteaseLrcFormat = true;

QFile file(lyricFilePath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QString content;
UnicodeReader unicodeReader;
if(!unicodeReader.ReadFromFile(lyricFilePath,content))
return false;
}

while(!file.atEnd())
{
QByteArray line = file.readLine();
QString strline = QString(line).trimmed();
QRegExp sepRegExp = QRegExp("\n|\r"); //linux\mac\windows 换行符号
QStringList lineList = content.split(sepRegExp);

if(strline.size() != 0)
lines.push_back(strline); //收集非空行
for(auto& line: lineList)
{
line = line.trimmed();
if(!line.isEmpty())
lines.push_back(line.trimmed());
}

file.close();

LoadFromRawLines(lines);

return true;
Expand Down

0 comments on commit e62cc8d

Please sign in to comment.