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
9dc530ab
Commit
9dc530ab
authored
Apr 03, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/icu/Util: pass std::string_view
parent
2d0798cd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
14 deletions
+10
-14
Util.cxx
src/lib/icu/Util.cxx
+6
-11
Util.hxx
src/lib/icu/Util.hxx
+4
-3
No files found.
src/lib/icu/Util.cxx
View file @
9dc530ab
...
@@ -31,18 +31,15 @@
...
@@ -31,18 +31,15 @@
#include <string.h>
#include <string.h>
AllocatedArray
<
UChar
>
AllocatedArray
<
UChar
>
UCharFromUTF8
(
const
char
*
src
)
UCharFromUTF8
(
std
::
string_view
src
)
{
{
assert
(
src
!=
nullptr
);
const
size_t
dest_capacity
=
src
.
size
();
const
size_t
src_length
=
strlen
(
src
);
const
size_t
dest_capacity
=
src_length
;
AllocatedArray
<
UChar
>
dest
(
dest_capacity
);
AllocatedArray
<
UChar
>
dest
(
dest_capacity
);
UErrorCode
error_code
=
U_ZERO_ERROR
;
UErrorCode
error_code
=
U_ZERO_ERROR
;
int32_t
dest_length
;
int32_t
dest_length
;
u_strFromUTF8
(
dest
.
begin
(),
dest_capacity
,
&
dest_length
,
u_strFromUTF8
(
dest
.
begin
(),
dest_capacity
,
&
dest_length
,
src
,
src_length
,
src
.
data
(),
src
.
size
()
,
&
error_code
);
&
error_code
);
if
(
U_FAILURE
(
error_code
))
if
(
U_FAILURE
(
error_code
))
throw
std
::
runtime_error
(
u_errorName
(
error_code
));
throw
std
::
runtime_error
(
u_errorName
(
error_code
));
...
@@ -52,19 +49,17 @@ UCharFromUTF8(const char *src)
...
@@ -52,19 +49,17 @@ UCharFromUTF8(const char *src)
}
}
AllocatedString
<>
AllocatedString
<>
UCharToUTF8
(
ConstBuffer
<
UChar
>
src
)
UCharToUTF8
(
std
::
basic_string_view
<
UChar
>
src
)
{
{
assert
(
!
src
.
IsNull
());
/* worst-case estimate */
/* worst-case estimate */
size_t
dest_capacity
=
4
*
src
.
size
;
size_t
dest_capacity
=
4
*
src
.
size
()
;
std
::
unique_ptr
<
char
[]
>
dest
(
new
char
[
dest_capacity
+
1
]);
std
::
unique_ptr
<
char
[]
>
dest
(
new
char
[
dest_capacity
+
1
]);
UErrorCode
error_code
=
U_ZERO_ERROR
;
UErrorCode
error_code
=
U_ZERO_ERROR
;
int32_t
dest_length
;
int32_t
dest_length
;
u_strToUTF8
(
dest
.
get
(),
dest_capacity
,
&
dest_length
,
u_strToUTF8
(
dest
.
get
(),
dest_capacity
,
&
dest_length
,
src
.
data
,
src
.
size
,
src
.
data
(),
src
.
size
()
,
&
error_code
);
&
error_code
);
if
(
U_FAILURE
(
error_code
))
if
(
U_FAILURE
(
error_code
))
throw
std
::
runtime_error
(
u_errorName
(
error_code
));
throw
std
::
runtime_error
(
u_errorName
(
error_code
));
...
...
src/lib/icu/Util.hxx
View file @
9dc530ab
...
@@ -22,7 +22,8 @@
...
@@ -22,7 +22,8 @@
#include <unicode/utypes.h>
#include <unicode/utypes.h>
template
<
typename
T
>
struct
ConstBuffer
;
#include <string_view>
template
<
typename
T
>
class
AllocatedArray
;
template
<
typename
T
>
class
AllocatedArray
;
template
<
typename
T
>
class
AllocatedString
;
template
<
typename
T
>
class
AllocatedString
;
...
@@ -32,7 +33,7 @@ template<typename T> class AllocatedString;
...
@@ -32,7 +33,7 @@ template<typename T> class AllocatedString;
* Throws std::runtime_error on error.
* Throws std::runtime_error on error.
*/
*/
AllocatedArray
<
UChar
>
AllocatedArray
<
UChar
>
UCharFromUTF8
(
const
char
*
src
);
UCharFromUTF8
(
std
::
string_view
src
);
/**
/**
* Wrapper for u_strToUTF8().
* Wrapper for u_strToUTF8().
...
@@ -40,6 +41,6 @@ UCharFromUTF8(const char *src);
...
@@ -40,6 +41,6 @@ UCharFromUTF8(const char *src);
* Throws std::runtime_error on error.
* Throws std::runtime_error on error.
*/
*/
AllocatedString
<
char
>
AllocatedString
<
char
>
UCharToUTF8
(
ConstBuffer
<
UChar
>
src
);
UCharToUTF8
(
std
::
basic_string_view
<
UChar
>
src
);
#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