projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Version 5.9.0
[yaz-moved-to-github.git]
/
src
/
icu_sortkey.c
diff --git
a/src/icu_sortkey.c
b/src/icu_sortkey.c
index
a00c473
..
ceffa59
100644
(file)
--- a/
src/icu_sortkey.c
+++ b/
src/icu_sortkey.c
@@
-1,5
+1,5
@@
/* This file is part of the YAZ toolkit.
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2009 Index Data
+ * Copyright (C) Index Data
* See the file LICENSE for details.
*/
* See the file LICENSE for details.
*/
@@
-27,17
+27,20
@@
#include <unicode/uchar.h> /* char names */
void icu_sortkey8_from_utf16(UCollator *coll,
#include <unicode/uchar.h> /* char names */
void icu_sortkey8_from_utf16(UCollator *coll,
- struct icu_buf_utf8 * dest8,
- struct icu_buf_utf16 * src16,
+ struct icu_buf_utf8 *dest8,
+ struct icu_buf_utf16 *src16,
UErrorCode * status)
UErrorCode * status)
-{
+{
int32_t sortkey_len = 0;
int32_t sortkey_len = 0;
+ /* we'll fake a capacity of one less, because it turns out
+ that ucol_getSortKey writes ONE character too much */
+ int32_t cap = dest8->utf8_cap ? dest8->utf8_cap - 1 : 0;
sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
- dest8->utf8, dest8->utf8_cap);
+ dest8->utf8, cap);
/* check for buffer overflow, resize and retry */
/* check for buffer overflow, resize and retry */
- if (sortkey_len > dest8->utf8_cap)
+ if (sortkey_len > cap)
{
icu_buf_utf8_resize(dest8, sortkey_len * 2);
sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
{
icu_buf_utf8_resize(dest8, sortkey_len * 2);
sortkey_len = ucol_getSortKey(coll, src16->utf16, src16->utf16_len,
@@
-47,7
+50,7
@@
void icu_sortkey8_from_utf16(UCollator *coll,
if (U_SUCCESS(*status)
&& sortkey_len > 0)
dest8->utf8_len = sortkey_len;
if (U_SUCCESS(*status)
&& sortkey_len > 0)
dest8->utf8_len = sortkey_len;
- else
+ else
icu_buf_utf8_clear(dest8);
}
icu_buf_utf8_clear(dest8);
}