Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
6513ff92
Commit
6513ff92
authored
Apr 12, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/Charset: throw exception on error
parent
a0eb6d09
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
26 deletions
+29
-26
AllocatedPath.cxx
src/fs/AllocatedPath.cxx
+12
-2
Charset.cxx
src/fs/Charset.cxx
+6
-21
Charset.hxx
src/fs/Charset.hxx
+4
-2
Path.cxx
src/fs/Path.cxx
+7
-1
No files found.
src/fs/AllocatedPath.cxx
View file @
6513ff92
...
...
@@ -24,6 +24,8 @@
#include "util/Error.hxx"
#include "Compiler.h"
#include <stdexcept>
/* no inlining, please */
AllocatedPath
::~
AllocatedPath
()
{}
...
...
@@ -31,7 +33,11 @@ AllocatedPath
AllocatedPath
::
FromUTF8
(
const
char
*
path_utf8
)
{
#if defined(HAVE_FS_CHARSET) || defined(WIN32)
return
AllocatedPath
(
::
PathFromUTF8
(
path_utf8
));
try
{
return
AllocatedPath
(
::
PathFromUTF8
(
path_utf8
));
}
catch
(
const
std
::
runtime_error
&
)
{
return
nullptr
;
}
#else
return
FromFS
(
path_utf8
);
#endif
...
...
@@ -58,7 +64,11 @@ AllocatedPath::GetDirectoryName() const
std
::
string
AllocatedPath
::
ToUTF8
()
const
{
return
::
PathToUTF8
(
c_str
());
try
{
return
::
PathToUTF8
(
c_str
());
}
catch
(
const
std
::
runtime_error
&
)
{
return
std
::
string
();
}
}
void
...
...
src/fs/Charset.cxx
View file @
6513ff92
...
...
@@ -101,12 +101,8 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
#endif
#ifdef WIN32
try
{
const
auto
buffer
=
WideCharToMultiByte
(
CP_UTF8
,
path_fs
);
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
}
catch
(
const
std
::
runtime_error
&
)
{
return
PathTraitsUTF8
::
string
();
}
const
auto
buffer
=
WideCharToMultiByte
(
CP_UTF8
,
path_fs
);
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
#else
#ifdef HAVE_FS_CHARSET
if
(
fs_converter
==
nullptr
)
...
...
@@ -114,12 +110,8 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
return
FixSeparators
(
path_fs
);
#ifdef HAVE_FS_CHARSET
try
{
const
auto
buffer
=
fs_converter
->
ToUTF8
(
path_fs
);
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
}
catch
(
const
std
::
runtime_error
&
)
{
return
PathTraitsUTF8
::
string
();
}
const
auto
buffer
=
fs_converter
->
ToUTF8
(
path_fs
);
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
#endif
#endif
}
...
...
@@ -135,20 +127,13 @@ PathFromUTF8(PathTraitsUTF8::const_pointer_type path_utf8)
#endif
#ifdef WIN32
try
{
const
auto
buffer
=
MultiByteToWideChar
(
CP_UTF8
,
path_utf8
);
return
PathTraitsFS
::
string
(
buffer
.
c_str
());
}
catch
(
const
std
::
runtime_error
&
)
{
return
PathTraitsFS
::
string
();
}
const
auto
buffer
=
MultiByteToWideChar
(
CP_UTF8
,
path_utf8
);
return
PathTraitsFS
::
string
(
buffer
.
c_str
());
#else
if
(
fs_converter
==
nullptr
)
return
path_utf8
;
const
auto
buffer
=
fs_converter
->
FromUTF8
(
path_utf8
);
if
(
buffer
.
IsNull
())
return
PathTraitsFS
::
string
();
return
PathTraitsFS
::
string
(
buffer
.
c_str
());
#endif
}
...
...
src/fs/Charset.hxx
View file @
6513ff92
...
...
@@ -48,7 +48,8 @@ DeinitFSCharset();
/**
* Convert the path to UTF-8.
* Returns empty string on error.
*
* Throws std::runtime_error on error.
*/
gcc_pure
gcc_nonnull_all
PathTraitsUTF8
::
string
...
...
@@ -56,7 +57,8 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs);
/**
* Convert the path from UTF-8.
* Returns empty string on error.
*
* Throws std::runtime_error on error.
*/
gcc_pure
gcc_nonnull_all
PathTraitsFS
::
string
...
...
src/fs/Path.cxx
View file @
6513ff92
...
...
@@ -21,10 +21,16 @@
#include "Path.hxx"
#include "Charset.hxx"
#include <stdexcept>
std
::
string
Path
::
ToUTF8
()
const
{
return
::
PathToUTF8
(
c_str
());
try
{
return
::
PathToUTF8
(
c_str
());
}
catch
(
const
std
::
runtime_error
&
)
{
return
std
::
string
();
}
}
Path
::
const_pointer_type
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment