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
41507d81
Commit
41507d81
authored
May 12, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
icu/Collate: use u_strFoldCase() instead of ucol_getSortKey()
Turns out ucol_getSortKey() does not what I thought it does.
parent
317a98a5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
10 deletions
+41
-10
Collate.cxx
src/lib/icu/Collate.cxx
+41
-10
No files found.
src/lib/icu/Collate.cxx
View file @
41507d81
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#ifdef HAVE_ICU
#ifdef HAVE_ICU
#include "Error.hxx"
#include "Error.hxx"
#include "util/WritableBuffer.hxx"
#include "util/WritableBuffer.hxx"
#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
...
@@ -97,6 +98,28 @@ UCharFromUTF8(const char *src)
...
@@ -97,6 +98,28 @@ UCharFromUTF8(const char *src)
return
{
dest
,
size_t
(
dest_length
)
};
return
{
dest
,
size_t
(
dest_length
)
};
}
}
static
WritableBuffer
<
char
>
UCharToUTF8
(
ConstBuffer
<
UChar
>
src
)
{
assert
(
!
src
.
IsNull
());
/* worst-case estimate */
size_t
dest_capacity
=
4
*
src
.
size
;
char
*
dest
=
new
char
[
dest_capacity
];
UErrorCode
error_code
=
U_ZERO_ERROR
;
int32_t
dest_length
;
u_strToUTF8
(
dest
,
dest_capacity
,
&
dest_length
,
src
.
data
,
src
.
size
,
&
error_code
);
if
(
U_FAILURE
(
error_code
))
{
delete
[]
dest
;
return
nullptr
;
}
return
{
dest
,
size_t
(
dest_length
)
};
}
#endif
#endif
gcc_pure
gcc_pure
...
@@ -147,19 +170,27 @@ IcuCaseFold(const char *src)
...
@@ -147,19 +170,27 @@ IcuCaseFold(const char *src)
if
(
u
.
IsNull
())
if
(
u
.
IsNull
())
return
std
::
string
(
src
);
return
std
::
string
(
src
);
size_t
dest_length
=
ucol_getSortKey
(
collator
,
u
.
data
,
u
.
size
,
size_t
folded_capacity
=
u
.
size
*
2u
;
nullptr
,
0
);
UChar
*
folded
=
new
UChar
[
folded_capacity
];
if
(
dest_length
==
0
)
{
delete
[]
u
.
data
;
UErrorCode
error_code
=
U_ZERO_ERROR
;
size_t
folded_length
=
u_strFoldCase
(
folded
,
folded_capacity
,
u
.
data
,
u
.
size
,
U_FOLD_CASE_DEFAULT
,
&
error_code
);
delete
[]
u
.
data
;
if
(
folded_length
==
0
||
error_code
!=
U_ZERO_ERROR
)
{
delete
[]
folded
;
return
std
::
string
(
src
);
return
std
::
string
(
src
);
}
}
uint8_t
*
dest
=
new
uint8_t
[
dest_length
];
auto
result2
=
UCharToUTF8
({
folded
,
folded_length
});
ucol_getSortKey
(
collator
,
u
.
data
,
u
.
size
,
delete
[]
folded
;
dest
,
dest_length
);
if
(
result2
.
IsNull
())
delete
[]
u
.
data
;
return
std
::
string
(
src
);
std
::
string
result
((
const
char
*
)
dest
);
delete
[]
dest
;
std
::
string
result
(
result2
.
data
,
result2
.
size
);
delete
[]
result2
.
data
;
#elif defined(HAVE_GLIB)
#elif defined(HAVE_GLIB)
char
*
tmp
=
g_utf8_casefold
(
src
,
-
1
);
char
*
tmp
=
g_utf8_casefold
(
src
,
-
1
);
std
::
string
result
(
tmp
);
std
::
string
result
(
tmp
);
...
...
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