mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
hash.c: env_str_transcode
* hash.c (env_str_transcode): convert with replacing invalid/undef characters, on Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4f7449beba
commit
c5255bdd03
1 changed files with 11 additions and 6 deletions
17
hash.c
17
hash.c
|
@ -2500,13 +2500,20 @@ extern char **environ;
|
|||
#define ENVNMATCH(s1, s2, n) (memcmp((s1), (s2), (n)) == 0)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
static VALUE
|
||||
env_str_transcode(VALUE str, rb_encoding *enc)
|
||||
{
|
||||
return rb_str_conv_enc_opts(str, rb_utf8_encoding(), enc,
|
||||
ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE, Qnil);
|
||||
}
|
||||
#endif
|
||||
|
||||
static VALUE
|
||||
env_str_new(const char *ptr, long len)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
VALUE str = rb_str_conv_enc_opts(rb_str_new(ptr, len),
|
||||
rb_utf8_encoding(), rb_locale_encoding(),
|
||||
ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE, Qnil);
|
||||
VALUE str = env_str_transcode(rb_str_new(ptr, len), rb_locale_encoding());
|
||||
#else
|
||||
VALUE str = rb_locale_str_new(ptr, len);
|
||||
#endif
|
||||
|
@ -2519,9 +2526,7 @@ static VALUE
|
|||
env_path_str_new(const char *ptr)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
VALUE str = rb_str_conv_enc_opts(rb_str_new_cstr(ptr),
|
||||
rb_utf8_encoding(), rb_filesystem_encoding(),
|
||||
ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE, Qnil);
|
||||
VALUE str = env_str_transcode(rb_str_new_cstr(ptr), rb_filesystem_encoding());
|
||||
#else
|
||||
VALUE str = rb_filesystem_str_new_cstr(ptr);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue