@@ -41,18 +41,27 @@ enum ruby_encoding_consts {
41
41
#define ENCODING_SHIFT RUBY_ENCODING_SHIFT
42
42
#define ENCODING_MASK RUBY_ENCODING_MASK
43
43
44
+ #ifdef TRUFFLERUBY
45
+ #define RB_ENCODING_SET_INLINED (obj ,i ) RB_ENCODING_SET(obj,i)
46
+ #else
44
47
#define RB_ENCODING_SET_INLINED (obj ,i ) do {\
45
48
RBASIC(obj)->flags &= ~RUBY_ENCODING_MASK;\
46
49
RBASIC(obj)->flags |= (VALUE)(i) << RUBY_ENCODING_SHIFT;\
47
50
} while (0)
51
+ #endif
48
52
#define RB_ENCODING_SET (obj ,i ) rb_enc_set_index((obj), (i))
49
53
54
+ #ifdef TRUFFLERUBY
55
+ #define RB_ENCODING_GET_INLINED (obj ) RB_ENCODING_GET(obj)
56
+ #define RB_ENCODING_GET (obj ) rb_enc_get_index(obj)
57
+ #else
50
58
#define RB_ENCODING_GET_INLINED (obj ) \
51
59
(int)((RBASIC(obj)->flags & RUBY_ENCODING_MASK)>>RUBY_ENCODING_SHIFT)
52
60
#define RB_ENCODING_GET (obj ) \
53
61
(RB_ENCODING_GET_INLINED(obj) != RUBY_ENCODING_INLINE_MAX ? \
54
62
RB_ENCODING_GET_INLINED(obj) : \
55
63
rb_enc_get_index(obj))
64
+ #endif
56
65
57
66
#define RB_ENCODING_IS_ASCII8BIT (obj ) (RB_ENCODING_GET_INLINED(obj) == 0)
58
67
@@ -65,12 +74,18 @@ enum ruby_encoding_consts {
65
74
66
75
enum ruby_coderange_type {
67
76
RUBY_ENC_CODERANGE_UNKNOWN = 0 ,
77
+ #ifdef TRUFFLERUBY
78
+ RUBY_ENC_CODERANGE_7BIT = 1 ,
79
+ RUBY_ENC_CODERANGE_VALID = 2 ,
80
+ RUBY_ENC_CODERANGE_BROKEN = 4
81
+ #else
68
82
RUBY_ENC_CODERANGE_7BIT = ((int )RUBY_FL_USER8 ),
69
83
RUBY_ENC_CODERANGE_VALID = ((int )RUBY_FL_USER9 ),
70
84
RUBY_ENC_CODERANGE_BROKEN = ((int )(RUBY_FL_USER8 |RUBY_FL_USER9 )),
71
85
RUBY_ENC_CODERANGE_MASK = (RUBY_ENC_CODERANGE_7BIT |
72
86
RUBY_ENC_CODERANGE_VALID |
73
87
RUBY_ENC_CODERANGE_BROKEN )
88
+ #endif
74
89
};
75
90
76
91
static inline int
@@ -79,12 +94,23 @@ rb_enc_coderange_clean_p(int cr)
79
94
return (cr ^ (cr >> 1 )) & RUBY_ENC_CODERANGE_7BIT ;
80
95
}
81
96
#define RB_ENC_CODERANGE_CLEAN_P (cr ) rb_enc_coderange_clean_p(cr)
97
+ #ifdef TRUFFLERUBY
98
+ enum ruby_coderange_type RB_ENC_CODERANGE (VALUE obj );
99
+ #else
82
100
#define RB_ENC_CODERANGE (obj ) ((int)RBASIC(obj)->flags & RUBY_ENC_CODERANGE_MASK)
101
+ #endif
83
102
#define RB_ENC_CODERANGE_ASCIIONLY (obj ) (RB_ENC_CODERANGE(obj) == RUBY_ENC_CODERANGE_7BIT)
103
+
104
+ #ifdef TRUFFLERUBY
105
+ void RB_ENC_CODERANGE_SET (VALUE obj , int cr );
106
+ void rb_enc_coderange_clear (VALUE );
107
+ #define RB_ENC_CODERANGE_CLEAR (obj ) rb_enc_coderange_clear(obj)
108
+ #else
84
109
#define RB_ENC_CODERANGE_SET (obj ,cr ) (\
85
110
RBASIC(obj)->flags = \
86
111
(RBASIC(obj)->flags & ~RUBY_ENC_CODERANGE_MASK) | (cr))
87
112
#define RB_ENC_CODERANGE_CLEAR (obj ) RB_ENC_CODERANGE_SET((obj),0)
113
+ #endif
88
114
89
115
/* assumed ASCII compatibility */
90
116
#define RB_ENC_CODERANGE_AND (a , b ) \
@@ -147,6 +173,9 @@ VALUE rb_obj_encoding(VALUE);
147
173
VALUE rb_enc_str_buf_cat (VALUE str , const char * ptr , long len , rb_encoding * enc );
148
174
VALUE rb_enc_uint_chr (unsigned int code , rb_encoding * enc );
149
175
176
+ VALUE rb_external_str_with_enc (VALUE string , rb_encoding * eenc );
177
+ rb_encoding * get_encoding (VALUE string );
178
+ #define STR_ENC_GET (string ) get_encoding(string)
150
179
VALUE rb_external_str_new_with_enc (const char * ptr , long len , rb_encoding * );
151
180
VALUE rb_str_export_to_enc (VALUE , rb_encoding * );
152
181
VALUE rb_str_conv_enc (VALUE str , rb_encoding * from , rb_encoding * to );
@@ -177,8 +206,13 @@ rb_encoding *rb_enc_find(const char *name);
177
206
#define rb_enc_name (enc ) (enc)->name
178
207
179
208
/* rb_encoding * -> minlen/maxlen */
209
+ #ifdef TRUFFLERUBY
210
+ int rb_enc_mbminlen (rb_encoding * enc );
211
+ int rb_enc_mbmaxlen (rb_encoding * enc );
212
+ #else
180
213
#define rb_enc_mbminlen (enc ) (enc)->min_enc_len
181
214
#define rb_enc_mbmaxlen (enc ) (enc)->max_enc_len
215
+ #endif
182
216
183
217
/* -> mbclen (no error notification: 0 < ret <= e-p, no exception) */
184
218
int rb_enc_mbclen (const char * p , const char * e , rb_encoding * enc );
@@ -205,7 +239,12 @@ unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_enc
205
239
unsigned int rb_enc_codepoint (const char * p , const char * e , rb_encoding * enc );
206
240
/* overriding macro */
207
241
#define rb_enc_codepoint (p ,e ,enc ) rb_enc_codepoint_len((p),(e),0,(enc))
242
+ #ifdef TRUFFLERUBY
243
+ int rb_enc_mbc_to_codepoint (char * p , char * e , rb_encoding * enc );
244
+ #define rb_enc_mbc_to_codepoint (p , e , enc ) rb_enc_mbc_to_codepoint(p, e, enc)
245
+ #else
208
246
#define rb_enc_mbc_to_codepoint (p , e , enc ) ONIGENC_MBC_TO_CODE((enc),(UChar*)(p),(UChar*)(e))
247
+ #endif
209
248
210
249
/* -> codelen>0 or raise exception */
211
250
int rb_enc_codelen (int code , rb_encoding * enc );
@@ -219,7 +258,11 @@ int rb_enc_code_to_mbclen(int code, rb_encoding *enc);
219
258
/* start, ptr, end, encoding -> prev_char */
220
259
#define rb_enc_prev_char (s ,p ,e ,enc ) ((char *)onigenc_get_prev_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
221
260
/* start, ptr, end, encoding -> next_char */
261
+ #ifdef TRUFFLERUBY
262
+ char * rb_enc_left_char_head (char * start , char * p , char * end , rb_encoding * enc );
263
+ #else
222
264
#define rb_enc_left_char_head (s ,p ,e ,enc ) ((char *)onigenc_get_left_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
265
+ #endif
223
266
#define rb_enc_right_char_head (s ,p ,e ,enc ) ((char *)onigenc_get_right_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
224
267
#define rb_enc_step_back (s ,p ,e ,n ,enc ) ((char *)onigenc_step_back((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e),(int)(n)))
225
268
@@ -232,17 +275,31 @@ int rb_enc_code_to_mbclen(int code, rb_encoding *enc);
232
275
#define rb_enc_islower (c ,enc ) ONIGENC_IS_CODE_LOWER((enc),(c))
233
276
#define rb_enc_isupper (c ,enc ) ONIGENC_IS_CODE_UPPER((enc),(c))
234
277
#define rb_enc_ispunct (c ,enc ) ONIGENC_IS_CODE_PUNCT((enc),(c))
278
+ #ifdef TRUFFLERUBY
279
+ int rb_enc_isalnum (unsigned char c , rb_encoding * enc );
280
+ #define rb_enc_isalnum (c ,enc ) rb_enc_isalnum(c,enc)
281
+ #else
235
282
#define rb_enc_isalnum (c ,enc ) ONIGENC_IS_CODE_ALNUM((enc),(c))
283
+ #endif
236
284
#define rb_enc_isprint (c ,enc ) ONIGENC_IS_CODE_PRINT((enc),(c))
285
+ #ifdef TRUFFLERUBY
286
+ int rb_enc_isspace (unsigned char c , rb_encoding * enc );
287
+ #define rb_enc_isspace (c ,enc ) rb_enc_isspace(c,enc)
288
+ #else
237
289
#define rb_enc_isspace (c ,enc ) ONIGENC_IS_CODE_SPACE((enc),(c))
290
+ #endif
238
291
#define rb_enc_isdigit (c ,enc ) ONIGENC_IS_CODE_DIGIT((enc),(c))
239
292
293
+ #ifdef TRUFFLERUBY
294
+ int rb_enc_asciicompat (rb_encoding * enc );
295
+ #else
240
296
static inline int
241
297
rb_enc_asciicompat_inline (rb_encoding * enc )
242
298
{
243
299
return rb_enc_mbminlen (enc )== 1 && !rb_enc_dummy_p (enc );
244
300
}
245
301
#define rb_enc_asciicompat (enc ) rb_enc_asciicompat_inline(enc)
302
+ #endif
246
303
247
304
int rb_enc_casefold (char * to , const char * p , const char * e , rb_encoding * enc );
248
305
CONSTFUNC (int rb_enc_toupper (int c , rb_encoding * enc ));
@@ -293,6 +350,9 @@ VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc);
293
350
RUBY_EXTERN VALUE rb_cEncoding ;
294
351
295
352
/* econv stuff */
353
+ #ifdef TRUFFLERUBY
354
+ struct rb_econv_t {};
355
+ #endif
296
356
297
357
typedef enum {
298
358
econv_invalid_byte_sequence ,
0 commit comments