summaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authordavidflanagan <davidflanagan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-10 05:45:52 +0000
committerdavidflanagan <davidflanagan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-10 05:45:52 +0000
commitc993ee03277b8faae1be8466a827cd48102c52e9 (patch)
tree2d08cab9fdbe0390b283d98877b2bd424a793695 /parse.y
parentb6d03352faf804a1acb491565a38afac770d5ddc (diff)
downloadruby-c993ee03277b8faae1be8466a827cd48102c52e9.tar.gz
ruby-c993ee03277b8faae1be8466a827cd48102c52e9.tar.xz
ruby-c993ee03277b8faae1be8466a827cd48102c52e9.zip
* parse.y: use ASCII encoding for string literals that are
7-bit clean, fixing regression from my previous patch git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@13860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y14
1 files changed, 14 insertions, 0 deletions
diff --git a/parse.y b/parse.y
index 1d4598c3d..8284603c0 100644
--- a/parse.y
+++ b/parse.y
@@ -4842,9 +4842,23 @@ parser_str_new(const char *p, long n, rb_encoding *enc, int coderange)
static VALUE
parser_str_new2(const char *p, long n, rb_encoding *enc, int has8bit,int hasmb)
{
+ /*
+ * Set coderange bit flags based on the presence of 8-bit and
+ * multi-byte characters in the string
+ */
int coderange = ENC_CODERANGE_SINGLE;
if (hasmb) coderange = ENC_CODERANGE_MULTI;
else if (has8bit) coderange = ENC_CODERANGE_UNKNOWN;
+
+ /*
+ * If it is all single byte characters with the 8th bit clear,
+ * and if the specified encoding is ASCII-compatible, then this
+ * string is in the ASCII subset, and we just use the ASCII encoding
+ * instead.
+ */
+ if ((coderange == ENC_CODERANGE_SINGLE) && rb_enc_asciicompat(enc))
+ enc = rb_enc_default();
+
return parser_str_new(p, n, enc, coderange);
}