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

Allow loading stylesheets from paths containing non-ASCII characters #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 13 additions & 10 deletions src/CssParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,24 @@ RESTORE_WARNINGS
#include <ios>
#include <sstream>

#include <QFile>

namespace
{

/*! @throw std::ios_base::failure for IO errors or if the file at @path
* could not be opened. */
std::string loadFileIntoString(const std::string& path)
std::string loadFileIntoString(const QString& path)
{
std::stringstream result;

std::ifstream in(path.c_str(), std::ios::in | std::ios::binary);
in.exceptions(std::ifstream::failbit);

result << in.rdbuf();

return result.str();
QFile file(path);
if (!file.open(QFile::ReadOnly)) {
throw std::ios_base::failure(file.errorString().toStdString());
}
auto data = file.readAll().toStdString();
if (file.error() != QFile::NoError) {
throw std::ios_base::failure(file.errorString().toStdString());
}
return data;
}

} // anon namespace
Expand Down Expand Up @@ -227,7 +230,7 @@ StyleSheet parseString(const QString& data)

StyleSheet parseStyleFile(const QString& path)
{
return parseStdString(loadFileIntoString(path.toStdString()));
return parseStdString(loadFileIntoString(path));
}

} // namespace stylesheets
Expand Down