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
b9f535cd
Commit
b9f535cd
authored
Apr 13, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/icu/Win32: throw exception on error
parent
e2281441
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
40 deletions
+72
-40
PlaylistSave.cxx
src/PlaylistSave.cxx
+19
-11
ExcludeList.cxx
src/db/update/ExcludeList.cxx
+9
-3
Charset.cxx
src/fs/Charset.cxx
+11
-8
Collate.cxx
src/lib/icu/Collate.cxx
+22
-14
Win32.cxx
src/lib/icu/Win32.cxx
+5
-4
Win32.hxx
src/lib/icu/Win32.hxx
+6
-0
No files found.
src/PlaylistSave.cxx
View file @
b9f535cd
...
@@ -33,6 +33,8 @@
...
@@ -33,6 +33,8 @@
#include "fs/io/BufferedOutputStream.hxx"
#include "fs/io/BufferedOutputStream.hxx"
#include "util/UriUtil.hxx"
#include "util/UriUtil.hxx"
#include <stdexcept>
void
void
playlist_print_song
(
BufferedOutputStream
&
os
,
const
DetachedSong
&
song
)
playlist_print_song
(
BufferedOutputStream
&
os
,
const
DetachedSong
&
song
)
{
{
...
@@ -40,25 +42,31 @@ playlist_print_song(BufferedOutputStream &os, const DetachedSong &song)
...
@@ -40,25 +42,31 @@ playlist_print_song(BufferedOutputStream &os, const DetachedSong &song)
?
song
.
GetRealURI
()
?
song
.
GetRealURI
()
:
song
.
GetURI
();
:
song
.
GetURI
();
const
auto
uri_fs
=
AllocatedPath
::
FromUTF8
(
uri_utf8
);
try
{
if
(
!
uri_fs
.
IsNull
())
const
auto
uri_fs
=
AllocatedPath
::
FromUTF8
(
uri_utf8
);
os
.
Format
(
"%s
\n
"
,
NarrowPath
(
uri_fs
).
c_str
());
if
(
!
uri_fs
.
IsNull
())
os
.
Format
(
"%s
\n
"
,
NarrowPath
(
uri_fs
).
c_str
());
}
catch
(
const
std
::
runtime_error
&
)
{
}
}
}
void
void
playlist_print_uri
(
BufferedOutputStream
&
os
,
const
char
*
uri
)
playlist_print_uri
(
BufferedOutputStream
&
os
,
const
char
*
uri
)
{
{
auto
path
=
try
{
auto
path
=
#ifdef ENABLE_DATABASE
#ifdef ENABLE_DATABASE
playlist_saveAbsolutePaths
&&
!
uri_has_scheme
(
uri
)
&&
playlist_saveAbsolutePaths
&&
!
uri_has_scheme
(
uri
)
&&
!
PathTraitsUTF8
::
IsAbsolute
(
uri
)
!
PathTraitsUTF8
::
IsAbsolute
(
uri
)
?
map_uri_fs
(
uri
)
?
map_uri_fs
(
uri
)
:
:
#endif
#endif
AllocatedPath
::
FromUTF8
(
uri
);
AllocatedPath
::
FromUTF8
(
uri
);
if
(
!
path
.
IsNull
())
if
(
!
path
.
IsNull
())
os
.
Format
(
"%s
\n
"
,
NarrowPath
(
path
).
c_str
());
os
.
Format
(
"%s
\n
"
,
NarrowPath
(
path
).
c_str
());
}
catch
(
const
std
::
runtime_error
&
)
{
}
}
}
void
void
...
...
src/db/update/ExcludeList.cxx
View file @
b9f535cd
...
@@ -30,6 +30,8 @@
...
@@ -30,6 +30,8 @@
#include "system/Error.hxx"
#include "system/Error.hxx"
#include "Log.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
...
@@ -78,9 +80,13 @@ ExcludeList::Check(Path name_fs) const
...
@@ -78,9 +80,13 @@ ExcludeList::Check(Path name_fs) const
}
}
}
}
for
(
const
auto
&
i
:
patterns
)
for
(
const
auto
&
i
:
patterns
)
{
if
(
i
.
Check
(
NarrowPath
(
name_fs
).
c_str
()))
try
{
return
true
;
if
(
i
.
Check
(
NarrowPath
(
name_fs
).
c_str
()))
return
true
;
}
catch
(
const
std
::
runtime_error
&
)
{
}
}
#else
#else
/* not implemented */
/* not implemented */
(
void
)
name_fs
;
(
void
)
name_fs
;
...
...
src/fs/Charset.cxx
View file @
b9f535cd
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#endif
#endif
#include <algorithm>
#include <algorithm>
#include <stdexcept>
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
...
@@ -100,11 +101,12 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
...
@@ -100,11 +101,12 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
#endif
#endif
#ifdef WIN32
#ifdef WIN32
const
auto
buffer
=
WideCharToMultiByte
(
CP_UTF8
,
path_fs
);
try
{
if
(
buffer
.
IsNull
())
const
auto
buffer
=
WideCharToMultiByte
(
CP_UTF8
,
path_fs
);
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
}
catch
(
const
std
::
runtime_error
&
)
{
return
PathTraitsUTF8
::
string
();
return
PathTraitsUTF8
::
string
();
}
return
FixSeparators
(
PathTraitsUTF8
::
string
(
buffer
.
c_str
()));
#else
#else
#ifdef HAVE_FS_CHARSET
#ifdef HAVE_FS_CHARSET
if
(
fs_converter
==
nullptr
)
if
(
fs_converter
==
nullptr
)
...
@@ -132,11 +134,12 @@ PathFromUTF8(PathTraitsUTF8::const_pointer_type path_utf8)
...
@@ -132,11 +134,12 @@ PathFromUTF8(PathTraitsUTF8::const_pointer_type path_utf8)
#endif
#endif
#ifdef WIN32
#ifdef WIN32
const
auto
buffer
=
MultiByteToWideChar
(
CP_UTF8
,
path_utf8
);
try
{
if
(
buffer
.
IsNull
())
const
auto
buffer
=
MultiByteToWideChar
(
CP_UTF8
,
path_utf8
);
return
PathTraitsFS
::
string
(
buffer
.
c_str
());
}
catch
(
const
std
::
runtime_error
&
)
{
return
PathTraitsFS
::
string
();
return
PathTraitsFS
::
string
();
}
return
PathTraitsFS
::
string
(
buffer
.
c_str
());
#else
#else
if
(
fs_converter
==
nullptr
)
if
(
fs_converter
==
nullptr
)
return
path_utf8
;
return
path_utf8
;
...
...
src/lib/icu/Collate.cxx
View file @
b9f535cd
...
@@ -42,6 +42,7 @@
...
@@ -42,6 +42,7 @@
#endif
#endif
#include <memory>
#include <memory>
#include <stdexcept>
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
...
@@ -108,12 +109,24 @@ IcuCollate(const char *a, const char *b)
...
@@ -108,12 +109,24 @@ IcuCollate(const char *a, const char *b)
#endif
#endif
#elif defined(WIN32)
#elif defined(WIN32)
const
auto
wa
=
MultiByteToWideChar
(
CP_UTF8
,
a
);
AllocatedString
<
wchar_t
>
wa
=
nullptr
,
wb
=
nullptr
;
const
auto
wb
=
MultiByteToWideChar
(
CP_UTF8
,
b
);
if
(
wa
.
IsNull
())
try
{
return
wb
.
IsNull
()
?
0
:
-
1
;
wa
=
MultiByteToWideChar
(
CP_UTF8
,
a
);
else
if
(
wb
.
IsNull
())
}
catch
(
const
std
::
runtime_error
&
)
{
try
{
wb
=
MultiByteToWideChar
(
CP_UTF8
,
b
);
return
-
1
;
}
catch
(
const
std
::
runtime_error
&
)
{
return
0
;
}
}
try
{
wb
=
MultiByteToWideChar
(
CP_UTF8
,
b
);
}
catch
(
const
std
::
runtime_error
&
)
{
return
1
;
return
1
;
}
auto
result
=
CompareStringEx
(
LOCALE_NAME_INVARIANT
,
auto
result
=
CompareStringEx
(
LOCALE_NAME_INVARIANT
,
LINGUISTIC_IGNORECASE
,
LINGUISTIC_IGNORECASE
,
...
@@ -134,7 +147,7 @@ IcuCollate(const char *a, const char *b)
...
@@ -134,7 +147,7 @@ IcuCollate(const char *a, const char *b)
AllocatedString
<>
AllocatedString
<>
IcuCaseFold
(
const
char
*
src
)
IcuCaseFold
(
const
char
*
src
)
{
try
{
#ifdef HAVE_ICU
#ifdef HAVE_ICU
assert
(
collator
!=
nullptr
);
assert
(
collator
!=
nullptr
);
#if !CLANG_CHECK_VERSION(3,6)
#if !CLANG_CHECK_VERSION(3,6)
...
@@ -161,8 +174,6 @@ IcuCaseFold(const char *src)
...
@@ -161,8 +174,6 @@ IcuCaseFold(const char *src)
#elif defined(WIN32)
#elif defined(WIN32)
const
auto
u
=
MultiByteToWideChar
(
CP_UTF8
,
src
);
const
auto
u
=
MultiByteToWideChar
(
CP_UTF8
,
src
);
if
(
u
.
IsNull
())
return
AllocatedString
<>::
Duplicate
(
src
);
const
int
size
=
LCMapStringEx
(
LOCALE_NAME_INVARIANT
,
const
int
size
=
LCMapStringEx
(
LOCALE_NAME_INVARIANT
,
LCMAP_SORTKEY
|
LINGUISTIC_IGNORECASE
,
LCMAP_SORTKEY
|
LINGUISTIC_IGNORECASE
,
...
@@ -178,11 +189,7 @@ IcuCaseFold(const char *src)
...
@@ -178,11 +189,7 @@ IcuCaseFold(const char *src)
nullptr
,
nullptr
,
0
)
<=
0
)
nullptr
,
nullptr
,
0
)
<=
0
)
return
AllocatedString
<>::
Duplicate
(
src
);
return
AllocatedString
<>::
Duplicate
(
src
);
auto
result
=
WideCharToMultiByte
(
CP_UTF8
,
buffer
.
get
());
return
WideCharToMultiByte
(
CP_UTF8
,
buffer
.
get
());
if
(
result
.
IsNull
())
return
AllocatedString
<>::
Duplicate
(
src
);
return
result
;
#else
#else
size_t
size
=
strlen
(
src
)
+
1
;
size_t
size
=
strlen
(
src
)
+
1
;
...
@@ -201,5 +208,6 @@ IcuCaseFold(const char *src)
...
@@ -201,5 +208,6 @@ IcuCaseFold(const char *src)
return
AllocatedString
<>::
Donate
(
buffer
.
release
());
return
AllocatedString
<>::
Donate
(
buffer
.
release
());
#endif
#endif
}
catch
(
const
std
::
runtime_error
&
)
{
return
AllocatedString
<>::
Duplicate
(
src
);
}
}
src/lib/icu/Win32.cxx
View file @
b9f535cd
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "config.h"
#include "Win32.hxx"
#include "Win32.hxx"
#include "system/Error.hxx"
#include "util/AllocatedString.hxx"
#include "util/AllocatedString.hxx"
#include <memory>
#include <memory>
...
@@ -31,14 +32,14 @@ WideCharToMultiByte(unsigned code_page, const wchar_t *src)
...
@@ -31,14 +32,14 @@ WideCharToMultiByte(unsigned code_page, const wchar_t *src)
int
length
=
WideCharToMultiByte
(
code_page
,
0
,
src
,
-
1
,
nullptr
,
0
,
int
length
=
WideCharToMultiByte
(
code_page
,
0
,
src
,
-
1
,
nullptr
,
0
,
nullptr
,
nullptr
);
nullptr
,
nullptr
);
if
(
length
<=
0
)
if
(
length
<=
0
)
return
nullptr
;
throw
MakeLastError
(
"Failed to convert from Unicode"
)
;
std
::
unique_ptr
<
char
[]
>
buffer
(
new
char
[
length
]);
std
::
unique_ptr
<
char
[]
>
buffer
(
new
char
[
length
]);
length
=
WideCharToMultiByte
(
code_page
,
0
,
src
,
-
1
,
length
=
WideCharToMultiByte
(
code_page
,
0
,
src
,
-
1
,
buffer
.
get
(),
length
,
buffer
.
get
(),
length
,
nullptr
,
nullptr
);
nullptr
,
nullptr
);
if
(
length
<=
0
)
if
(
length
<=
0
)
return
nullptr
;
throw
MakeLastError
(
"Failed to convert from Unicode"
)
;
return
AllocatedString
<
char
>::
Donate
(
buffer
.
release
());
return
AllocatedString
<
char
>::
Donate
(
buffer
.
release
());
}
}
...
@@ -48,13 +49,13 @@ MultiByteToWideChar(unsigned code_page, const char *src)
...
@@ -48,13 +49,13 @@ MultiByteToWideChar(unsigned code_page, const char *src)
{
{
int
length
=
MultiByteToWideChar
(
code_page
,
0
,
src
,
-
1
,
nullptr
,
0
);
int
length
=
MultiByteToWideChar
(
code_page
,
0
,
src
,
-
1
,
nullptr
,
0
);
if
(
length
<=
0
)
if
(
length
<=
0
)
return
nullptr
;
throw
MakeLastError
(
"Failed to convert to Unicode"
)
;
std
::
unique_ptr
<
wchar_t
[]
>
buffer
(
new
wchar_t
[
length
]);
std
::
unique_ptr
<
wchar_t
[]
>
buffer
(
new
wchar_t
[
length
]);
length
=
MultiByteToWideChar
(
code_page
,
0
,
src
,
-
1
,
length
=
MultiByteToWideChar
(
code_page
,
0
,
src
,
-
1
,
buffer
.
get
(),
length
);
buffer
.
get
(),
length
);
if
(
length
<=
0
)
if
(
length
<=
0
)
return
nullptr
;
throw
MakeLastError
(
"Failed to convert to Unicode"
)
;
return
AllocatedString
<
wchar_t
>::
Donate
(
buffer
.
release
());
return
AllocatedString
<
wchar_t
>::
Donate
(
buffer
.
release
());
}
}
src/lib/icu/Win32.hxx
View file @
b9f535cd
...
@@ -27,10 +27,16 @@
...
@@ -27,10 +27,16 @@
template
<
typename
T
>
class
AllocatedString
;
template
<
typename
T
>
class
AllocatedString
;
/**
* Throws std::system_error on error.
*/
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
AllocatedString
<
char
>
AllocatedString
<
char
>
WideCharToMultiByte
(
unsigned
code_page
,
const
wchar_t
*
src
);
WideCharToMultiByte
(
unsigned
code_page
,
const
wchar_t
*
src
);
/**
* Throws std::system_error on error.
*/
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
AllocatedString
<
wchar_t
>
AllocatedString
<
wchar_t
>
MultiByteToWideChar
(
unsigned
code_page
,
const
char
*
src
);
MultiByteToWideChar
(
unsigned
code_page
,
const
char
*
src
);
...
...
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