Path: add FromUTF8() overload that returns an Error
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "fs/Path.hxx"
|
||||
#include "ConfigGlobal.hxx"
|
||||
#include "system/FatalError.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "gcc.h"
|
||||
|
||||
@@ -89,6 +90,18 @@ Path Path::FromUTF8(const char *path_utf8)
|
||||
return Path(Donate(), p);
|
||||
}
|
||||
|
||||
Path
|
||||
Path::FromUTF8(const char *path_utf8, Error &error)
|
||||
{
|
||||
Path path = FromUTF8(path_utf8);
|
||||
if (path.IsNull())
|
||||
error.Format(path_domain,
|
||||
"Failed to convert to file system charset: %s",
|
||||
path_utf8);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
static bool
|
||||
IsSupportedCharset(const char *charset)
|
||||
|
@@ -44,6 +44,8 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
class Error;
|
||||
|
||||
extern const class Domain path_domain;
|
||||
|
||||
/**
|
||||
@@ -151,6 +153,9 @@ public:
|
||||
gcc_pure
|
||||
static Path FromUTF8(const char *path_utf8);
|
||||
|
||||
gcc_pure
|
||||
static Path FromUTF8(const char *path_utf8, Error &error);
|
||||
|
||||
/**
|
||||
* Convert the path to UTF-8.
|
||||
* Returns empty string on error or if #path_fs is null pointer.
|
||||
|
Reference in New Issue
Block a user