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
Add a "string-like" class to represent filepaths #2326
Comments
@Minoru I wanna try to solve this issue, but I confess that I don’t quite understand it completely, so in order not to write a bunch of unnecessary code, I’ll write here a wrapper draft, questions and etc.
As I understand, in case of invalid UTF-8 symbol class should:
class FilePathString {
public:
// Constructors
// check is UTF8 valid and signal to user as described above
FilePathString(const std::vector<std::uint8_t>& path);
FilePathString(const std::string& path);
std::string data() const
{
return str;
}
// Other common string methods if necessary
private:
std::string str;
}; Am I on the right way at all, or am I missing something? |
You kind of are, but not quite. Your example seem to hint that the path will get converted to UTF-8 and stored as UTF-8, but that's exactly what we need to avoid. The class should store the path as bytes, with no assumptions about its encoding. There should be a method that returns UTF-8, we're going to use it when writing the path to logs. Also, the class should not have the common string methods. Just treat the path as a vector of bytes, with no knowledge about what it contains. Maybe take a look at Rust's I actually started working on this a while ago. Take a look at The skeleton probably doesn't have all the necessary methods. They should be added as more code is converted and you see that the methods are actually needed. Keep them as similar to I should warn you that this task is a slog :) But if you make even a singe commit, please publish your work so the next person starts a bit closer to the goal. |
So, where is update and what's next? |
Sorry, I dropped the ball on this one! Here goes. In #2561, @bogdasar1985 ported all interfaces and storage to the new This doesn't provide any type-safety yet, because I think the best approach to this would be to go through all .cpp files, and for each put |
This is an offshoot of #1344, and it blocks that issue.
We currently represent paths with
std::string
. What we want is to represent them with some other class which wrapsstd::string
.I think the basic interface for that class should be:
std::vector<std::uint8_t>
orstd::vector<char>
.std::string
is up to debate; if it's provided, it should definitely be markedexplicit
or done through a helper method with a descriptive name\x80
Then this new class should be used where filepaths are used. I'd start with
ConfigContainer
: some of the settings contain filepaths, start with those. Also look through the utils module, as it has some filepath-related utilities likeresolve_tilde
.Finally, Rust FFI should be fixed to pass filepaths as
&[u8]
, not&str
(becausestr
is UTF-8).This issue is up for grabs, but might not be suitable for those who see Newsboat for the first time. Don't hesitate to ask questions though!
The text was updated successfully, but these errors were encountered: