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
0756607e
Commit
0756607e
authored
Jun 26, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/icu/Converter: add iconv() implementation
parent
a03be5a8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
3 deletions
+60
-3
configure.ac
configure.ac
+4
-0
CommandLine.cxx
src/CommandLine.cxx
+3
-0
Charset.hxx
src/fs/Charset.hxx
+1
-1
Converter.cxx
src/lib/icu/Converter.cxx
+39
-2
Converter.hxx
src/lib/icu/Converter.hxx
+13
-0
No files found.
configure.ac
View file @
0756607e
...
@@ -472,6 +472,10 @@ fi
...
@@ -472,6 +472,10 @@ fi
MPD_DEFINE_CONDITIONAL(enable_icu, HAVE_ICU, [libicu])
MPD_DEFINE_CONDITIONAL(enable_icu, HAVE_ICU, [libicu])
if test x$enable_icu != xyes; then
AC_CHECK_FUNCS(iconv)
fi
AC_ARG_ENABLE(glib,
AC_ARG_ENABLE(glib,
AS_HELP_STRING([--enable-glib],
AS_HELP_STRING([--enable-glib],
[enable GLib (default: auto)]),,
[enable GLib (default: auto)]),,
...
...
src/CommandLine.cxx
View file @
0756607e
...
@@ -215,6 +215,9 @@ static void version(void)
...
@@ -215,6 +215,9 @@ static void version(void)
#ifdef USE_EPOLL
#ifdef USE_EPOLL
" epoll"
" epoll"
#endif
#endif
#ifdef HAVE_ICONV
" iconv"
#endif
#ifdef HAVE_ICU
#ifdef HAVE_ICU
" icu"
" icu"
#endif
#endif
...
...
src/fs/Charset.hxx
View file @
0756607e
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
#include "Compiler.h"
#include "Compiler.h"
#include "Traits.hxx"
#include "Traits.hxx"
#if (defined(HAVE_ICU) || defined(HAVE_GLIB)) && !defined(WIN32)
#if (defined(HAVE_ICU) || defined(HAVE_
ICONV) || defined(HAVE_
GLIB)) && !defined(WIN32)
#define HAVE_FS_CHARSET
#define HAVE_FS_CHARSET
#endif
#endif
...
...
src/lib/icu/Converter.cxx
View file @
0756607e
...
@@ -31,6 +31,9 @@
...
@@ -31,6 +31,9 @@
#ifdef HAVE_ICU
#ifdef HAVE_ICU
#include "Util.hxx"
#include "Util.hxx"
#include <unicode/ucnv.h>
#include <unicode/ucnv.h>
#elif defined(HAVE_ICONV)
#include "util/Domain.hxx"
static
constexpr
Domain
iconv_domain
(
"iconv"
);
#elif defined(HAVE_GLIB)
#elif defined(HAVE_GLIB)
#include "util/Domain.hxx"
#include "util/Domain.hxx"
static
constexpr
Domain
g_iconv_domain
(
"g_iconv"
);
static
constexpr
Domain
g_iconv_domain
(
"g_iconv"
);
...
@@ -61,6 +64,20 @@ IcuConverter::Create(const char *charset, Error &error)
...
@@ -61,6 +64,20 @@ IcuConverter::Create(const char *charset, Error &error)
}
}
return
new
IcuConverter
(
converter
);
return
new
IcuConverter
(
converter
);
#elif defined(HAVE_ICONV)
iconv_t
to
=
iconv_open
(
"utf-8"
,
charset
);
iconv_t
from
=
iconv_open
(
charset
,
"utf-8"
);
if
(
to
==
(
iconv_t
)
-
1
||
from
==
(
iconv_t
)
-
1
)
{
error
.
FormatErrno
(
"Failed to initialize charset '%s'"
,
charset
);
if
(
to
!=
(
iconv_t
)
-
1
)
iconv_close
(
to
);
if
(
from
!=
(
iconv_t
)
-
1
)
iconv_close
(
from
);
return
nullptr
;
}
return
new
IcuConverter
(
to
,
from
);
#elif defined(HAVE_GLIB)
#elif defined(HAVE_GLIB)
GIConv
to
=
g_iconv_open
(
"utf-8"
,
charset
);
GIConv
to
=
g_iconv_open
(
"utf-8"
,
charset
);
GIConv
from
=
g_iconv_open
(
charset
,
"utf-8"
);
GIConv
from
=
g_iconv_open
(
charset
,
"utf-8"
);
...
@@ -79,6 +96,26 @@ IcuConverter::Create(const char *charset, Error &error)
...
@@ -79,6 +96,26 @@ IcuConverter::Create(const char *charset, Error &error)
}
}
#ifdef HAVE_ICU
#ifdef HAVE_ICU
#elif defined(HAVE_ICONV)
static
AllocatedString
<
char
>
DoConvert
(
iconv_t
conv
,
const
char
*
src
)
{
// TODO: dynamic buffer?
char
buffer
[
4096
];
char
*
in
=
const_cast
<
char
*>
(
src
);
char
*
out
=
buffer
;
size_t
in_left
=
strlen
(
src
);
size_t
out_left
=
sizeof
(
buffer
);
size_t
n
=
iconv
(
conv
,
&
in
,
&
in_left
,
&
out
,
&
out_left
);
if
(
n
==
static_cast
<
size_t
>
(
-
1
)
||
in_left
>
0
)
return
nullptr
;
return
AllocatedString
<>::
Duplicate
(
buffer
,
sizeof
(
buffer
)
-
out_left
);
}
#elif defined(HAVE_GLIB)
#elif defined(HAVE_GLIB)
static
AllocatedString
<
char
>
static
AllocatedString
<
char
>
...
@@ -123,7 +160,7 @@ IcuConverter::ToUTF8(const char *s) const
...
@@ -123,7 +160,7 @@ IcuConverter::ToUTF8(const char *s) const
const
size_t
target_length
=
target
-
buffer
;
const
size_t
target_length
=
target
-
buffer
;
return
UCharToUTF8
({
buffer
,
target_length
});
return
UCharToUTF8
({
buffer
,
target_length
});
#elif defined(HAVE_GLIB)
#elif defined(HAVE_
ICONV) || defined(HAVE_
GLIB)
return
DoConvert
(
to_utf8
,
s
);
return
DoConvert
(
to_utf8
,
s
);
#endif
#endif
}
}
...
@@ -155,7 +192,7 @@ IcuConverter::FromUTF8(const char *s) const
...
@@ -155,7 +192,7 @@ IcuConverter::FromUTF8(const char *s) const
return
AllocatedString
<>::
Duplicate
(
buffer
,
target
);
return
AllocatedString
<>::
Duplicate
(
buffer
,
target
);
#elif defined(HAVE_GLIB)
#elif defined(HAVE_
ICONV) || defined(HAVE_
GLIB)
return
DoConvert
(
from_utf8
,
s
);
return
DoConvert
(
from_utf8
,
s
);
#endif
#endif
}
}
...
...
src/lib/icu/Converter.hxx
View file @
0756607e
...
@@ -26,6 +26,9 @@
...
@@ -26,6 +26,9 @@
#ifdef HAVE_ICU
#ifdef HAVE_ICU
#include "thread/Mutex.hxx"
#include "thread/Mutex.hxx"
#define HAVE_ICU_CONVERTER
#define HAVE_ICU_CONVERTER
#elif defined(HAVE_ICONV)
#include <iconv.h>
#define HAVE_ICU_CONVERTER
#elif defined(HAVE_GLIB)
#elif defined(HAVE_GLIB)
#include <glib.h>
#include <glib.h>
#define HAVE_ICU_CONVERTER
#define HAVE_ICU_CONVERTER
...
@@ -56,6 +59,11 @@ class IcuConverter {
...
@@ -56,6 +59,11 @@ class IcuConverter {
UConverter
*
const
converter
;
UConverter
*
const
converter
;
IcuConverter
(
UConverter
*
_converter
)
:
converter
(
_converter
)
{}
IcuConverter
(
UConverter
*
_converter
)
:
converter
(
_converter
)
{}
#elif defined(HAVE_ICONV)
const
iconv_t
to_utf8
,
from_utf8
;
IcuConverter
(
iconv_t
_to
,
iconv_t
_from
)
:
to_utf8
(
_to
),
from_utf8
(
_from
)
{}
#elif defined(HAVE_GLIB)
#elif defined(HAVE_GLIB)
const
GIConv
to_utf8
,
from_utf8
;
const
GIConv
to_utf8
,
from_utf8
;
...
@@ -66,6 +74,11 @@ class IcuConverter {
...
@@ -66,6 +74,11 @@ class IcuConverter {
public
:
public
:
#ifdef HAVE_ICU
#ifdef HAVE_ICU
~
IcuConverter
();
~
IcuConverter
();
#elif defined(HAVE_ICONV)
~
IcuConverter
()
{
iconv_close
(
to_utf8
);
iconv_close
(
from_utf8
);
}
#elif defined(HAVE_GLIB)
#elif defined(HAVE_GLIB)
~
IcuConverter
()
{
~
IcuConverter
()
{
g_iconv_close
(
to_utf8
);
g_iconv_close
(
to_utf8
);
...
...
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