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
317a98a5
Commit
317a98a5
authored
May 12, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
icu/Collate: UCharFromUTF8() returns WritableBuffer<UChar>
parent
13957949
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
19 deletions
+20
-19
Collate.cxx
src/lib/icu/Collate.cxx
+20
-19
No files found.
src/lib/icu/Collate.cxx
View file @
317a98a5
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#ifdef HAVE_ICU
#ifdef HAVE_ICU
#include "Error.hxx"
#include "Error.hxx"
#include "util/WritableBuffer.hxx"
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
...
@@ -74,18 +75,18 @@ IcuCollateFinish()
...
@@ -74,18 +75,18 @@ IcuCollateFinish()
#ifdef HAVE_ICU
#ifdef HAVE_ICU
static
UChar
*
static
WritableBuffer
<
UChar
>
UCharFromUTF8
(
const
char
*
src
,
int32_t
*
dest_length
)
UCharFromUTF8
(
const
char
*
src
)
{
{
assert
(
src
!=
nullptr
);
assert
(
src
!=
nullptr
);
const
size_t
src_length
=
strlen
(
src
);
const
size_t
src_length
=
strlen
(
src
);
size_t
dest_capacity
=
src_length
+
1
;
const
size_t
dest_capacity
=
src_length
;
UChar
*
dest
=
new
UChar
[
dest_capacity
];
UChar
*
dest
=
new
UChar
[
dest_capacity
];
UErrorCode
error_code
=
U_ZERO_ERROR
;
UErrorCode
error_code
=
U_ZERO_ERROR
;
u_strFromUTF8
(
dest
,
dest_capacity
,
int32_t
dest_length
;
dest_length
,
u_strFromUTF8
(
dest
,
dest_capacity
,
&
dest_length
,
src
,
src_length
,
src
,
src_length
,
&
error_code
);
&
error_code
);
if
(
U_FAILURE
(
error_code
))
{
if
(
U_FAILURE
(
error_code
))
{
...
@@ -93,7 +94,7 @@ UCharFromUTF8(const char *src, int32_t *dest_length)
...
@@ -93,7 +94,7 @@ UCharFromUTF8(const char *src, int32_t *dest_length)
return
nullptr
;
return
nullptr
;
}
}
return
dest
;
return
{
dest
,
size_t
(
dest_length
)
}
;
}
}
#endif
#endif
...
@@ -114,15 +115,16 @@ IcuCollate(const char *a, const char *b)
...
@@ -114,15 +115,16 @@ IcuCollate(const char *a, const char *b)
#else
#else
/* fall back to ucol_strcoll() */
/* fall back to ucol_strcoll() */
UChar
*
au
=
UCharFromUTF8
(
a
,
nullptr
);
const
auto
au
=
UCharFromUTF8
(
a
);
UChar
*
bu
=
UCharFromUTF8
(
b
,
nullptr
);
const
auto
bu
=
UCharFromUTF8
(
b
);
int
result
=
au
!=
nullptr
&&
bu
!=
nullptr
int
result
=
!
au
.
IsNull
()
&&
!
bu
.
IsNull
()
?
(
int
)
ucol_strcoll
(
collator
,
au
,
-
1
,
bu
,
-
1
)
?
(
int
)
ucol_strcoll
(
collator
,
au
.
data
,
au
.
size
,
bu
.
data
,
bu
.
size
)
:
strcasecmp
(
a
,
b
);
:
strcasecmp
(
a
,
b
);
delete
[]
au
;
delete
[]
au
.
data
;
delete
[]
bu
;
delete
[]
bu
.
data
;
return
result
;
return
result
;
#endif
#endif
...
@@ -141,22 +143,21 @@ IcuCaseFold(const char *src)
...
@@ -141,22 +143,21 @@ IcuCaseFold(const char *src)
assert
(
collator
!=
nullptr
);
assert
(
collator
!=
nullptr
);
assert
(
src
!=
nullptr
);
assert
(
src
!=
nullptr
);
int32_t
u_length
;
const
auto
u
=
UCharFromUTF8
(
src
);
UChar
*
u
=
UCharFromUTF8
(
src
,
&
u_length
);
if
(
u
.
IsNull
())
if
(
u
==
nullptr
)
return
std
::
string
(
src
);
return
std
::
string
(
src
);
size_t
dest_length
=
ucol_getSortKey
(
collator
,
u
,
u_length
,
size_t
dest_length
=
ucol_getSortKey
(
collator
,
u
.
data
,
u
.
size
,
nullptr
,
0
);
nullptr
,
0
);
if
(
dest_length
==
0
)
{
if
(
dest_length
==
0
)
{
delete
[]
u
;
delete
[]
u
.
data
;
return
std
::
string
(
src
);
return
std
::
string
(
src
);
}
}
uint8_t
*
dest
=
new
uint8_t
[
dest_length
];
uint8_t
*
dest
=
new
uint8_t
[
dest_length
];
ucol_getSortKey
(
collator
,
u
,
u_length
,
ucol_getSortKey
(
collator
,
u
.
data
,
u
.
size
,
dest
,
dest_length
);
dest
,
dest_length
);
delete
[]
u
;
delete
[]
u
.
data
;
std
::
string
result
((
const
char
*
)
dest
);
std
::
string
result
((
const
char
*
)
dest
);
delete
[]
dest
;
delete
[]
dest
;
#elif defined(HAVE_GLIB)
#elif defined(HAVE_GLIB)
...
...
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