Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of the not working binary file check #3916

Merged
merged 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
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: 0 additions & 27 deletions src/library/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,6 @@ long Parser::countParsed() {
return (long)m_sLocations.count();
}

bool Parser::isBinary(const QString& filename) {
char firstByte;
QFile file(filename);
if (file.open(QIODevice::ReadOnly) && file.getChar(&firstByte)) {
// If starting byte is not an ASCII character then the file
// probably contains binary data.
if (firstByte >= 32 && firstByte <= 126) {
// Valid ASCII character
return false;
}
// Check for UTF-8 BOM
if (firstByte == '\xEF') {
char nextChar;
if (file.getChar(&nextChar) &&
nextChar == '\xBB' &&
file.getChar(&nextChar) &&
nextChar == '\xBF') {
// UTF-8 text file
return false;
}
return true;
}
}
qDebug() << "Parser: Error reading from" << filename;
return true; //should this raise an exception?
}

// The following public domain code is taken from
// http://stackoverflow.com/questions/1031645/how-to-detect-utf-8-in-plain-c
// Thank you Christoph!
Expand Down
2 changes: 0 additions & 2 deletions src/library/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class Parser : public QObject {
long countParsed();
// Clears m_psLocations
void clearLocations();
// Checks if the file does contain binary content
bool isBinary(const QString&);
// check for Utf8 encoding
static bool isUtf8(const char* string);
// Resolve an absolute or relative file path
Expand Down
2 changes: 1 addition & 1 deletion src/library/parsercsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ QList<QString> ParserCsv::parse(const QString& sFilename) {

clearLocations();
//qDebug() << "ParserCsv: Starting to parse.";
if (file.open(QIODevice::ReadOnly) && !isBinary(sFilename)) {
if (file.open(QIODevice::ReadOnly)) {
QByteArray ba = file.readAll();

QList<QList<QString> > tokens = tokenize(ba, ',');
Expand Down
2 changes: 1 addition & 1 deletion src/library/parserm3u.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ QList<QString> ParserM3u::parse(const QString& sFilename) {
clearLocations();

QFile file(sFilename);
if (isBinary(sFilename) || !file.open(QIODevice::ReadOnly)) {
if (!file.open(QIODevice::ReadOnly)) {
qWarning()
<< "Failed to open playlist file"
<< sFilename;
Expand Down
3 changes: 1 addition & 2 deletions src/library/parserpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ QList<QString> ParserPls::parse(const QString& sFilename) {

clearLocations();

if (file.open(QIODevice::ReadOnly) && !isBinary(sFilename)) {

if (file.open(QIODevice::ReadOnly)) {
/* Unfortunately, QT 4.7 does not handle <CR> (=\r or asci value 13) line breaks.
* This is important on OS X where iTunes, e.g., exports M3U playlists using <CR>
* rather that <LF>
Expand Down