X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ficu_sortkey.c;h=32ee1349407c549d5fd1380ab3559ed6bb1b97fe;hb=03dccce903176e61f889b1558834aa5a09f9f8c0;hp=8fed3948a4f6ffc55519e1e80b71a2548261e103;hpb=43a9d38d20c1b1bcd1a03b2445a501d27526bd35;p=yaz-moved-to-github.git diff --git a/src/icu_sortkey.c b/src/icu_sortkey.c index 8fed394..32ee134 100644 --- a/src/icu_sortkey.c +++ b/src/icu_sortkey.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2011 Index Data + * Copyright (C) 1995-2012 Index Data * See the file LICENSE for details. */ @@ -32,12 +32,15 @@ void icu_sortkey8_from_utf16(UCollator *coll, UErrorCode * status) { 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, - dest8->utf8, dest8->utf8_cap); + dest8->utf8, cap); /* 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,