20#ifndef YAPTEXT_H_INCLUDED
21#define YAPTEXT_H_INCLUDED
32#define Yap_Min(x, y) (x < y ? x : y)
38#define NUMBER_OF_CHARS 256
39extern char *Yap_chtype;
41#define Yap_strlen(s) strlen((void *)(s))
59extern char_kind_t Yap_chtype0[];
61#define Yap_chtype (Yap_chtype0 + 1)
66inline static char_kind_t chtype(Int ch) {
67 if (ch < NUMBER_OF_CHARS)
68 return Yap_chtype[ch];
73#define __android_log_print(...)
76extern const char *Yap_tokText(
void *tokptr);
86 YAP_STRING_STRING = 0x1,
87 YAP_STRING_CODES = 0x2,
88 YAP_STRING_ATOMS = 0x4,
89 YAP_STRING_ATOMS_CODES = 0x6,
90 YAP_STRING_CHARS = 0x8,
91 YAP_STRING_WCHARS = 0x10,
92 YAP_STRING_ATOM = 0x20,
93 YAP_STRING_INT = 0x40,
94 YAP_STRING_FLOAT = 0x80,
95 YAP_STRING_BIG = 0x100,
96 YAP_STRING_DATUM = 0x200,
97 YAP_STRING_LENGTH = 0x400,
98 YAP_STRING_NTH = 0x800,
99 YAP_STRING_TERM = 0x1000,
100 YAP_STRING_DIFF = 0x2000,
101 YAP_STRING_NCHARS = 0x4000,
102 YAP_STRING_TRUNC = 0x8000,
103 YAP_STRING_WQ = 0x10000,
104 YAP_STRING_WC = 0x20000,
105 YAP_STRING_WITH_BUFFER = 0x40000,
106 YAP_STRING_MALLOC = 0x80000,
107 YAP_STRING_UPCASE = 0x100000,
108 YAP_STRING_DOWNCASE = 0x200000,
109 YAP_STRING_IN_TMP = 0x400000,
110 YAP_STRING_OUTPUT_TERM = 0x800000,
111 YAP_STRING_PREFER_LIST = 0x1000000
114typedef UInt seq_type_t;
116#define YAP_TYPE_MASK 0x0FFF
126 const unsigned char *uc0;
145static inline seq_type_t mod_to_type(Term mod USES_REGS) {
148 unsigned int flags = Yap_GetModuleEntry(mod)->
flags;
149 if (flags & DBLQ_ATOM) {
150 return YAP_STRING_ATOM | YAP_STRING_OUTPUT_TERM;
151 }
else if (flags & DBLQ_STRING) {
152 return YAP_STRING_STRING;
153 }
else if (flags & DBLQ_CHARS) {
154 return YAP_STRING_ATOMS;
156 return YAP_STRING_CODES;
160static inline seq_type_t mod_to_atype(Term mod USES_REGS) {
163 unsigned int flags = Yap_GetModuleEntry(mod)->
flags;
164 if (flags & SNGQ_ATOM) {
165 return YAP_STRING_ATOM | YAP_STRING_OUTPUT_TERM;
166 }
else if (flags & SNGQ_STRING) {
167 return YAP_STRING_STRING;
168 }
else if (flags & SNGQ_CHARS) {
169 return YAP_STRING_ATOMS;
171 return YAP_STRING_CODES;
175static inline seq_type_t mod_to_bqtype(Term mod USES_REGS) {
178 unsigned int flags = Yap_GetModuleEntry(mod)->
flags;
179 if (flags & BCKQ_STRING) {
180 return YAP_STRING_STRING;
181 }
else if (flags & BCKQ_ATOM) {
182 return YAP_STRING_ATOM | YAP_STRING_OUTPUT_TERM;
183 }
else if (flags & BCKQ_CHARS) {
184 return YAP_STRING_ATOMS;
185 }
else if (flags & BCKQ_CODES) {
186 return YAP_STRING_CODES;
188 if ((t2 = GLOBAL_Flags[BACK_QUOTES_FLAG].at)) {
189 if (t2 == TermString) {
190 return YAP_STRING_STRING;
191 }
else if (t2 == TermAtom) {
192 return YAP_STRING_ATOM | YAP_STRING_OUTPUT_TERM;
193 }
else if (t2 == TermCodes) {
194 return YAP_STRING_CODES;
197 return YAP_STRING_ATOMS;
200static inline seq_type_t Yap_TextType(Term t) {
201 if (IsVarTerm(t = Deref(t))) {
202 Yap_ThrowError(INSTANTIATION_ERROR, t,
"expected text");
205 return YAP_STRING_ATOM;
207 if (IsStringTerm(t)) {
208 return YAP_STRING_STRING;
211 Term hd = HeadOfTerm(t);
213 Yap_ThrowError(INSTANTIATION_ERROR, t,
"expected text");
215 if (IsIntegerTerm(hd)) {
216 return YAP_STRING_CODES;
218 if (IsAtomTerm(hd)) {
219 return YAP_STRING_ATOMS;
222 Yap_ThrowError(TYPE_ERROR_TEXT, t,
"expected text");
223 return YAP_STRING_ATOM;
228extern unsigned char *Yap_readText(
seq_tv_t *inp USES_REGS);
229extern bool write_Text(
unsigned char *inp,
seq_tv_t *out USES_REGS);
232extern bool Yap_Splice_Text(
int n,
size_t cuts[],
seq_tv_t *inp,
237static inline Atom Yap_AtomicToLowAtom(Term t0 USES_REGS) {
240 inp.type = YAP_STRING_STRING | YAP_STRING_CODES | YAP_STRING_ATOMS |
241 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
242 YAP_STRING_BIG | YAP_STRING_TERM;
243 out.type = YAP_STRING_ATOM | YAP_STRING_DOWNCASE;
244 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
245 Yap_ThrowError(LOCAL_Error_TYPE, t0,
"");
249static inline Atom Yap_AtomicToUpAtom(Term t0 USES_REGS) {
252 inp.type = YAP_STRING_STRING | YAP_STRING_CODES | YAP_STRING_ATOMS |
253 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
254 YAP_STRING_BIG | YAP_STRING_TERM;
255 out.type = YAP_STRING_ATOM | YAP_STRING_UPCASE;
256 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
257 Yap_ThrowError(LOCAL_Error_TYPE, t0,
"");
261static inline Term Yap_AtomicToLowString(Term t0 USES_REGS) {
264 inp.type = YAP_STRING_STRING | YAP_STRING_CODES | YAP_STRING_ATOMS |
265 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
266 YAP_STRING_BIG | YAP_STRING_TERM;
267 out.type = YAP_STRING_STRING | YAP_STRING_DOWNCASE;
268 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
269 Yap_ThrowError(LOCAL_Error_TYPE, t0,
"");
273static inline Term Yap_AtomicToUpString(Term t0 USES_REGS) {
276 inp.type = YAP_STRING_STRING | YAP_STRING_CODES | YAP_STRING_ATOMS |
277 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
278 YAP_STRING_BIG | YAP_STRING_TERM;
279 out.type = YAP_STRING_STRING | YAP_STRING_UPCASE;
280 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
281 Yap_ThrowError(LOCAL_Error_TYPE, t0,
"");
285static inline Term Yap_AtomicToLowListOfCodes(Term t0 USES_REGS) {
288 inp.type = YAP_STRING_STRING | YAP_STRING_CODES | YAP_STRING_ATOMS |
289 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
290 YAP_STRING_BIG | YAP_STRING_TERM;
291 out.type = YAP_STRING_CODES | YAP_STRING_DOWNCASE;
292 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
297static inline Term Yap_AtomicToUpListOfCodes(Term t0 USES_REGS) {
300 inp.type = YAP_STRING_STRING | YAP_STRING_CODES | YAP_STRING_ATOMS |
301 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
302 YAP_STRING_BIG | YAP_STRING_TERM;
303 out.type = YAP_STRING_CODES | YAP_STRING_UPCASE;
304 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
309static inline Term Yap_AtomicToLowListOfAtoms(Term t0 USES_REGS) {
312 inp.type = YAP_STRING_STRING | YAP_STRING_CODES | YAP_STRING_ATOMS |
313 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
314 YAP_STRING_BIG | YAP_STRING_TERM;
315 out.type = YAP_STRING_ATOMS | YAP_STRING_DOWNCASE;
316 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
321static inline Term Yap_AtomicToUpListOfAtoms(Term t0 USES_REGS) {
324 inp.type = YAP_STRING_STRING | YAP_STRING_CODES | YAP_STRING_ATOMS |
325 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
326 YAP_STRING_BIG | YAP_STRING_TERM;
327 out.type = YAP_STRING_ATOMS | YAP_STRING_UPCASE;
328 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
333static inline size_t Yap_AtomicToUnicodeLength(Term t0 USES_REGS) {
336 inp.type = YAP_STRING_STRING | YAP_STRING_CODES | YAP_STRING_ATOMS |
337 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
338 YAP_STRING_BIG | YAP_STRING_TERM;
339 out.type = YAP_STRING_CHARS | YAP_STRING_OUTPUT_TERM;
340 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
342 return strlen_utf8(out.val.uc0);
345static inline Term Yap_AtomicToListOfAtoms(Term t0 USES_REGS) {
348 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
349 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
350 out.type = YAP_STRING_ATOMS;
351 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
356static inline Term Yap_AtomicToListOfCodes(Term t0 USES_REGS) {
359 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
360 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
362 out.type = YAP_STRING_CODES;
363 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
368static inline Atom Yap_AtomicToAtom(Term t0 USES_REGS) {
371 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
372 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
374 out.type = YAP_STRING_ATOM;
375 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
380static inline size_t Yap_AtomToLength(Term t0 USES_REGS) {
381 if (!IsAtomTerm(t0)) {
382 return -TYPE_ERROR_ATOM;
384 return strlen(RepAtom(AtomOfTerm(t0))->StrOfAE);
387static inline size_t Yap_AtomToUnicodeLength(Term t0 USES_REGS) {
388 if (!IsAtomTerm(t0)) {
389 return -TYPE_ERROR_ATOM;
391 return strlen_utf8(RepAtom(AtomOfTerm(t0))->UStrOfAE);
394static inline Term Yap_AtomToListOfAtoms(Term t0 USES_REGS) {
397 inp.type = YAP_STRING_ATOM;
399 out.type = YAP_STRING_ATOMS;
400 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
405static inline Term Yap_AtomSWIToListOfAtoms(Term t0 USES_REGS) {
409 inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_INT |
410 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_ATOMS_CODES;
412 out.type = YAP_STRING_ATOMS;
414 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
419static inline Term Yap_AtomToListOfCodes(Term t0 USES_REGS) {
422 inp.type = YAP_STRING_ATOM;
424 out.type = YAP_STRING_CODES;
425 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
430static inline Term Yap_AtomSWIToListOfCodes(Term t0 USES_REGS) {
434 inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_INT |
435 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_ATOMS_CODES | YAP_STRING_ATOMS_CODES | YAP_STRING_ATOMS_CODES |
438 out.type = YAP_STRING_CODES;
440 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
446static inline Term Yap_AtomToNumber(Term t0 USES_REGS) {
449 inp.type = YAP_STRING_ATOM;
451 out.enc = ENC_ISO_UTF8;
452 out.type = YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG;
453 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
458static inline Term Yap_AtomToString(Term t0 USES_REGS) {
462 inp.type = YAP_STRING_ATOM;
464 out.type = YAP_STRING_STRING;
466 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
472static inline Term Yap_AtomSWIToString(Term t0 USES_REGS) {
476 inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_INT |
477 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_ATOMS_CODES ;
479 out.type = YAP_STRING_STRING;
480 out.enc = ENC_ISO_UTF8;
482 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
487static inline Term Yap_AtomicToString(Term t0 USES_REGS) {
491 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
492 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
494 out.type = YAP_STRING_STRING;
496 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
501static inline Term Yap_AtomicToTDQ(Term t0, Term mod USES_REGS) {
505 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
506 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
508 out.type = mod_to_type(mod PASS_REGS);
509 out.enc = ENC_ISO_UTF8;
510 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
515static inline wchar_t *Yap_AtomToWide(
Atom at USES_REGS) {
518 inp.type = YAP_STRING_ATOM;
520 out.type = YAP_STRING_WCHARS;
521 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
526static inline Term Yap_AtomicToTBQ(Term t0, Term mod USES_REGS) {
530 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
531 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
533 out.type = mod_to_bqtype(mod PASS_REGS);
535 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
540static inline Atom Yap_CharsToAtom(
const char *s, encoding_t enc USES_REGS) {
545 inp.type = YAP_STRING_CHARS;
547 out.type = YAP_STRING_ATOM;
548 out.enc = ENC_ISO_UTF8;
549 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
554static inline Term Yap_CharsToListOfAtoms(
const char *s,
555 encoding_t enc USES_REGS) {
560 inp.type = YAP_STRING_CHARS;
562 out.type = YAP_STRING_ATOMS;
563 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
568static inline Term Yap_CharsToListOfCodes(
const char *s,
569 encoding_t enc USES_REGS) {
574 inp.type = YAP_STRING_CHARS;
576 out.type = YAP_STRING_CODES;
577 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
582static inline Term Yap_UTF8ToListOfCodes(
const char *s USES_REGS) {
586 inp.type = YAP_STRING_CHARS;
587 inp.enc = ENC_ISO_UTF8;
588 out.type = YAP_STRING_CODES;
589 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
594static inline Atom Yap_UTF8ToAtom(
const unsigned char *s USES_REGS) {
598 inp.type = YAP_STRING_CHARS;
599 inp.enc = ENC_ISO_UTF8;
600 out.type = YAP_STRING_ATOM;
601 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
606static inline Term Yap_CharsToDiffListOfCodes(
const char *s, Term tail,
607 encoding_t enc USES_REGS) {
612 inp.type = YAP_STRING_CHARS;
614 out.type = YAP_STRING_DIFF | YAP_STRING_CODES;
616 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
621static inline Term Yap_UTF8ToDiffListOfCodes(
const unsigned char *s,
622 Term tail USES_REGS) {
626 inp.type = YAP_STRING_CHARS;
627 inp.enc = ENC_ISO_UTF8;
628 out.type = YAP_STRING_DIFF | YAP_STRING_CODES;
631 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
636static inline Term Yap_WCharsToDiffListOfCodes(
const wchar_t *s,
637 Term tail USES_REGS) {
641 inp.type = YAP_STRING_WCHARS;
642 out.type = YAP_STRING_DIFF | YAP_STRING_CODES;
645 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
651static inline Term Yap_CharsToString(
const char *s, encoding_t enc USES_REGS) {
656 inp.type = YAP_STRING_CHARS;
657 out.type = YAP_STRING_STRING;
659 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
664static inline char *Yap_AtomToUTF8Text(
Atom at USES_REGS) {
665 return RepAtom(at)->StrOfAE;
668static inline Term Yap_CharsToTAQ(
const char *s, Term mod,
669 encoding_t enc USES_REGS) {
673 inp.type = YAP_STRING_CHARS;
676 out.type = mod_to_atype(mod PASS_REGS);
678 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
683static inline Term Yap_CharsToTDQ(
const char *s, Term mod,
684 encoding_t enc USES_REGS) {
688 inp.type = YAP_STRING_CHARS;
691 out.type = mod_to_type(mod PASS_REGS);
693 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
698static inline Term Yap_CharsToTBQ(
const char *s, Term mod,
699 encoding_t enc USES_REGS) {
703 inp.type = YAP_STRING_CHARS;
706 out.type = mod_to_bqtype(mod PASS_REGS);
708 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
713static inline Atom Yap_ListOfAtomsToAtom(Term t0 USES_REGS) {
716 inp.type = YAP_STRING_ATOMS|YAP_STRING_CODES;
717 out.type = YAP_STRING_ATOM;
719 out.enc = ENC_ISO_UTF8;
720 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
725static inline Term Yap_ListOfAtomsToNumber(Term t0 USES_REGS) {
728 inp.type = YAP_STRING_ATOMS|YAP_STRING_CODES;
730 YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
732 out.enc = ENC_ISO_UTF8;
733 if (!Yap_CVT_Text(&inp, &out PASS_REGS) )
738static inline Term Yap_ListOfAtomsToString(Term t0 USES_REGS) {
741 inp.type = YAP_STRING_ATOMS|YAP_STRING_CODES;
742 out.type = YAP_STRING_STRING;
744 out.enc = ENC_ISO_UTF8;
745 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
750static inline Atom Yap_ListOfCodesToAtom(Term t0 USES_REGS) {
753 inp.type = YAP_STRING_CODES|YAP_STRING_ATOMS;
754 out.type = YAP_STRING_ATOM;
756 out.enc = ENC_ISO_UTF8;
757 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
762static inline Term Yap_ListOfCodesToNumber(Term t0 USES_REGS) {
765 inp.type = YAP_STRING_CODES|YAP_STRING_ATOMS;
766 out.type = YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG;
767 out.enc = ENC_ISO_UTF8;
769 if (!Yap_CVT_Text(&inp, &out PASS_REGS) )
774static inline Term Yap_ListOfCodesToString(Term t0 USES_REGS) {
778 inp.type = YAP_STRING_CODES|YAP_STRING_ATOMS;
780 out.type = YAP_STRING_STRING;
781 out.enc = ENC_ISO_UTF8;
782 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
787static inline Atom Yap_ListToAtom(Term t0 USES_REGS) {
790 inp.type = YAP_STRING_ATOMS_CODES|YAP_STRING_ATOM|YAP_STRING_STRING|YAP_STRING_INT|YAP_STRING_FLOAT|YAP_STRING_BIG;
792 out.type = YAP_STRING_ATOM;
793 out.enc = ENC_ISO_UTF8;
794 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
799static inline Term Yap_ListToAtomic(Term t0 USES_REGS) {
802 inp.type = YAP_STRING_STRING | YAP_STRING_ATOMS_CODES | YAP_STRING_TERM;
804 out.enc = ENC_ISO_UTF8;
805 out.type = YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
806 YAP_STRING_BIG | YAP_STRING_OUTPUT_TERM;
807 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
812static inline Term Yap_ListToNumber(Term t0 USES_REGS) {
816 inp.type = YAP_STRING_STRING | YAP_STRING_ATOMS_CODES;
818 out.enc = ENC_ISO_UTF8;
819 out.type = YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG;
821 if (!Yap_CVT_Text(&inp, &out PASS_REGS) )
826static inline Term Yap_ListToString(Term t0 USES_REGS) {
830 inp.type = YAP_STRING_STRING | YAP_STRING_ATOMS_CODES | YAP_STRING_TERM;
832 out.type = YAP_STRING_STRING;
833 out.enc = ENC_ISO_UTF8;
835 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
840static inline Term Yap_ListSWIToString(Term t0 USES_REGS) {
844 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_ATOMS_CODES |
845 YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG |
846 YAP_STRING_OUTPUT_TERM | YAP_STRING_PREFER_LIST;
848 out.type = YAP_STRING_STRING;
849 out.enc = ENC_ISO_UTF8;
851 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
856static inline Term YapListToTDQ(Term t0, Term mod USES_REGS) {
860 inp.type = YAP_STRING_STRING | YAP_STRING_ATOMS_CODES | YAP_STRING_TERM;
862 out.type = mod_to_type(mod PASS_REGS);
863 out.enc = ENC_ISO_UTF8;
865 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
870static inline Term YapListToTBQ(Term t0, Term mod USES_REGS) {
874 inp.type = YAP_STRING_STRING | YAP_STRING_ATOMS_CODES | YAP_STRING_TERM;
876 out.type = mod_to_bqtype(mod PASS_REGS);
877 out.enc = ENC_ISO_UTF8;
879 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
884static inline Atom Yap_NCharsToAtom(
const char *s,
size_t len,
885 encoding_t enc USES_REGS) {
889 inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
891 out.enc = ENC_ISO_UTF8;
892 out.type = YAP_STRING_ATOM;
895 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
900static inline Term Yap_CharsToDiffListOfAtoms(
const char *s, encoding_t enc,
901 Term tail USES_REGS) {
905 inp.type = YAP_STRING_CHARS;
907 out.type = YAP_STRING_ATOMS | YAP_STRING_DIFF;
909 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
914static inline Term Yap_NCharsToListOfCodes(
const char *s,
size_t len,
915 encoding_t enc USES_REGS) {
919 inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
921 out.type = YAP_STRING_CODES;
923 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
928static inline Term Yap_NCharsToString(
const char *s,
size_t len,
929 encoding_t enc USES_REGS) {
934 inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
935 out.type = YAP_STRING_STRING;
937 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
942static inline Term Yap_NCharsToTDQ(
const char *s,
size_t len, encoding_t enc,
943 Term mod USES_REGS) {
947 inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
950 out.type = mod_to_type(mod PASS_REGS);
952 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
957static inline Term Yap_NCharsToTBQ(
const char *s,
size_t len, encoding_t enc,
958 Term mod USES_REGS) {
962 inp.type = YAP_STRING_CHARS | YAP_STRING_NCHARS;
965 out.type = mod_to_bqtype(mod PASS_REGS);
967 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
972static inline Atom Yap_NumberToAtom(Term t0 USES_REGS) {
976 YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
977 out.type = YAP_STRING_ATOM;
978 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
983static inline Term Yap_NumberToListOfAtoms(Term t0 USES_REGS) {
987 YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
988 out.type = YAP_STRING_ATOMS;
989 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
994static inline Term Yap_NumberToListOfCodes(Term t0 USES_REGS) {
998 YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
999 out.type = YAP_STRING_CODES;
1000 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1005static inline Term Yap_NumberToString(Term t0 USES_REGS) {
1009 YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
1010 out.type = YAP_STRING_STRING;
1011 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1016static inline Atom Yap_NWCharsToAtom(
const wchar_t *s,
size_t len USES_REGS) {
1020 inp.type = YAP_STRING_WCHARS | YAP_STRING_NCHARS;
1021 out.type = YAP_STRING_ATOM;
1023 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1024 Yap_ThrowError(LOCAL_Error_TYPE, TermNil,
"");
1028static inline Term Yap_NWCharsToListOfAtoms(
const wchar_t *s,
1029 size_t len USES_REGS) {
1033 inp.type = YAP_STRING_WCHARS | YAP_STRING_NCHARS;
1034 out.type = YAP_STRING_ATOMS;
1036 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1037 Yap_ThrowError(LOCAL_Error_TYPE, TermNil,
"");
1041static inline Term Yap_NWCharsToListOfCodes(
const wchar_t *s,
1042 size_t len USES_REGS) {
1046 inp.type = YAP_STRING_WCHARS | YAP_STRING_NCHARS;
1047 out.type = YAP_STRING_CODES;
1050 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1051 Yap_ThrowError(LOCAL_Error_TYPE, TermNil,
"");
1055static inline Term Yap_NWCharsToString(
const wchar_t *s,
size_t len USES_REGS) {
1059 inp.type = YAP_STRING_WCHARS | YAP_STRING_NCHARS;
1061 out.type = YAP_STRING_STRING;
1063 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1064 Yap_ThrowError(LOCAL_Error_TYPE, TermNil,
"");
1068static inline Atom Yap_StringToAtom(Term t0 USES_REGS) {
1071 inp.type = YAP_STRING_STRING;
1073 out.type = YAP_STRING_ATOM;
1074 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1079static inline Atom Yap_StringSWIToAtom(Term t0 USES_REGS) {
1082 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
1083 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_ATOMS_CODES |
1085 out.type = YAP_STRING_ATOM;
1087 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1088 Yap_ThrowError(LOCAL_Error_TYPE, t0,
"string_to_atom");
1092static inline Term Yap_StringToAtomic(Term t0 USES_REGS) {
1095 inp.type = YAP_STRING_STRING;
1097 YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG;
1099 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1104static inline size_t Yap_StringToUnicodeLength(Term t0 USES_REGS) {
1105 if (!IsStringTerm(t0)) {
1106 return -TYPE_ERROR_STRING;
1108 return strlen_utf8(UStringOfTerm(t0));
1111static inline size_t Yap_StringToListOfAtoms(Term t0 USES_REGS) {
1114 inp.type = YAP_STRING_STRING;
1115 out.type = YAP_STRING_ATOMS;
1117 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1122static inline size_t Yap_StringSWIToListOfAtoms(Term t0 USES_REGS) {
1125 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
1126 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_ATOMS_CODES |
1128 out.type = YAP_STRING_ATOMS;
1130 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1135static inline size_t Yap_StringToListOfCodes(Term t0 USES_REGS) {
1138 inp.type = YAP_STRING_STRING;
1139 out.type = YAP_STRING_CODES;
1141 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1146static inline size_t Yap_StringSWIToListOfCodes(Term t0 USES_REGS) {
1149 inp.type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
1150 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_ATOMS_CODES |
1152 out.type = YAP_STRING_CODES;
1154 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1159static inline Term Yap_StringToNumber(Term t0 USES_REGS) {
1162 inp.type = YAP_STRING_STRING;
1164 YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
1166 out.enc = ENC_ISO_UTF8;
1167 if (!Yap_CVT_Text(&inp, &out PASS_REGS) )
1172static inline Atom Yap_TextToAtom(Term t0 USES_REGS) {
1176 inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_CODES |
1177 YAP_STRING_ATOMS_CODES;
1179 out.type = YAP_STRING_ATOM;
1181 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1186static inline Term Yap_TextToString(Term t0 USES_REGS) {
1190 inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_CODES |
1191 YAP_STRING_ATOMS_CODES;
1193 out.type = YAP_STRING_STRING;
1195 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1200static inline void Yap_OverwriteUTF8BufferToLowCase(
void *buf USES_REGS) {
1201 unsigned char *s = (
unsigned char *)buf;
1204 utf8proc_int32_t chr;
1205 get_utf8(s, -1, &chr);
1206 chr = utf8proc_tolower(chr);
1207 s += put_utf8(s, chr);
1228static inline const char *Yap_TextTermToText(Term t0 USES_REGS) {
1232 inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_CODES |
1233 YAP_STRING_ATOMS_CODES | YAP_STRING_MALLOC;
1235 out.type = YAP_STRING_CHARS| YAP_STRING_MALLOC;
1236 out.enc = ENC_ISO_UTF8;
1238 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1243static inline const unsigned char *Yap_TextToUTF8Buffer(Term t0 USES_REGS) {
1247 inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_CODES |
1248 YAP_STRING_ATOMS_CODES;
1250 out.type = YAP_STRING_CHARS | YAP_STRING_MALLOC;
1251 out.enc = ENC_ISO_UTF8;
1253 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1258static inline Term Yap_UTF8ToString(
const char *s USES_REGS) {
1259 return MkStringTerm(s);
1262static inline Atom UTF32ToAtom(
const wchar_t *s USES_REGS) {
1266 inp.type = YAP_STRING_WCHARS;
1267 out.type = YAP_STRING_ATOM;
1269 if (!Yap_CVT_Text(&inp, &out PASS_REGS)) {
1270 LOCAL_Error_TYPE = (LOCAL_Error_TYPE == TYPE_ERROR_TEXT ? TYPE_ERROR_ATOM : LOCAL_Error_TYPE );
1276static inline Term Yap_WCharsToListOfCodes(
const wchar_t *s USES_REGS) {
1279 inp.type = YAP_STRING_WCHARS;
1281 out.type = YAP_STRING_CODES;
1282 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1283 Yap_ThrowError(LOCAL_Error_TYPE, TermNil,
"");
1287static inline Term Yap_WCharsToTDQ(
wchar_t *s, Term mod USES_REGS) {
1291 inp.type = YAP_STRING_WCHARS;
1294 out.type = mod_to_type(mod PASS_REGS);
1296 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1297 Yap_ThrowError(LOCAL_Error_TYPE, TermNil,
"");
1301static inline Term Yap_WCharsToTBQ(
wchar_t *s, Term mod USES_REGS) {
1305 inp.type = YAP_STRING_WCHARS;
1307 out.type = mod_to_bqtype(mod PASS_REGS);
1309 if (!Yap_CVT_Text(&inp, &out PASS_REGS))
1310 Yap_ThrowError(LOCAL_Error_TYPE, TermNil,
"");
1314static inline Term Yap_WCharsToString(
const wchar_t *s USES_REGS) {
1317 inp.type = YAP_STRING_WCHARS;
1318 out.type = YAP_STRING_STRING;
1320 if (!Yap_CVT_Text(&inp, &out PASS_REGS)) {
1321 LOCAL_Error_TYPE = (LOCAL_Error_TYPE == TYPE_ERROR_TEXT ? TYPE_ERROR_STRING : LOCAL_Error_TYPE );
1322 Yap_ThrowError(LOCAL_Error_TYPE, TermNil,
"");
1327static inline Atom Yap_ConcatAtoms(Term t1, Term t2 USES_REGS) {
1330 inpv[0].type = YAP_STRING_ATOM ;
1332 inpv[1].type = YAP_STRING_ATOM;
1333 out.type = YAP_STRING_ATOM;
1335 if (!Yap_Concat_Text(2, inpv, &out PASS_REGS)) {
1336 LOCAL_Error_TYPE = (LOCAL_Error_TYPE == TYPE_ERROR_TEXT ? TYPE_ERROR_ATOM : LOCAL_Error_TYPE );
1342static inline Atom Yap_ConcatAtomics(Term t1, Term t2 USES_REGS) {
1345 inpv[0].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
1346 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
1348 inpv[1].type = YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
1349 YAP_STRING_FLOAT | YAP_STRING_BIG | YAP_STRING_TERM;
1350 out.type = YAP_STRING_ATOM;
1352 if (!Yap_Concat_Text(2, inpv, &out PASS_REGS))
1357static inline Term Yap_ConcatStrings(Term t1, Term t2 USES_REGS) {
1360 inpv[0].type = YAP_STRING_STRING;
1362 inpv[1].type = YAP_STRING_STRING;
1363 out.type = YAP_STRING_STRING;
1365 if (!Yap_Concat_Text(2, inpv, &out PASS_REGS)){
1366 LOCAL_Error_TYPE = (LOCAL_Error_TYPE == TYPE_ERROR_TEXT ? TYPE_ERROR_STRING : LOCAL_Error_TYPE );
1367 Yap_ThrowError(LOCAL_Error_TYPE, t1,
"");
1372static inline Atom Yap_SpliceAtom(Term t1,
Atom ats[],
size_t cut,
1373 size_t max USES_REGS) {
1378 inp.type = YAP_STRING_ATOM;
1380 outv[0].type = YAP_STRING_ATOM;
1381 outv[1].type = YAP_STRING_ATOM;
1382 if (!Yap_Splice_Text(2, cuts, &inp, outv PASS_REGS)) {
1383 LOCAL_Error_TYPE = (LOCAL_Error_TYPE == TYPE_ERROR_TEXT ? TYPE_ERROR_ATOM : LOCAL_Error_TYPE );
1386 ats[0] = outv[0].val.a;
1387 ats[1] = outv[1].val.a;
1391static inline Atom Yap_SubtractHeadAtom(Term t1, Term th USES_REGS) {
1392 const char *s = RepAtom(AtomOfTerm(t1))->StrOfAE;
1393 const char *sh = RepAtom(AtomOfTerm(th))->StrOfAE;
1394 if (strncmp(s, sh, strlen(sh)) == 0)
1395 return Yap_LookupAtom(s+strlen(sh));
1400static inline Atom Yap_SubtractTailAtom(Term t1, Term th USES_REGS) {
1401 const char *s = RepAtom(AtomOfTerm(t1))->StrOfAE;
1402 const char *sh = RepAtom(AtomOfTerm(th))->StrOfAE;
1403 size_t n = strlen(s);
1404 size_t nh = strlen(sh);
1405 if (strncmp(s+(n-nh) , sh, nh) == 0) {
1406 return Yap_LookupAtomWithLength(s, n-nh);
1411static inline Term Yap_SpliceString(Term t1, Term ts[],
size_t cut,
1412 size_t max USES_REGS) {
1415 inp.type = YAP_STRING_STRING;
1417 outv[0].type = YAP_STRING_STRING;
1418 outv[1].type = YAP_STRING_STRING;
1421 if (!Yap_Splice_Text(2, cuts, &inp, outv PASS_REGS)){
1422 LOCAL_Error_TYPE = (LOCAL_Error_TYPE == TYPE_ERROR_TEXT ? TYPE_ERROR_STRING : LOCAL_Error_TYPE );
1423 Yap_ThrowError(LOCAL_Error_TYPE, t1,
"");
1425 ts[0] = outv[0].val.t;
1426 ts[1] = outv[1].val.t;
1430static inline Term Yap_SubtractHeadString(Term t1, Term th USES_REGS) {
1432 inp.type = YAP_STRING_STRING;
1434 outv[0].type = YAP_STRING_STRING;
1436 outv[1].type = YAP_STRING_STRING;
1438 if (!Yap_Splice_Text(2, (
size_t *)NULL, &inp, outv PASS_REGS)){
1439 LOCAL_Error_TYPE = (LOCAL_Error_TYPE == TYPE_ERROR_TEXT ? TYPE_ERROR_STRING : LOCAL_Error_TYPE );
1440 Yap_ThrowError(LOCAL_Error_TYPE, t1,
"");
1442 return outv[1].val.t;
1445static inline Term Yap_SubtractTailString(Term t1, Term th USES_REGS) {
1447 inp.type = YAP_STRING_STRING;
1449 outv[0].type = YAP_STRING_STRING;
1451 outv[1].type = YAP_STRING_STRING;
1453 if (!Yap_Splice_Text(2, (
size_t *)NULL, &inp, outv PASS_REGS)){
1454 LOCAL_Error_TYPE = (LOCAL_Error_TYPE == TYPE_ERROR_TEXT ? TYPE_ERROR_STRING : LOCAL_Error_TYPE );
1455 Yap_ThrowError(LOCAL_Error_TYPE, t1,
"");
1457 return outv[0].val.t;
uTF-8 codepoint translation and processing
Term Yap_tokRep(void *tokptrXS)
represent token *_tokptr_ in string s, maxlength is sz-1
unsigned int flags
module's owner file
char_kind_t Yap_wide_chtype(int ch)
Term Yap_MkTextTerm(const char *s, int guide USES_REGS)
Convert from a text buffer (8-bit) to a term that has the same type as Tguide