From b2e60b2ce7a7cbcb8a67ac78606a18d3c2591d81 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 25 Nov 2007 13:25:34 +0000 Subject: * include/ruby/encoding.h (rb_enc_str_asciionly_p): declared. (rb_enc_str_asciicompat_p): defined. * re.c (rb_reg_initialize_str): use rb_enc_str_asciionly_p. (rb_reg_quote): return ascii-8bit string if the argument is ascii-only to generate encoding generic regexp if possible. (rb_reg_s_union): fix encoding handling. [ruby-dev:32094] * string.c (rb_enc_str_asciionly_p): defined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'string.c') diff --git a/string.c b/string.c index 286c56a93a..20ce81963c 100644 --- a/string.c +++ b/string.c @@ -129,6 +129,23 @@ rb_enc_str_coderange(VALUE str) return cr; } +int rb_enc_str_asciionly_p(VALUE str) +{ + rb_encoding *enc = rb_enc_get(str); + + if (rb_enc_asciicompat(enc) && + rb_enc_str_coderange(str) == ENC_CODERANGE_SINGLE) { + char *ptr = RSTRING_PTR(str); + long len = RSTRING_LEN(str); + long i; + for (i = 0; i < len; i++) + if (ptr[i] & 0x80) + return Qfalse; + return Qtrue; + } + return Qfalse; +} + static inline void str_mod_check(VALUE s, char *p, long len) { -- cgit v1.2.3