2008-12-22 12:02:22 +00:00
|
|
|
/* $Id$
|
|
|
|
|
|
|
|
Part of SWI-Prolog
|
|
|
|
|
|
|
|
Author: Jan Wielemaker and Anjo Anjewierden
|
|
|
|
E-mail: jan@swi.psy.uva.nl
|
|
|
|
WWW: http://www.swi-prolog.org
|
|
|
|
Copyright (C): 1985-2002, University of Amsterdam
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
2013-01-19 14:19:01 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-12-22 12:02:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PL_TEXT_H_INCLUDED
|
|
|
|
#define PL_TEXT_H_INCLUDED
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{ PL_CHARS_MALLOC, /* malloced data */
|
|
|
|
PL_CHARS_RING, /* stored in the buffer ring */
|
|
|
|
PL_CHARS_HEAP, /* stored in program area (atoms) */
|
|
|
|
PL_CHARS_STACK, /* stored on the global stack */
|
|
|
|
PL_CHARS_LOCAL /* stored in in-line buffer */
|
|
|
|
} PL_chars_alloc_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{ union
|
|
|
|
{ char *t; /* tranditional 8-bit char* */
|
|
|
|
pl_wchar_t *w; /* wide character string */
|
|
|
|
} text;
|
|
|
|
size_t length;
|
|
|
|
/* private stuff */
|
|
|
|
IOENC encoding; /* how it is encoded */
|
|
|
|
PL_chars_alloc_t storage; /* how it is stored */
|
|
|
|
int canonical; /* TRUE: ENC_ISO_LATIN_1 or ENC_WCHAR */
|
|
|
|
char buf[100]; /* buffer for simple stuff */
|
|
|
|
} PL_chars_t;
|
|
|
|
|
|
|
|
#define PL_init_text(txt) \
|
|
|
|
{ (txt)->text.t = NULL; \
|
|
|
|
(txt)->encoding = ENC_UNKNOWN; \
|
|
|
|
(txt)->storage = PL_CHARS_LOCAL; \
|
|
|
|
(txt)->canonical = FALSE; \
|
|
|
|
}
|
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
int PL_unify_text(term_t term, term_t tail, PL_chars_t *text, int type);
|
|
|
|
int PL_unify_text_range(term_t term, PL_chars_t *text,
|
2008-12-22 12:02:22 +00:00
|
|
|
size_t from, size_t len, int type);
|
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
int PL_promote_text(PL_chars_t *text);
|
|
|
|
int PL_demote_text(PL_chars_t *text);
|
|
|
|
int PL_mb_text(PL_chars_t *text, int flags);
|
|
|
|
int PL_canonise_text(PL_chars_t *text);
|
2008-12-22 12:02:22 +00:00
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
int PL_cmp_text(PL_chars_t *t1, size_t o1, PL_chars_t *t2, size_t o2,
|
2008-12-22 12:02:22 +00:00
|
|
|
size_t len);
|
2011-02-10 00:01:19 +00:00
|
|
|
int PL_concat_text(int n, PL_chars_t **text, PL_chars_t *result);
|
2008-12-22 12:02:22 +00:00
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
void PL_free_text(PL_chars_t *text);
|
|
|
|
void PL_save_text(PL_chars_t *text, int flags);
|
2008-12-22 12:02:22 +00:00
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
COMMON(int) PL_get_text__LD(term_t l, PL_chars_t *text, int flags ARG_LD);
|
2015-02-13 12:20:46 +00:00
|
|
|
COMMON(Atom) textToAtom(PL_chars_t *text);
|
2008-12-22 12:02:22 +00:00
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
COMMON(IOSTREAM *) Sopen_text(PL_chars_t *text, const char *mode);
|
|
|
|
COMMON(void) PL_text_recode(PL_chars_t *text, IOENC encoding);
|
2008-12-22 12:02:22 +00:00
|
|
|
|
2011-02-10 00:01:19 +00:00
|
|
|
/* pl-fli.c */
|
|
|
|
COMMON(int) get_atom_ptr_text(Atom atom, PL_chars_t *text);
|
|
|
|
COMMON(int) get_atom_text(atom_t atom, PL_chars_t *text);
|
|
|
|
COMMON(int) get_string_text(atom_t atom, PL_chars_t *text ARG_LD);
|
2008-12-22 12:02:22 +00:00
|
|
|
|
2013-11-15 01:10:25 +00:00
|
|
|
static inline int
|
|
|
|
text_get_char(const PL_chars_t *t, size_t i)
|
|
|
|
{ assert(t->canonical);
|
|
|
|
return t->encoding == ENC_ISO_LATIN_1 ? t->text.t[i]&0xff
|
|
|
|
: t->text.w[i];
|
|
|
|
}
|
|
|
|
|
2008-12-22 12:02:22 +00:00
|
|
|
#endif /*PL_TEXT_H_INCLUDED*/
|