sub_atom
This commit is contained in:
parent
9fce1e9ba2
commit
63e8e89dab
41
C/atomic.c
41
C/atomic.c
@ -2230,17 +2230,17 @@ static bool check_sub_string_bef(int max, const unsigned char *p1,
|
|||||||
const unsigned char *p2) {
|
const unsigned char *p2) {
|
||||||
size_t len = strlen_utf8(p2);
|
size_t len = strlen_utf8(p2);
|
||||||
int minv = max - len;
|
int minv = max - len;
|
||||||
int c1;
|
int c2;
|
||||||
|
|
||||||
if ((Int)(minv - len) < 0)
|
if ((Int)(minv) < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
p1 = skip_utf8(p1, minv);
|
p1 = skip_utf8(p1, minv);
|
||||||
if (p1 == NULL || p2 == NULL)
|
if (p1 == NULL || p2 == NULL)
|
||||||
return p1 == p2;
|
return p1 == p2;
|
||||||
while ((c1 = *p1++) == *p2++ && c1)
|
while ((c2 = *p2++) == *p1++ && c2)
|
||||||
;
|
;
|
||||||
return c1 == 0;
|
return c2 == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int cont_sub_atomic(USES_REGS1) {
|
static Int cont_sub_atomic(USES_REGS1) {
|
||||||
@ -2478,8 +2478,29 @@ static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) {
|
|||||||
if (bnds > 1) {
|
if (bnds > 1) {
|
||||||
int out = FALSE;
|
int out = FALSE;
|
||||||
|
|
||||||
if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) ==
|
if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_AFTER)) ==
|
||||||
|
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_AFTER)) {
|
||||||
|
const unsigned char *sm;
|
||||||
|
if (sub_atom)
|
||||||
|
sm = RepAtom(AtomOfTerm(tout))->UStrOfAE;
|
||||||
|
else
|
||||||
|
sm = UStringOfTerm(tout);
|
||||||
|
if (mask & SUB_ATOM_HAS_SIZE) {
|
||||||
|
if (len != strlen_utf8(sm) ) {
|
||||||
|
cut_fail();
|
||||||
|
} else {
|
||||||
|
len = strlen_utf8(sm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sz != minv+len+after) {
|
||||||
|
cut_fail();
|
||||||
|
}
|
||||||
|
return do_cut(check_sub_string_at(
|
||||||
|
minv, p, sm, len));
|
||||||
|
} else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) ==
|
||||||
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) {
|
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) {
|
||||||
|
if (! Yap_unify(ARG4,MkIntegerTerm(sz-minv-len)) )
|
||||||
|
cut_fail();
|
||||||
if (sub_atom)
|
if (sub_atom)
|
||||||
return do_cut(check_sub_string_at(
|
return do_cut(check_sub_string_at(
|
||||||
minv, p, RepAtom(AtomOfTerm(tout))->UStrOfAE, len));
|
minv, p, RepAtom(AtomOfTerm(tout))->UStrOfAE, len));
|
||||||
@ -2487,14 +2508,16 @@ static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) {
|
|||||||
return do_cut(check_sub_string_at(minv, p, UStringOfTerm(tout), len));
|
return do_cut(check_sub_string_at(minv, p, UStringOfTerm(tout), len));
|
||||||
} else if ((mask & (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) ==
|
} else if ((mask & (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) ==
|
||||||
(SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) {
|
(SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) {
|
||||||
if (sub_atom)
|
if (! Yap_unify(ARG2,MkIntegerTerm(sz-after-len)) )
|
||||||
|
cut_fail();
|
||||||
|
if (sub_atom) {
|
||||||
return do_cut(check_sub_string_bef(
|
return do_cut(check_sub_string_bef(
|
||||||
sz - after, p, RepAtom(AtomOfTerm(tout))->UStrOfAE));
|
sz - after, p, RepAtom(AtomOfTerm(tout))->UStrOfAE));
|
||||||
else
|
} else {
|
||||||
return do_cut(check_sub_string_bef(sz - after, p, UStringOfTerm(tout)));
|
return do_cut(check_sub_string_bef(sz - after, p, UStringOfTerm(tout)));}
|
||||||
} else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) ==
|
} else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) ==
|
||||||
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) {
|
(SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) {
|
||||||
if (minv + len > sz) {
|
if (minv + len + after > sz) {
|
||||||
cut_fail();
|
cut_fail();
|
||||||
}
|
}
|
||||||
if ((Int)(after = (sz - (minv + len))) < 0) {
|
if ((Int)(after = (sz - (minv + len))) < 0) {
|
||||||
|
Reference in New Issue
Block a user