fix list of atoms (Paulo Moura obs)
This commit is contained in:
parent
0f560abc92
commit
7038ea1958
22
C/text.c
22
C/text.c
@ -707,6 +707,10 @@ write_atoms( void *s0, seq_tv_t *out, encoding_t enc, int minimal, size_t leng U
|
|||||||
Term t = AbsPair(HR);
|
Term t = AbsPair(HR);
|
||||||
size_t sz = 0;
|
size_t sz = 0;
|
||||||
size_t min = 0, max = leng;
|
size_t min = 0, max = leng;
|
||||||
|
if (leng == 0) {
|
||||||
|
out->val.t = t;
|
||||||
|
return TermNil;
|
||||||
|
}
|
||||||
if (out->type & (YAP_STRING_NCHARS|YAP_STRING_TRUNC)) {
|
if (out->type & (YAP_STRING_NCHARS|YAP_STRING_TRUNC)) {
|
||||||
if (out->type & YAP_STRING_NCHARS) min = out->sz;
|
if (out->type & YAP_STRING_NCHARS) min = out->sz;
|
||||||
if (out->type & YAP_STRING_TRUNC && out->max < max) max = out->max;
|
if (out->type & YAP_STRING_TRUNC && out->max < max) max = out->max;
|
||||||
@ -719,13 +723,16 @@ write_atoms( void *s0, seq_tv_t *out, encoding_t enc, int minimal, size_t leng U
|
|||||||
wchar_t w[2];
|
wchar_t w[2];
|
||||||
w[1] = '\0';
|
w[1] = '\0';
|
||||||
LOCAL_TERM_ERROR( 2*(lim-s) );
|
LOCAL_TERM_ERROR( 2*(lim-s) );
|
||||||
while (cp < lim) {
|
while (cp < lim && *cp) {
|
||||||
int chr;
|
int chr;
|
||||||
|
CELL *cl;
|
||||||
cp = utf8_get_char(cp, &chr);
|
cp = utf8_get_char(cp, &chr);
|
||||||
|
if (chr == '\0') break;
|
||||||
w[0] = chr;
|
w[0] = chr;
|
||||||
HR[0] = MkAtomTerm(Yap_LookupMaybeWideAtom(w));
|
cl = HR;
|
||||||
HR[1] = AbsPair(HR+2);
|
|
||||||
HR += 2;
|
HR += 2;
|
||||||
|
cl[0] = MkAtomTerm(Yap_LookupMaybeWideAtom(w));
|
||||||
|
cl[1] = AbsPair(HR);
|
||||||
sz++;
|
sz++;
|
||||||
if (sz == max) break;
|
if (sz == max) break;
|
||||||
}
|
}
|
||||||
@ -741,6 +748,7 @@ write_atoms( void *s0, seq_tv_t *out, encoding_t enc, int minimal, size_t leng U
|
|||||||
while (cp < lim) {
|
while (cp < lim) {
|
||||||
int chr;
|
int chr;
|
||||||
cp = get_char(cp, &chr);
|
cp = get_char(cp, &chr);
|
||||||
|
if (chr == '\0') break;
|
||||||
w[0] = chr;
|
w[0] = chr;
|
||||||
HR[0] = MkAtomTerm(Yap_LookupAtom(w));
|
HR[0] = MkAtomTerm(Yap_LookupAtom(w));
|
||||||
HR[1] = AbsPair(HR+2);
|
HR[1] = AbsPair(HR+2);
|
||||||
@ -760,6 +768,7 @@ write_atoms( void *s0, seq_tv_t *out, encoding_t enc, int minimal, size_t leng U
|
|||||||
while (*cp && cp < lim) {
|
while (*cp && cp < lim) {
|
||||||
int chr;
|
int chr;
|
||||||
cp = get_wchar(cp, &chr);
|
cp = get_wchar(cp, &chr);
|
||||||
|
if (chr == '\0') break;
|
||||||
w[0] = chr;
|
w[0] = chr;
|
||||||
HR[0] = MkAtomTerm(Yap_LookupMaybeWideAtom(w));
|
HR[0] = MkAtomTerm(Yap_LookupMaybeWideAtom(w));
|
||||||
HR[1] = AbsPair(HR+2);
|
HR[1] = AbsPair(HR+2);
|
||||||
@ -769,12 +778,6 @@ write_atoms( void *s0, seq_tv_t *out, encoding_t enc, int minimal, size_t leng U
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (sz < min) {
|
|
||||||
HR[0] = MkAtomTerm(AtomEmptyAtom);
|
|
||||||
HR[1] = AbsPair(HR+2);
|
|
||||||
HR += 2;
|
|
||||||
sz++;
|
|
||||||
}
|
|
||||||
if (out->type & YAP_STRING_DIFF) {
|
if (out->type & YAP_STRING_DIFF) {
|
||||||
if (sz == 0) t = out->dif;
|
if (sz == 0) t = out->dif;
|
||||||
else HR[-1] = Globalize(out->dif PASS_REGS);
|
else HR[-1] = Globalize(out->dif PASS_REGS);
|
||||||
@ -1015,7 +1018,6 @@ write_term( void *s0, seq_tv_t *out, encoding_t enc, int minimal, size_t leng US
|
|||||||
int
|
int
|
||||||
write_Text( void *inp, seq_tv_t *out, encoding_t enc, int minimal, size_t leng USES_REGS)
|
write_Text( void *inp, seq_tv_t *out, encoding_t enc, int minimal, size_t leng USES_REGS)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* we know what the term is */
|
/* we know what the term is */
|
||||||
switch (out->type & YAP_TYPE_MASK) {
|
switch (out->type & YAP_TYPE_MASK) {
|
||||||
case YAP_STRING_STRING:
|
case YAP_STRING_STRING:
|
||||||
|
Reference in New Issue
Block a user