23#include "YapIOConfig.h"
28typedef enum YAP_encoding {
36 ENC_ISO_UTF32_BE = 64,
37 ENC_ISO_UTF32_LE = 128,
43#define ENC_WCHAR ENC_ISO_UTF32_BE
45#define ENC_WCHAR ENC_ISO_UTF32_LE
51encoding_t Yap_DefaultEncoding(
void);
52encoding_t Yap_SystemEncoding(
void);
53void Yap_SetDefaultEncoding(encoding_t new_encoding);
69static inline seq_encoding_t seq_encoding(encoding_t inp) {
70#if HAVE__BUILTIN_FFSLL
71 return __builtin_ffsll(inp);
80 if (inp & ((CELL)0xffL << 8)) {
84 if (inp & ((CELL)0xfL << 4)) {
88 if (inp & ((CELL)0x3L << 2)) {
92 if (inp & ((CELL)0x1 << 1))
98extern xlocale enc_locales[SEQ_ENC_ISO_UTF32_LE + 1];
101static inline const char *enc_name(encoding_t enc) {
106 return "iso_latin_1";
121 case ENC_ISO_UTF32_BE:
123 case ENC_ISO_UTF32_LE:
126 return "thanks for watching!!";
130static inline encoding_t enc_id(
const char *s, encoding_t enc_bom) {
135 if (!strcmp(s,
"default")) {
136 if (enc_bom != ENC_OCTET)
138 return Yap_DefaultEncoding();
140 return Yap_DefaultEncoding();
145 if (!strcmp(s,
"iso_utf8"))
147 if (!strcmp(s,
"iso_latin_1"))
148 return ENC_ISO_LATIN1;
149 if (!strcmp(s,
"iso_ascii"))
150 return ENC_ISO_ASCII;
151 if (!strcmp(s,
"iso_ansi"))
156 if (!strcmp(s,
"ISO-8859-1"))
157 return ENC_ISO_LATIN1;
161 if (!strcmp(s,
"octet"))
166 if (!strcmp(s,
"utf8"))
168 if (!strcmp(s,
"utf16_le"))
170 if (!strcmp(s,
"utf16_be"))
172 if (!strcmp(s,
"utf32_be"))
173 return ENC_ISO_UTF32_BE;
174 if (!strcmp(s,
"utf32_le"))
175 return ENC_ISO_UTF32_LE;
176 if (!strcmp(s,
"unicode_be"))
178 if (!strcmp(s,
"unicode_le"))
183 if (!strcmp(s,
"UTF-8"))
185 if (!strcmp(s,
"UTF-16")) {
186 if (enc_bom == ENC_UTF16_LE)
190 if (!strcmp(s,
"UTF-16LE"))
192 if (!strcmp(s,
"UTF-16BE"))
194 if (!strcmp(s,
"UTF-32BE"))
195 return ENC_ISO_UTF32_BE;
196 if (!strcmp(s,
"UTF-32LE"))
197 return ENC_ISO_UTF32_LE;
198 if (!strcmp(s,
"US_ASCII"))
199 return ENC_ISO_ASCII;
200 if (!strcmp(s,
"UTF-32")) {
201 if (enc_bom == ENC_ISO_UTF32_LE)
202 return ENC_ISO_UTF32_LE;
203 return ENC_ISO_UTF32_BE;
208 if (!strcmp(s,
"UCS-2")) {
209 if (enc_bom == ENC_UTF16_LE)
213 if (!strcmp(s,
"UCS-2LE"))
215 if (!strcmp(s,
"UCS-2BE"))