diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-06-26 14:15:22 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2017-06-26 15:23:03 +0900 |
commit | 4376437c378e6a9f8a64cfa095dcedae1542cb4b (patch) | |
tree | 7377ece6ccde43a82d19c22ca0c990bc733c59f0 | |
parent | 47c5f0cc3285fd4d6e95cad0f72c8491a101c275 (diff) | |
download | ruby-4376437c378e6a9f8a64cfa095dcedae1542cb4b.tar.gz |
string.c: preserve coderange in rb_str_drop_bytes()
It is currently always clears the coderange.
-rw-r--r-- | string.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -4434,7 +4434,14 @@ rb_str_drop_bytes(VALUE str, long len) RSTRING(str)->as.heap.len = nlen; } ptr[nlen] = 0; - ENC_CODERANGE_CLEAR(str); + if (ENC_CODERANGE(str) == ENC_CODERANGE_VALID) { + int n = rb_enc_precise_mbclen(ptr, ptr + nlen, STR_ENC_GET(str)); + if (!MBCLEN_CHARFOUND_P(n)) + ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN); + } + else if (ENC_CODERANGE(str) == ENC_CODERANGE_BROKEN) { + ENC_CODERANGE_CLEAR(str); + } return str; } |