Add `__ENCODING__' support.

`__ENCODING__' returns the current encoding name (string), unlike
CRuby that returns the encoding object.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2017-08-28 22:42:06 +09:00
parent f1fa5bf1c6
commit 1260d3b68a
+9
View File
@@ -2968,6 +2968,15 @@ var_ref : variable
snprintf(buf, sizeof(buf), "%d", p->lineno);
$$ = new_int(p, buf, 10);
}
| keyword__ENCODING__
{
#ifdef MRB_UTF8_STRING
const char *enc = "UTF-8";
#else
const char *enc = "ASCII-8BIT";
#endif
$$ = new_str(p, enc, strlen(enc));
}
;
backref : tNTH_REF