Skip to content

Commit

Permalink
Using is_ascii_string to check encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
S-H-GAMELINKS authored and nobu committed Jun 17, 2022
1 parent 51a3ebf commit 420f3ce
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
Expand Down
6 changes: 3 additions & 3 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion transcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 420f3ce

Please sign in to comment.