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
4eaa82fd
Commit
4eaa82fd
authored
Apr 12, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/icu/Util: add overload which throws exception
parent
a497cc46
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
Util.cxx
src/lib/icu/Util.cxx
+23
-0
Util.hxx
src/lib/icu/Util.hxx
+8
-0
No files found.
src/lib/icu/Util.cxx
View file @
4eaa82fd
...
...
@@ -27,6 +27,7 @@
#include <unicode/ustring.h>
#include <memory>
#include <stdexcept>
#include <assert.h>
#include <string.h>
...
...
@@ -73,3 +74,25 @@ UCharToUTF8(ConstBuffer<UChar> src)
dest
[
dest_length
]
=
0
;
return
AllocatedString
<>::
Donate
(
dest
.
release
());
}
AllocatedString
<>
UCharToUTF8Throw
(
ConstBuffer
<
UChar
>
src
)
{
assert
(
!
src
.
IsNull
());
/* worst-case estimate */
size_t
dest_capacity
=
4
*
src
.
size
;
std
::
unique_ptr
<
char
[]
>
dest
(
new
char
[
dest_capacity
+
1
]);
UErrorCode
error_code
=
U_ZERO_ERROR
;
int32_t
dest_length
;
u_strToUTF8
(
dest
.
get
(),
dest_capacity
,
&
dest_length
,
src
.
data
,
src
.
size
,
&
error_code
);
if
(
U_FAILURE
(
error_code
))
throw
std
::
runtime_error
(
u_errorName
(
error_code
));
dest
[
dest_length
]
=
0
;
return
AllocatedString
<>::
Donate
(
dest
.
release
());
}
src/lib/icu/Util.hxx
View file @
4eaa82fd
...
...
@@ -40,4 +40,12 @@ UCharFromUTF8(const char *src);
AllocatedString
<
char
>
UCharToUTF8
(
ConstBuffer
<
UChar
>
src
);
/**
* Wrapper for u_strToUTF8().
*
* Throws std::runtime_error on error.
*/
AllocatedString
<
char
>
UCharToUTF8Throw
(
ConstBuffer
<
UChar
>
src
);
#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