Skip to content

Commit 14b18e9

Browse files
committed
Use Dovecot's internal unichar handling
See GitHub Issue slusarz#62
1 parent 28f7c50 commit 14b18e9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/fts-backend-flatcurve-xapian.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern "C" {
2424
#include "sleep.h"
2525
#include "str.h"
2626
#include "time-util.h"
27+
#include "unichar.h"
2728
#include "fts-backend-flatcurve.h"
2829
#include "fts-backend-flatcurve-xapian.h"
2930
#include <dirent.h>
@@ -1247,7 +1248,7 @@ fts_flatcurve_xapian_index_header(struct flatcurve_fts_backend_update_context *c
12471248
{
12481249
struct fts_flatcurve_user *fuser = ctx->backend->fuser;
12491250
std::string h;
1250-
Xapian::Utf8Iterator ustr;
1251+
const char *p = (const char *)data;
12511252
struct flatcurve_xapian *x = ctx->backend->xapian;
12521253

12531254
if (!fts_flatcurve_xapian_init_msg(ctx))
@@ -1259,12 +1260,11 @@ fts_flatcurve_xapian_index_header(struct flatcurve_fts_backend_update_context *c
12591260
FLATCURVE_XAPIAN_BOOLEAN_FIELD_PREFIX + h);
12601261
}
12611262

1262-
ustr = Xapian::Utf8Iterator((const char *)data, size);
12631263
if (ctx->indexed_hdr)
12641264
h = str_ucase(str_c_modifiable(ctx->hdr_name));
12651265

12661266
do {
1267-
std::string t (ustr.raw());
1267+
std::string t (p, size);
12681268

12691269
/* Capital ASCII letters at the beginning of a Xapian term are
12701270
* treated as a "term prefix". Check for a leading ASCII
@@ -1278,25 +1278,28 @@ fts_flatcurve_xapian_index_header(struct flatcurve_fts_backend_update_context *c
12781278
FLATCURVE_XAPIAN_HEADER_PREFIX + h + t);
12791279
}
12801280
x->doc->add_term(FLATCURVE_XAPIAN_ALL_HEADERS_PREFIX + t);
1281+
1282+
unsigned int csize = uni_utf8_char_bytes(*p);
1283+
p += csize;
1284+
size -= csize;
12811285
} while (fuser->set.substring_search &&
1282-
((++ustr).left() >= fuser->set.min_term_size));
1286+
(size >= 0) &&
1287+
(uni_utf8_strlen(p) >= fuser->set.min_term_size));
12831288
}
12841289

12851290
void
12861291
fts_flatcurve_xapian_index_body(struct flatcurve_fts_backend_update_context *ctx,
12871292
const unsigned char *data, size_t size)
12881293
{
12891294
struct fts_flatcurve_user *fuser = ctx->backend->fuser;
1290-
Xapian::Utf8Iterator ustr;
1295+
const char *p = (const char *)data;
12911296
struct flatcurve_xapian *x = ctx->backend->xapian;
12921297

12931298
if (!fts_flatcurve_xapian_init_msg(ctx))
12941299
return;
12951300

1296-
ustr = Xapian::Utf8Iterator((const char *)data, size);
1297-
12981301
do {
1299-
std::string t (ustr.raw());
1302+
std::string t (p, size);
13001303

13011304
/* Capital ASCII letters at the beginning of a Xapian term are
13021305
* treated as a "term prefix". Check for a leading ASCII
@@ -1306,8 +1309,13 @@ fts_flatcurve_xapian_index_body(struct flatcurve_fts_backend_update_context *ctx
13061309
t[0] = i_tolower(t[0]);
13071310

13081311
x->doc->add_term(t);
1312+
1313+
unsigned int csize = uni_utf8_char_bytes(*p);
1314+
p += csize;
1315+
size -= csize;
13091316
} while (fuser->set.substring_search &&
1310-
((++ustr).left() >= fuser->set.min_term_size));
1317+
(size >= 0) &&
1318+
(uni_utf8_strlen(p) >= fuser->set.min_term_size));
13111319
}
13121320

13131321
void fts_flatcurve_xapian_delete_index(struct flatcurve_fts_backend *backend)

0 commit comments

Comments
 (0)