new text interface

This commit is contained in:
Vitor Santos Costa 2016-08-15 15:30:26 -05:00
parent 0f32e2cc9f
commit fab0075f9b

View File

@ -203,6 +203,7 @@ X_API int PL_get_nchars(term_t l, size_t *lengthp, char **s, unsigned flags) {
inp.val.t = Yap_GetFromSlot(l); inp.val.t = Yap_GetFromSlot(l);
inp.type = cvtFlags(flags); inp.type = cvtFlags(flags);
out.type = YAP_STRING_CHARS; out.type = YAP_STRING_CHARS;
out.val.c = *s;
if (flags & (REP_UTF8 | REP_MB)) { if (flags & (REP_UTF8 | REP_MB)) {
out.enc = ENC_ISO_UTF8; out.enc = ENC_ISO_UTF8;
} else { } else {
@ -210,11 +211,13 @@ X_API int PL_get_nchars(term_t l, size_t *lengthp, char **s, unsigned flags) {
} }
if (flags & BUF_MALLOC) if (flags & BUF_MALLOC)
out.type |= YAP_STRING_MALLOC; out.type |= YAP_STRING_MALLOC;
if (lengthp) {
out.type |= YAP_STRING_NCHARS;
out.max = *lengthp;
}
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return false; return false;
*s = out.val.c; *s = out.val.c;
if (lengthp)
*lengthp = out.sz;
return true; return true;
} }
@ -231,11 +234,15 @@ int PL_get_wchars(term_t l, size_t *lengthp, wchar_t **s, unsigned flags) {
out.type = YAP_STRING_WCHARS; out.type = YAP_STRING_WCHARS;
if (flags & BUF_MALLOC) if (flags & BUF_MALLOC)
out.type |= YAP_STRING_MALLOC; out.type |= YAP_STRING_MALLOC;
if (lengthp) {
out.type |= YAP_STRING_NCHARS;
out.max = *lengthp;
}
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return false; return false;
*s = out.val.w; *s = out.val.w;
if (lengthp) if (lengthp && (out.type & YAP_STRING_NCHARS))
*lengthp = out.sz; *lengthp = out.max;
return true; return true;
} }
@ -245,13 +252,9 @@ X_API int PL_unify_chars(term_t l, int flags, size_t length, const char *s) {
if (flags & REP_UTF8) { if (flags & REP_UTF8) {
inp.val.c0 = s; inp.val.c0 = s;
inp.type = YAP_STRING_CHARS|ENC_ISO_LATIN1;
if (length != (size_t)-1) { if (length != (size_t)-1) {
inp.sz = length; inp.type |= YAP_STRING_NCHARS;
inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
inp.enc = ENC_ISO_UTF8;
} else {
inp.type = YAP_STRING_CHARS;
inp.enc = ENC_ISO_LATIN1;
} }
} }
if (flags & PL_ATOM) { if (flags & PL_ATOM) {