Path: ToUTF() returns std::string
This commit is contained in:
parent
0273cd44b0
commit
292d7c3fdf
@ -37,10 +37,10 @@ ExcludeList::LoadFile(const Path &path_fs)
|
|||||||
FILE *file = fopen(path_fs.c_str(), "r");
|
FILE *file = fopen(path_fs.c_str(), "r");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
char *path_utf8 = path_fs.ToUTF8();
|
const char *msg = g_strerror(errno);
|
||||||
|
const auto path_utf8 = path_fs.ToUTF8();
|
||||||
g_debug("Failed to open %s: %s",
|
g_debug("Failed to open %s: %s",
|
||||||
path_utf8, g_strerror(errno));
|
path_utf8.c_str(), msg);
|
||||||
g_free(path_utf8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -38,6 +38,18 @@
|
|||||||
|
|
||||||
static char *fs_charset;
|
static char *fs_charset;
|
||||||
|
|
||||||
|
std::string Path::ToUTF8() const
|
||||||
|
{
|
||||||
|
if (value == nullptr)
|
||||||
|
return std::string();
|
||||||
|
char *path_utf8 = fs_charset_to_utf8(value);
|
||||||
|
if (path_utf8 == nullptr)
|
||||||
|
return std::string();
|
||||||
|
std::string result = value;
|
||||||
|
g_free(path_utf8);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
fs_charset_to_utf8(const char *path_fs)
|
fs_charset_to_utf8(const char *path_fs)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -250,15 +251,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the path to UTF-8. The caller is responsible for
|
* Convert the path to UTF-8.
|
||||||
* freeing the return value with g_free(). Returns nullptr on
|
* Returns empty string on error or if this instance is "nulled"
|
||||||
* error.
|
* (#IsNull returns true).
|
||||||
*/
|
*/
|
||||||
char *ToUTF8() const {
|
std::string ToUTF8() const;
|
||||||
return value != nullptr
|
|
||||||
? fs_charset_to_utf8(value)
|
|
||||||
: nullptr;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user