mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-24 03:52:50 -06:00
pre now does case insensitive matching if case_sensitive=off is set
This commit is contained in:
@@ -646,8 +646,14 @@ void PgfLinearizer::reverse_and_label(bool add_linref)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGF_INTERNAL_DECL bool
|
||||||
|
pgf_is_case_sensitive(ref<PgfConcr> concr);
|
||||||
|
|
||||||
void PgfLinearizer::flush_pre_stack(PgfLinearizationOutputIface *out, PgfText *token)
|
void PgfLinearizer::flush_pre_stack(PgfLinearizationOutputIface *out, PgfText *token)
|
||||||
{
|
{
|
||||||
|
bool (*cmp)(PgfText *t, PgfText *prefix) =
|
||||||
|
pgf_is_case_sensitive(concr) ? textstarts : textistarts;
|
||||||
|
|
||||||
while (pre_stack != NULL) {
|
while (pre_stack != NULL) {
|
||||||
PreStack *pre = pre_stack;
|
PreStack *pre = pre_stack;
|
||||||
pre_stack = pre->next;
|
pre_stack = pre->next;
|
||||||
@@ -657,7 +663,7 @@ void PgfLinearizer::flush_pre_stack(PgfLinearizationOutputIface *out, PgfText *t
|
|||||||
PgfAlternative *alt = &pre->sym_kp->alts.data[i];
|
PgfAlternative *alt = &pre->sym_kp->alts.data[i];
|
||||||
for (size_t j = 0; j < alt->prefixes->len; j++) {
|
for (size_t j = 0; j < alt->prefixes->len; j++) {
|
||||||
ref<PgfText> prefix = *vector_elem(alt->prefixes,j);
|
ref<PgfText> prefix = *vector_elem(alt->prefixes,j);
|
||||||
if (textstarts(token, &(*prefix))) {
|
if (cmp(token, &(*prefix))) {
|
||||||
pre->node->linearize_seq(out, this, alt->form);
|
pre->node->linearize_seq(out, this, alt->form);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -819,7 +819,7 @@ void pgf_iter_lins(PgfDB *db, PgfConcrRevision cnc_revision,
|
|||||||
} PGF_API_END
|
} PGF_API_END
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
PGF_INTERNAL bool
|
||||||
pgf_is_case_sensitive(ref<PgfConcr> concr)
|
pgf_is_case_sensitive(ref<PgfConcr> concr)
|
||||||
{
|
{
|
||||||
PgfText *case_sensitive = (PgfText *)
|
PgfText *case_sensitive = (PgfText *)
|
||||||
|
|||||||
@@ -74,6 +74,29 @@ bool textstarts(PgfText *t, PgfText *prefix)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGF_INTERNAL
|
||||||
|
bool textistarts(PgfText *t, PgfText *prefix)
|
||||||
|
{
|
||||||
|
const uint8_t *s1 = (uint8_t*) &t->text;
|
||||||
|
const uint8_t *e1 = s1+t->size;
|
||||||
|
|
||||||
|
const uint8_t *s2 = (uint8_t*) &prefix->text;
|
||||||
|
const uint8_t *e2 = s2+prefix->size;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if (s1 >= e1)
|
||||||
|
return false;
|
||||||
|
if (s2 >= e2)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
uint32_t ucs1 = pgf_utf8_to_upper(pgf_utf8_decode(&s1));
|
||||||
|
uint32_t ucs2 = pgf_utf8_to_upper(pgf_utf8_decode(&s2));
|
||||||
|
|
||||||
|
if (ucs1 != ucs2)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PGF_INTERNAL
|
PGF_INTERNAL
|
||||||
PgfText* textdup(PgfText *t1)
|
PgfText* textdup(PgfText *t1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ void texticmp(PgfText *t1, PgfText *t2, int res[2]);
|
|||||||
PGF_INTERNAL_DECL
|
PGF_INTERNAL_DECL
|
||||||
bool textstarts(PgfText *t, PgfText *prefix);
|
bool textstarts(PgfText *t, PgfText *prefix);
|
||||||
|
|
||||||
|
PGF_INTERNAL
|
||||||
|
bool textistarts(PgfText *t, PgfText *prefix);
|
||||||
|
|
||||||
PGF_INTERNAL_DECL
|
PGF_INTERNAL_DECL
|
||||||
PgfText* string2text(const char *s);
|
PgfText* string2text(const char *s);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user