summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-15 06:06:19 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-15 06:06:19 (GMT)
commit2046f38aa6e2a28aea582ba84887ccef6fdd31d6 (patch)
tree904c6cbec6a4748e1c82995afc3833108304920c /dir.c
parent9c9d555e7f93ef232b42b3e8528df0ce5ac4faa3 (diff)
dir.c: fundamental_encoding_p
* dir.c (fundamental_encoding_p, push_glob): compare by encoding index immediately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/dir.c b/dir.c
index abb5295..aed3ecaa 100644
--- a/dir.c
+++ b/dir.c
@@ -12,6 +12,7 @@
**********************************************************************/
#include "internal.h"
+#include "encindex.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -670,6 +671,18 @@ dir_path(VALUE dir)
}
#if defined _WIN32
+static int
+fundamental_encoding_p(rb_encoding *enc)
+{
+ switch (rb_enc_to_index(enc)) {
+ case ENCINDEX_ASCII:
+ case ENCINDEX_US_ASCII:
+ case ENCINDEX_UTF_8:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
# define READDIR(dir, enc) rb_w32_readdir((dir), (enc))
#else
# define READDIR(dir, enc) readdir((dir))
@@ -1212,9 +1225,7 @@ do_opendir(const char *path, int flags, rb_encoding *enc)
DIR *dirp;
#ifdef _WIN32
VALUE tmp = 0;
- if (enc != rb_usascii_encoding() &&
- enc != rb_ascii8bit_encoding() &&
- enc != rb_utf8_encoding()) {
+ if (!fundamental_encoding_p(enc)) {
tmp = rb_enc_str_new(path, strlen(path), enc);
tmp = rb_str_encode_ospath(tmp);
path = RSTRING_PTR(tmp);
@@ -1525,10 +1536,7 @@ replace_real_basename(char *path, long base, rb_encoding *enc, int norm_p, int f
HANDLE h = INVALID_HANDLE_VALUE;
long wlen;
int e = 0;
- if (enc &&
- enc != rb_usascii_encoding() &&
- enc != rb_ascii8bit_encoding() &&
- enc != rb_utf8_encoding()) {
+ if (!fundamental_encoding_p(enc)) {
tmp = rb_enc_str_new_cstr(plainname, enc);
tmp = rb_str_encode_ospath(tmp);
plainname = RSTRING_PTR(tmp);
@@ -2119,8 +2127,10 @@ push_glob(VALUE ary, VALUE str, int flags)
#ifdef __APPLE__
str = rb_str_encode_ospath(str);
#endif
- if (enc == rb_usascii_encoding()) enc = rb_filesystem_encoding();
- if (enc == rb_usascii_encoding()) enc = rb_ascii8bit_encoding();
+ if (rb_enc_to_index(enc) == ENCINDEX_US_ASCII)
+ enc = rb_filesystem_encoding();
+ if (rb_enc_to_index(enc) == ENCINDEX_US_ASCII)
+ enc = rb_ascii8bit_encoding();
flags |= GLOB_VERBOSE;
args.glob.func = push_pattern;
args.glob.value = ary;