|
26 | 26 | # define RB_INTEGER_TYPE_P(c) (FIXNUM_P(c) || RB_TYPE_P(c, T_BIGNUM))
|
27 | 27 | #endif
|
28 | 28 |
|
| 29 | +#ifndef HAVE_RB_IO_EXTRACT_MODEENC |
| 30 | +#define rb_io_extract_modeenc strio_extract_modeenc |
| 31 | +static void |
| 32 | +strio_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, |
| 33 | + int *oflags_p, int *fmode_p, struct rb_io_enc_t *convconfig_p) |
| 34 | +{ |
| 35 | + VALUE mode = *vmode_p; |
| 36 | + int fmode; |
| 37 | + |
| 38 | + convconfig_p->enc = convconfig_p->enc2 = 0; |
| 39 | + if (NIL_P(mode)) { |
| 40 | + fmode = FMODE_READABLE; |
| 41 | + } |
| 42 | + else if (FIXNUM_P(mode)) { |
| 43 | + int flags = FIX2INT(mode); |
| 44 | + fmode = rb_io_oflags_fmode(flags); |
| 45 | + } |
| 46 | + else { |
| 47 | + const char *m = StringValueCStr(mode), *n, *e; |
| 48 | + fmode = rb_io_modestr_fmode(m); |
| 49 | + n = strchr(m, ':'); |
| 50 | + if (n) { |
| 51 | + long len; |
| 52 | + char encname[ENCODING_MAXNAMELEN+1]; |
| 53 | + if (fmode & FMODE_SETENC_BY_BOM) { |
| 54 | + n = strchr(n, '|'); |
| 55 | + } |
| 56 | + e = strchr(++n, ':'); |
| 57 | + len = e ? e - n : strlen(n); |
| 58 | + if (len > 0 && len <= ENCODING_MAXNAMELEN) { |
| 59 | + if (e) { |
| 60 | + memcpy(encname, n, len); |
| 61 | + encname[len] = '\0'; |
| 62 | + n = encname; |
| 63 | + } |
| 64 | + convconfig_p->enc = rb_enc_find(n); |
| 65 | + } |
| 66 | + if (e && (len = strlen(++e)) > 0 && len <= ENCODING_MAXNAMELEN) { |
| 67 | + convconfig_p->enc2 = rb_enc_find(e); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + if (!NIL_P(opthash)) { |
| 73 | + rb_encoding *extenc = 0, *intenc = 0; |
| 74 | + if (rb_io_extract_encoding_option(opthash, &extenc, &intenc, &fmode)) { |
| 75 | + if (convconfig_p->enc || convconfig_p->enc2) { |
| 76 | + rb_raise(rb_eArgError, "encoding specified twice"); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + *fmode_p = fmode; |
| 81 | +} |
| 82 | +#endif |
| 83 | + |
29 | 84 | struct StringIO {
|
30 | 85 | VALUE string;
|
31 | 86 | rb_encoding *enc;
|
|
0 commit comments