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
ed327c59
Commit
ed327c59
authored
Nov 04, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/icu/Converter: Create() returns std::unique_ptr
parent
496f43e2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11 additions
and
16 deletions
+11
-16
IcyMetaDataParser.cxx
src/IcyMetaDataParser.cxx
+1
-1
SidplayDecoderPlugin.cxx
src/decoder/plugins/SidplayDecoderPlugin.cxx
+1
-4
Charset.cxx
src/fs/Charset.cxx
+2
-3
Converter.cxx
src/lib/icu/Converter.cxx
+3
-3
Converter.hxx
src/lib/icu/Converter.hxx
+3
-1
TestIcu.cxx
test/TestIcu.cxx
+1
-4
No files found.
src/IcyMetaDataParser.cxx
View file @
ed327c59
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
void
void
IcyMetaDataParser
::
SetCharset
(
const
char
*
charset
)
IcyMetaDataParser
::
SetCharset
(
const
char
*
charset
)
{
{
icu_converter
.
reset
(
IcuConverter
::
Create
(
charset
)
);
icu_converter
=
IcuConverter
::
Create
(
charset
);
}
}
#endif
#endif
...
...
src/decoder/plugins/SidplayDecoderPlugin.cxx
View file @
ed327c59
...
@@ -456,10 +456,7 @@ Windows1252ToUTF8(const char *s) noexcept
...
@@ -456,10 +456,7 @@ Windows1252ToUTF8(const char *s) noexcept
{
{
#ifdef HAVE_ICU_CONVERTER
#ifdef HAVE_ICU_CONVERTER
try
{
try
{
std
::
unique_ptr
<
IcuConverter
>
return
IcuConverter
::
Create
(
"windows-1252"
)
->
ToUTF8
(
s
);
converter
(
IcuConverter
::
Create
(
"windows-1252"
));
return
converter
->
ToUTF8
(
s
);
}
catch
(...)
{
}
}
catch
(...)
{
}
#endif
#endif
...
...
src/fs/Charset.cxx
View file @
ed327c59
...
@@ -38,7 +38,7 @@
...
@@ -38,7 +38,7 @@
static
std
::
string
fs_charset
;
static
std
::
string
fs_charset
;
static
IcuConverter
*
fs_converter
;
static
std
::
unique_ptr
<
IcuConverter
>
fs_converter
;
void
void
SetFSCharset
(
const
char
*
charset
)
SetFSCharset
(
const
char
*
charset
)
...
@@ -59,8 +59,7 @@ void
...
@@ -59,8 +59,7 @@ void
DeinitFSCharset
()
noexcept
DeinitFSCharset
()
noexcept
{
{
#ifdef HAVE_ICU_CONVERTER
#ifdef HAVE_ICU_CONVERTER
delete
fs_converter
;
fs_converter
.
reset
();
fs_converter
=
nullptr
;
#endif
#endif
}
}
...
...
src/lib/icu/Converter.cxx
View file @
ed327c59
...
@@ -46,7 +46,7 @@ IcuConverter::~IcuConverter()
...
@@ -46,7 +46,7 @@ IcuConverter::~IcuConverter()
#ifdef HAVE_ICU_CONVERTER
#ifdef HAVE_ICU_CONVERTER
IcuConverter
*
std
::
unique_ptr
<
IcuConverter
>
IcuConverter
::
Create
(
const
char
*
charset
)
IcuConverter
::
Create
(
const
char
*
charset
)
{
{
#ifdef HAVE_ICU
#ifdef HAVE_ICU
...
@@ -56,7 +56,7 @@ IcuConverter::Create(const char *charset)
...
@@ -56,7 +56,7 @@ IcuConverter::Create(const char *charset)
throw
std
::
runtime_error
(
FormatString
(
"Failed to initialize charset '%s': %s"
,
throw
std
::
runtime_error
(
FormatString
(
"Failed to initialize charset '%s': %s"
,
charset
,
u_errorName
(
code
)).
c_str
());
charset
,
u_errorName
(
code
)).
c_str
());
return
new
IcuConverter
(
converter
);
return
std
::
unique_ptr
<
IcuConverter
>
(
new
IcuConverter
(
converter
)
);
#elif defined(HAVE_ICONV)
#elif defined(HAVE_ICONV)
iconv_t
to
=
iconv_open
(
"utf-8"
,
charset
);
iconv_t
to
=
iconv_open
(
"utf-8"
,
charset
);
iconv_t
from
=
iconv_open
(
charset
,
"utf-8"
);
iconv_t
from
=
iconv_open
(
charset
,
"utf-8"
);
...
@@ -70,7 +70,7 @@ IcuConverter::Create(const char *charset)
...
@@ -70,7 +70,7 @@ IcuConverter::Create(const char *charset)
charset
);
charset
);
}
}
return
new
IcuConverter
(
to
,
from
);
return
std
::
unique_ptr
<
IcuConverter
>
(
new
IcuConverter
(
to
,
from
)
);
#endif
#endif
}
}
...
...
src/lib/icu/Converter.hxx
View file @
ed327c59
...
@@ -33,6 +33,8 @@
...
@@ -33,6 +33,8 @@
#ifdef HAVE_ICU_CONVERTER
#ifdef HAVE_ICU_CONVERTER
#include <memory>
#ifdef HAVE_ICU
#ifdef HAVE_ICU
struct
UConverter
;
struct
UConverter
;
#endif
#endif
...
@@ -74,7 +76,7 @@ public:
...
@@ -74,7 +76,7 @@ public:
/**
/**
* Throws std::runtime_error on error.
* Throws std::runtime_error on error.
*/
*/
static
IcuConverter
*
Create
(
const
char
*
charset
);
static
std
::
unique_ptr
<
IcuConverter
>
Create
(
const
char
*
charset
);
/**
/**
* Convert the string to UTF-8.
* Convert the string to UTF-8.
...
...
test/TestIcu.cxx
View file @
ed327c59
...
@@ -30,8 +30,7 @@ TEST(IcuConverter, InvalidCharset)
...
@@ -30,8 +30,7 @@ TEST(IcuConverter, InvalidCharset)
TEST
(
IcuConverter
,
Latin1
)
TEST
(
IcuConverter
,
Latin1
)
{
{
IcuConverter
*
const
converter
=
const
auto
converter
=
IcuConverter
::
Create
(
"iso-8859-1"
);
IcuConverter
::
Create
(
"iso-8859-1"
);
ASSERT_NE
(
converter
,
nullptr
);
ASSERT_NE
(
converter
,
nullptr
);
for
(
const
auto
i
:
invalid_utf8
)
{
for
(
const
auto
i
:
invalid_utf8
)
{
...
@@ -45,8 +44,6 @@ TEST(IcuConverter, Latin1)
...
@@ -45,8 +44,6 @@ TEST(IcuConverter, Latin1)
auto
t
=
converter
->
ToUTF8
(
i
.
other
);
auto
t
=
converter
->
ToUTF8
(
i
.
other
);
EXPECT_STREQ
(
t
.
c_str
(),
i
.
utf8
);
EXPECT_STREQ
(
t
.
c_str
(),
i
.
utf8
);
}
}
delete
converter
;
}
}
#endif
#endif
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