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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
17 deletions
+20
-17
AllocatedPath.cxx
src/fs/AllocatedPath.cxx
+10
-0
Charset.cxx
src/fs/Charset.cxx
+0
-15
Charset.hxx
src/fs/Charset.hxx
+4
-2
Path.cxx
src/fs/Path.cxx
+6
-0
No files found.
src/fs/AllocatedPath.cxx
View file @
6513ff92
...
@@ -24,6 +24,8 @@
...
@@ -24,6 +24,8 @@
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "Compiler.h"
#include "Compiler.h"
#include <stdexcept>
/* no inlining, please */
/* no inlining, please */
AllocatedPath
::~
AllocatedPath
()
{}
AllocatedPath
::~
AllocatedPath
()
{}
...
@@ -31,7 +33,11 @@ AllocatedPath
...
@@ -31,7 +33,11 @@ AllocatedPath
AllocatedPath
::
FromUTF8
(
const
char
*
path_utf8
)
AllocatedPath
::
FromUTF8
(
const
char
*
path_utf8
)
{
{
#if defined(HAVE_FS_CHARSET) || defined(WIN32)
#if defined(HAVE_FS_CHARSET) || defined(WIN32)
try
{
return
AllocatedPath
(
::
PathFromUTF8
(
path_utf8
));
return
AllocatedPath
(
::
PathFromUTF8
(
path_utf8
));
}
catch
(
const
std
::
runtime_error
&
)
{
return
nullptr
;
}
#else
#else
return
FromFS
(
path_utf8
);
return
FromFS
(
path_utf8
);
#endif
#endif
...
@@ -58,7 +64,11 @@ AllocatedPath::GetDirectoryName() const
...
@@ -58,7 +64,11 @@ AllocatedPath::GetDirectoryName() const
std
::
string
std
::
string
AllocatedPath
::
ToUTF8
()
const
AllocatedPath
::
ToUTF8
()
const
{
{
try
{
return
::
PathToUTF8
(
c_str
());
return
::
PathToUTF8
(
c_str
());
}
catch
(
const
std
::
runtime_error
&
)
{
return
std
::
string
();
}
}
}
void
void
...
...
src/fs/Charset.cxx
View file @
6513ff92
...
@@ -101,12 +101,8 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
...
@@ -101,12 +101,8 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
#endif
#endif
#ifdef WIN32
#ifdef WIN32
try
{
const
auto
buffer
=
WideCharToMultiByte
(
CP_UTF8
,
path_fs
);
const
auto
buffer
=
WideCharToMultiByte
(
CP_UTF8
,
path_fs
);
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
}
catch
(
const
std
::
runtime_error
&
)
{
return
PathTraitsUTF8
::
string
();
}
#else
#else
#ifdef HAVE_FS_CHARSET
#ifdef HAVE_FS_CHARSET
if
(
fs_converter
==
nullptr
)
if
(
fs_converter
==
nullptr
)
...
@@ -114,12 +110,8 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
...
@@ -114,12 +110,8 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
return
FixSeparators
(
path_fs
);
return
FixSeparators
(
path_fs
);
#ifdef HAVE_FS_CHARSET
#ifdef HAVE_FS_CHARSET
try
{
const
auto
buffer
=
fs_converter
->
ToUTF8
(
path_fs
);
const
auto
buffer
=
fs_converter
->
ToUTF8
(
path_fs
);
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
}
catch
(
const
std
::
runtime_error
&
)
{
return
PathTraitsUTF8
::
string
();
}
#endif
#endif
#endif
#endif
}
}
...
@@ -135,20 +127,13 @@ PathFromUTF8(PathTraitsUTF8::const_pointer_type path_utf8)
...
@@ -135,20 +127,13 @@ PathFromUTF8(PathTraitsUTF8::const_pointer_type path_utf8)
#endif
#endif
#ifdef WIN32
#ifdef WIN32
try
{
const
auto
buffer
=
MultiByteToWideChar
(
CP_UTF8
,
path_utf8
);
const
auto
buffer
=
MultiByteToWideChar
(
CP_UTF8
,
path_utf8
);
return
PathTraitsFS
::
string
(
buffer
.
c_str
());
return
PathTraitsFS
::
string
(
buffer
.
c_str
());
}
catch
(
const
std
::
runtime_error
&
)
{
return
PathTraitsFS
::
string
();
}
#else
#else
if
(
fs_converter
==
nullptr
)
if
(
fs_converter
==
nullptr
)
return
path_utf8
;
return
path_utf8
;
const
auto
buffer
=
fs_converter
->
FromUTF8
(
path_utf8
);
const
auto
buffer
=
fs_converter
->
FromUTF8
(
path_utf8
);
if
(
buffer
.
IsNull
())
return
PathTraitsFS
::
string
();
return
PathTraitsFS
::
string
(
buffer
.
c_str
());
return
PathTraitsFS
::
string
(
buffer
.
c_str
());
#endif
#endif
}
}
...
...
src/fs/Charset.hxx
View file @
6513ff92
...
@@ -48,7 +48,8 @@ DeinitFSCharset();
...
@@ -48,7 +48,8 @@ DeinitFSCharset();
/**
/**
* Convert the path to UTF-8.
* Convert the path to UTF-8.
* Returns empty string on error.
*
* Throws std::runtime_error on error.
*/
*/
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
PathTraitsUTF8
::
string
PathTraitsUTF8
::
string
...
@@ -56,7 +57,8 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs);
...
@@ -56,7 +57,8 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs);
/**
/**
* Convert the path from UTF-8.
* Convert the path from UTF-8.
* Returns empty string on error.
*
* Throws std::runtime_error on error.
*/
*/
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
PathTraitsFS
::
string
PathTraitsFS
::
string
...
...
src/fs/Path.cxx
View file @
6513ff92
...
@@ -21,10 +21,16 @@
...
@@ -21,10 +21,16 @@
#include "Path.hxx"
#include "Path.hxx"
#include "Charset.hxx"
#include "Charset.hxx"
#include <stdexcept>
std
::
string
std
::
string
Path
::
ToUTF8
()
const
Path
::
ToUTF8
()
const
{
{
try
{
return
::
PathToUTF8
(
c_str
());
return
::
PathToUTF8
(
c_str
());
}
catch
(
const
std
::
runtime_error
&
)
{
return
std
::
string
();
}
}
}
Path
::
const_pointer_type
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