Skip to content

Commit 501be32

Browse files
committed
Merge pull request #49 from couchbase/feature/issue_1254
Fixed https://github.com/couchbase/couchbase-lite-java-core/issues/12…
2 parents 7271a5e + bdff59b commit 501be32

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

jni/source/com_couchbase_lite_storage_SQLiteJsonCollator.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,17 @@ static const char* createStringFromJSON(const char** in) {
338338
return (const char *)buf;
339339
}
340340

341+
static int compareBinary(const char *str1, const char *str2) {
342+
if (str1 == NULL && str2 == NULL)
343+
return 0;
344+
else if (str1 != NULL && str2 == NULL)
345+
return 1;
346+
else if (str1 == NULL && str2 != NULL)
347+
return -1;
348+
else
349+
return strcmp(str1, str2);
350+
}
351+
341352
static int compareStringsUnicode(const void *context, const char **in1, const char **in2) {
342353
int result = compareStringsUnicodeFast(in1, in2);
343354
if (result > -2)
@@ -352,20 +363,21 @@ static int compareStringsUnicode(const void *context, const char **in1, const ch
352363
if (c) {
353364
Collator* collator = (Collator*)c;
354365
result = (int)(collator->compare(str1, str2));
355-
} else
356-
result = 0;
366+
} else {
367+
result = compareBinary(str1, str2);
368+
}
357369
#else
358370
// Fast compare failed, so resort to using java.text.Collator
359371
// HACK : calling back to Java to do unicode string compare.
360372
result = java_unicode_string_compare(str1, str2);
361373
#endif
362374

363375
if (str1 != NULL) {
364-
::free((void*)str1);
376+
::free((void *) str1);
365377
str1 = NULL;
366378
}
367379
if (str2 != NULL) {
368-
::free((void*)str2);
380+
::free((void *) str2);
369381
str2 = NULL;
370382
}
371383

0 commit comments

Comments
 (0)