mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Merge branch 'fix-build-with-icu68' of https://github.com/heirecka/calibre
This commit is contained in:
commit
44f2d0e073
@ -1,5 +1,7 @@
|
|||||||
#include "icu_calibre_utils.h"
|
#include "icu_calibre_utils.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define UPPER_CASE 0
|
#define UPPER_CASE 0
|
||||||
#define LOWER_CASE 1
|
#define LOWER_CASE 1
|
||||||
#define TITLE_CASE 2
|
#define TITLE_CASE 2
|
||||||
@ -238,14 +240,14 @@ icu_Collator_contains(icu_Collator *self, PyObject *args) {
|
|||||||
|
|
||||||
a = python_to_icu(a_, &asz);
|
a = python_to_icu(a_, &asz);
|
||||||
if (a == NULL) goto end;
|
if (a == NULL) goto end;
|
||||||
if (asz == 0) { found = TRUE; goto end; }
|
if (asz == 0) { found = true; goto end; }
|
||||||
b = python_to_icu(b_, &bsz);
|
b = python_to_icu(b_, &bsz);
|
||||||
if (b == NULL) goto end;
|
if (b == NULL) goto end;
|
||||||
|
|
||||||
search = usearch_openFromCollator(a, asz, b, bsz, self->collator, NULL, &status);
|
search = usearch_openFromCollator(a, asz, b, bsz, self->collator, NULL, &status);
|
||||||
if (U_SUCCESS(status)) {
|
if (U_SUCCESS(status)) {
|
||||||
pos = usearch_first(search, &status);
|
pos = usearch_first(search, &status);
|
||||||
if (pos != USEARCH_DONE) found = TRUE;
|
if (pos != USEARCH_DONE) found = true;
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
if (search != NULL) usearch_close(search);
|
if (search != NULL) usearch_close(search);
|
||||||
|
@ -9,15 +9,13 @@
|
|||||||
#define NO_PYTHON_TO_ICU32
|
#define NO_PYTHON_TO_ICU32
|
||||||
#include "icu_calibre_utils.h"
|
#include "icu_calibre_utils.h"
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
// inline does not work with the visual studio C compiler
|
// inline does not work with the visual studio C compiler
|
||||||
#define inline
|
#define inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef unsigned char bool;
|
|
||||||
#define TRUE 1
|
|
||||||
#define FALSE 0
|
|
||||||
#define MAX(x, y) ((x > y) ? x : y)
|
#define MAX(x, y) ((x > y) ? x : y)
|
||||||
#define nullfree(x) if(x != NULL) free(x); x = NULL;
|
#define nullfree(x) if(x != NULL) free(x); x = NULL;
|
||||||
|
|
||||||
@ -240,10 +238,10 @@ static bool create_searches(UStringSearch **searches, UChar *haystack, int32_t h
|
|||||||
U16_FWD_1(needle, i, needle_len);
|
U16_FWD_1(needle, i, needle_len);
|
||||||
if (pos == i) break;
|
if (pos == i) break;
|
||||||
searches[pos] = usearch_openFromCollator(needle + pos, i - pos, haystack, haystack_len, collator, NULL, &status);
|
searches[pos] = usearch_openFromCollator(needle + pos, i - pos, haystack, haystack_len, collator, NULL, &status);
|
||||||
if (U_FAILURE(status)) { PyErr_SetString(PyExc_ValueError, u_errorName(status)); searches[pos] = NULL; return FALSE; }
|
if (U_FAILURE(status)) { PyErr_SetString(PyExc_ValueError, u_errorName(status)); searches[pos] = NULL; return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_searches(UStringSearch **searches, int32_t count) {
|
static void free_searches(UStringSearch **searches, int32_t count) {
|
||||||
@ -259,14 +257,14 @@ static bool match(UChar **items, int32_t *item_lengths, uint32_t item_count, UCh
|
|||||||
int32_t i = 0, maxhl = 0;
|
int32_t i = 0, maxhl = 0;
|
||||||
int32_t r = 0, *positions = NULL;
|
int32_t r = 0, *positions = NULL;
|
||||||
MatchInfo *matches = NULL;
|
MatchInfo *matches = NULL;
|
||||||
bool ok = FALSE;
|
bool ok = false;
|
||||||
MemoryItem ***memo = NULL;
|
MemoryItem ***memo = NULL;
|
||||||
int32_t needle_len = u_strlen(needle);
|
int32_t needle_len = u_strlen(needle);
|
||||||
UStringSearch **searches = NULL;
|
UStringSearch **searches = NULL;
|
||||||
|
|
||||||
if (needle_len <= 0 || item_count <= 0) {
|
if (needle_len <= 0 || item_count <= 0) {
|
||||||
for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0;
|
for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0;
|
||||||
ok = TRUE;
|
ok = true;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +287,7 @@ static bool match(UChar **items, int32_t *item_lengths, uint32_t item_count, UCh
|
|||||||
|
|
||||||
if (maxhl <= 0) {
|
if (maxhl <= 0) {
|
||||||
for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0;
|
for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0;
|
||||||
ok = TRUE;
|
ok = true;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +306,7 @@ static bool match(UChar **items, int32_t *item_lengths, uint32_t item_count, UCh
|
|||||||
convert_positions(positions, final_positions + i * needle_char_len, matches[i].haystack, needle_char_len, needle_len, match_results[i].score);
|
convert_positions(positions, final_positions + i * needle_char_len, matches[i].haystack, needle_char_len, needle_len, match_results[i].score);
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = TRUE;
|
ok = true;
|
||||||
end:
|
end:
|
||||||
nullfree(positions);
|
nullfree(positions);
|
||||||
nullfree(stack.items);
|
nullfree(stack.items);
|
||||||
@ -401,7 +399,7 @@ static PyObject *
|
|||||||
Matcher_calculate_scores(Matcher *self, PyObject *args) {
|
Matcher_calculate_scores(Matcher *self, PyObject *args) {
|
||||||
int32_t *final_positions = NULL, *p;
|
int32_t *final_positions = NULL, *p;
|
||||||
Match *matches = NULL;
|
Match *matches = NULL;
|
||||||
bool ok = FALSE;
|
bool ok = false;
|
||||||
uint32_t i = 0, needle_char_len = 0, j = 0;
|
uint32_t i = 0, needle_char_len = 0, j = 0;
|
||||||
PyObject *items = NULL, *score = NULL, *positions = NULL, *pneedle = NULL;
|
PyObject *items = NULL, *score = NULL, *positions = NULL, *pneedle = NULL;
|
||||||
UChar *needle = NULL;
|
UChar *needle = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user