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
262e1957
Commit
262e1957
authored
May 27, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/icu/Converter: use libfmt
parent
79241138
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
+12
-10
Converter.cxx
src/lib/icu/Converter.cxx
+11
-10
meson.build
src/lib/icu/meson.build
+1
-0
No files found.
src/lib/icu/Converter.cxx
View file @
262e1957
...
...
@@ -19,10 +19,10 @@
#include "Converter.hxx"
#include "util/AllocatedString.hxx"
#include "util/AllocatedArray.hxx"
#include "util/FormatString.hxx"
#include "config.h"
#include <fmt/format.h>
#include <iterator>
#include <stdexcept>
...
...
@@ -30,6 +30,7 @@
#ifdef HAVE_ICU
#include "Util.hxx"
#include "util/AllocatedArray.hxx"
#include <unicode/ucnv.h>
#elif defined(HAVE_ICONV)
#include "system/Error.hxx"
...
...
@@ -53,8 +54,8 @@ IcuConverter::Create(const char *charset)
UErrorCode
code
=
U_ZERO_ERROR
;
UConverter
*
converter
=
ucnv_open
(
charset
,
&
code
);
if
(
converter
==
nullptr
)
throw
std
::
runtime_error
(
FormatString
(
"Failed to initialize charset '%s': %s"
,
charset
,
u_errorName
(
code
)).
c_str
(
));
throw
std
::
runtime_error
(
fmt
::
format
(
FMT_STRING
(
"Failed to initialize charset '{}': {}"
)
,
charset
,
u_errorName
(
code
)
));
return
std
::
unique_ptr
<
IcuConverter
>
(
new
IcuConverter
(
converter
));
#elif defined(HAVE_ICONV)
...
...
@@ -66,8 +67,8 @@ IcuConverter::Create(const char *charset)
iconv_close
(
to
);
if
(
from
!=
(
iconv_t
)
-
1
)
iconv_close
(
from
);
throw
FormatErrno
(
e
,
"Failed to initialize charset '%s'"
,
charset
);
throw
MakeErrno
(
e
,
fmt
::
format
(
FMT_STRING
(
"Failed to initialize charset '{}'"
)
,
charset
).
c_str
()
);
}
return
std
::
unique_ptr
<
IcuConverter
>
(
new
IcuConverter
(
to
,
from
));
...
...
@@ -118,8 +119,8 @@ IcuConverter::ToUTF8(std::string_view s) const
&
source
,
source
+
s
.
size
(),
nullptr
,
true
,
&
code
);
if
(
code
!=
U_ZERO_ERROR
)
throw
std
::
runtime_error
(
FormatString
(
"Failed to convert to Unicode: %s"
,
u_errorName
(
code
)).
c_str
(
));
throw
std
::
runtime_error
(
fmt
::
format
(
FMT_STRING
(
"Failed to convert to Unicode: {}"
)
,
u_errorName
(
code
)
));
const
size_t
target_length
=
target
-
buffer
;
return
UCharToUTF8
({
buffer
,
target_length
});
...
...
@@ -148,8 +149,8 @@ IcuConverter::FromUTF8(std::string_view s) const
nullptr
,
true
,
&
code
);
if
(
code
!=
U_ZERO_ERROR
)
throw
std
::
runtime_error
(
FormatString
(
"Failed to convert from Unicode: %s"
,
u_errorName
(
code
)).
c_str
(
));
throw
std
::
runtime_error
(
fmt
::
format
(
FMT_STRING
(
"Failed to convert from Unicode: {}"
)
,
u_errorName
(
code
)
));
return
AllocatedString
({
buffer
,
size_t
(
target
-
buffer
)});
...
...
src/lib/icu/meson.build
View file @
262e1957
...
...
@@ -31,6 +31,7 @@ icu = static_library(
include_directories: inc,
dependencies: [
icu_dep,
fmt_dep,
],
)
...
...
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