aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dirbrowserformaction.cpp6
-rw-r--r--src/filebrowserformaction.cpp6
-rw-r--r--src/filesystembrowser.cpp48
3 files changed, 36 insertions, 24 deletions
diff --git a/src/dirbrowserformaction.cpp b/src/dirbrowserformaction.cpp
index 35fdec2e..f9fe34a1 100644
--- a/src/dirbrowserformaction.cpp
+++ b/src/dirbrowserformaction.cpp
@@ -60,7 +60,7 @@ bool DirBrowserFormAction::process_operation(Operation op,
const auto selection = id_at_position[selected_position];
switch (selection.filetype) {
case FileSystemBrowser::FileType::Directory: {
- const int status = ::chdir(selection.name.c_str());
+ const int status = ::chdir(selection.name.to_locale_charset().c_str());
LOG(Level::DEBUG,
"DirBrowserFormAction:OP_OPEN: chdir(%s) = %i",
selection.name,
@@ -82,7 +82,7 @@ bool DirBrowserFormAction::process_operation(Operation op,
if (utils::ends_with(NEWSBOAT_PATH_SEP, fn)) {
fn.append(NEWSBOAT_PATH_SEP);
}
- fn.append(selection.name);
+ fn.append(selection.name.to_utf8());
set_value("filenametext", fn);
f.set_focus("filename");
}
@@ -312,7 +312,7 @@ void DirBrowserFormAction::add_directory(
sizestr,
formatteddirname);
listfmt.add_line(utils::quote_for_stfl(line));
- id_at_position.push_back(FileSystemBrowser::FileSystemEntry{ftype, dirname});
+ id_at_position.push_back(FileSystemBrowser::FileSystemEntry{ftype, Utf8String::from_utf8(dirname)});
}
}
diff --git a/src/filebrowserformaction.cpp b/src/filebrowserformaction.cpp
index 502c4e00..f74fd252 100644
--- a/src/filebrowserformaction.cpp
+++ b/src/filebrowserformaction.cpp
@@ -61,7 +61,7 @@ bool FileBrowserFormAction::process_operation(Operation op,
const auto selection = id_at_position[selected_position];
switch (selection.filetype) {
case FileSystemBrowser::FileType::Directory: {
- const int status = ::chdir(selection.name.c_str());
+ const int status = ::chdir(selection.name.to_locale_charset().c_str());
LOG(Level::DEBUG,
"FileBrowserFormAction:OP_OPEN: chdir(%s) = %i",
selection.name,
@@ -94,7 +94,7 @@ bool FileBrowserFormAction::process_operation(Operation op,
if (utils::ends_with(NEWSBOAT_PATH_SEP, fn)) {
fn.append(NEWSBOAT_PATH_SEP);
}
- fn.append(selection.name);
+ fn.append(selection.name.to_utf8());
set_value("filenametext", fn);
f.set_focus("filename");
}
@@ -336,7 +336,7 @@ void FileBrowserFormAction::add_file(
sizestr,
formattedfilename);
listfmt.add_line(utils::quote_for_stfl(line));
- id_at_position.push_back(FileSystemBrowser::FileSystemEntry{ftype, filename});
+ id_at_position.push_back(FileSystemBrowser::FileSystemEntry{ftype, Utf8String::from_utf8(filename)});
}
}
diff --git a/src/filesystembrowser.cpp b/src/filesystembrowser.cpp
index 0715edaf..4528ddf5 100644
--- a/src/filesystembrowser.cpp
+++ b/src/filesystembrowser.cpp
@@ -87,38 +87,50 @@ nonstd::optional<char> mode_suffix(mode_t mode)
return nonstd::nullopt;
}
-std::string get_user_padded(uid_t uid)
+Utf8String get_user_padded(uid_t uid)
{
const struct passwd* spw = ::getpwuid(uid);
if (spw != nullptr) {
- return strprintf::fmt("%-8s", spw->pw_name);
+ // Manpages give no indication regarding the encoding of the username.
+ // However, according to https://serverfault.com/a/578264 POSIX
+ // suggests to use alphanumerics, period, hyphen, and underscore, and
+ // the hyphen can't be the first character. All of these fit into
+ // ASCII, which is a subset of UTF-8, so we'll treat the username as
+ // UTF-8.
+ return Utf8String::from_utf8(strprintf::fmt("%-8s", spw->pw_name));
}
- return "????????";
+ return Utf8String::from_utf8("????????");
}
-std::string get_group_padded(gid_t gid)
+Utf8String get_group_padded(gid_t gid)
{
const struct group* sgr = ::getgrgid(gid);
if (sgr != nullptr) {
- return strprintf::fmt("%-8s", sgr->gr_name);
+ // See the comment in get_user_padded() and
+ // https://unix.stackexchange.com/questions/11477/what-are-the-allowed-group-names-for-groupadd
+ return Utf8String::from_utf8(strprintf::fmt("%-8s", sgr->gr_name));
}
- return "????????";
+ return Utf8String::from_utf8("????????");
}
-std::string permissions_string(mode_t mode)
+Utf8String permissions_string(mode_t mode)
{
- unsigned int val = mode & 0777;
-
- std::string str;
- const char* bitstrs[] = {
- "---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"
+ static Utf8String bitstrs[] = {
+ Utf8String::from_utf8("---"),
+ Utf8String::from_utf8("--x"),
+ Utf8String::from_utf8("-w-"),
+ Utf8String::from_utf8("-wx"),
+ Utf8String::from_utf8("r--"),
+ Utf8String::from_utf8("r-x"),
+ Utf8String::from_utf8("rw-"),
+ Utf8String::from_utf8("rwx")
};
- for (int i = 0; i < 3; ++i) {
- unsigned char bits = val % 8;
- val /= 8;
- str.insert(0, bitstrs[bits]);
- }
- return str;
+
+ Utf8String result;
+ result.append(bitstrs[(mode & 0700) >> 6]);
+ result.append(bitstrs[(mode & 0070) >> 3]);
+ result.append(bitstrs[(mode & 0007)]);
+ return result;
}
} // namespace FileSystemBrowser