diff --git a/file.c b/file.c index 007a9cb88e..e92ceeabe1 100644 --- a/file.c +++ b/file.c @@ -4001,7 +4001,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na rb_str_set_len(result, p - buf + strlen(p)); encidx = ENCODING_GET(result); tmp = result; - if (encidx != ENCINDEX_UTF_8 && rb_enc_str_coderange(result) != ENC_CODERANGE_7BIT) { + if (encidx != ENCINDEX_UTF_8 && !is_ascii_string(result)) { tmp = rb_str_encode_ospath(result); } len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(tmp), -1, NULL, 0); diff --git a/io.c b/io.c index 170ccc690a..fc1a5d8110 100644 --- a/io.c +++ b/io.c @@ -3836,7 +3836,7 @@ check_getline_args(VALUE *rsp, long *limit, VALUE io) enc_rs = rb_enc_get(rs); enc_io = io_read_encoding(fptr); if (enc_io != enc_rs && - (rb_enc_str_coderange(rs) != ENC_CODERANGE_7BIT || + (!is_ascii_string(rs) || (RSTRING_LEN(rs) > 0 && !rb_enc_asciicompat(enc_io)))) { if (rs == rb_default_rs) { rs = rb_enc_str_new(0, 0, enc_io); diff --git a/marshal.c b/marshal.c index c5327fca60..8267658f5c 100644 --- a/marshal.c +++ b/marshal.c @@ -481,7 +481,7 @@ w_symbol(VALUE sym, struct dump_arg *arg) } encname = encoding_name(sym, arg); if (NIL_P(encname) || - rb_enc_str_coderange(sym) == ENC_CODERANGE_7BIT) { + is_ascii_string(sym)) { encname = Qnil; } else { diff --git a/parse.y b/parse.y index be5af00d43..4183804700 100644 --- a/parse.y +++ b/parse.y @@ -6570,7 +6570,7 @@ parser_str_new(const char *ptr, long len, rb_encoding *enc, int func, rb_encodin str = rb_enc_str_new(ptr, len, enc); if (!(func & STR_FUNC_REGEXP) && rb_enc_asciicompat(enc)) { - if (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) { + if (is_ascii_string(str)) { } else if (enc0 == rb_usascii_encoding() && enc != rb_utf8_encoding()) { rb_enc_associate(str, rb_ascii8bit_encoding()); @@ -12939,21 +12939,21 @@ rb_reg_fragment_setenc(struct parser_params* p, VALUE str, int options) int opt, idx; rb_char_to_option_kcode(c, &opt, &idx); if (idx != ENCODING_GET(str) && - rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) { + !is_ascii_string(str)) { goto error; } ENCODING_SET(str, idx); } else if (RE_OPTION_ENCODING_NONE(options)) { if (!ENCODING_IS_ASCII8BIT(str) && - rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) { + !is_ascii_string(str)) { c = 'n'; goto error; } rb_enc_associate(str, rb_ascii8bit_encoding()); } else if (p->enc == rb_usascii_encoding()) { - if (rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) { + if (!is_ascii_string(str)) { /* raise in re.c */ rb_enc_associate(str, rb_usascii_encoding()); } diff --git a/string.c b/string.c index e06e7745a6..23c651618d 100644 --- a/string.c +++ b/string.c @@ -856,7 +856,7 @@ rb_enc_str_asciionly_p(VALUE str) if (!rb_enc_asciicompat(enc)) return FALSE; - else if (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) + else if (is_ascii_string(str)) return TRUE; return FALSE; } @@ -1276,7 +1276,7 @@ rb_external_str_with_enc(VALUE str, rb_encoding *eenc) { int eidx = rb_enc_to_index(eenc); if (eidx == rb_usascii_encindex() && - rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) { + !is_ascii_string(str)) { rb_enc_associate_index(str, rb_ascii8bit_encindex()); return str; } @@ -3521,7 +3521,7 @@ st_index_t rb_str_hash(VALUE str) { int e = ENCODING_GET(str); - if (e && rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) { + if (e && is_ascii_string(str)) { e = 0; } return rb_memhash((const void *)RSTRING_PTR(str), RSTRING_LEN(str)) ^ e; diff --git a/transcode.c b/transcode.c index 7a080875d6..e6e585e901 100644 --- a/transcode.c +++ b/transcode.c @@ -2721,7 +2721,7 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts) return NIL_P(arg2) ? -1 : dencidx; } if (senc && denc && rb_enc_asciicompat(senc) && rb_enc_asciicompat(denc)) { - if (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) { + if (is_ascii_string(str)) { return dencidx; } }