1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

file.c: normalize Form C

* file.c (rb_str_normalize_ospath): normalize to Normalization Form C
  using CFString.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-08-09 03:06:53 +00:00
parent f9cbf0e89f
commit c04f402f0f
4 changed files with 31 additions and 6 deletions

View file

@ -1,3 +1,8 @@
Fri Aug 9 12:06:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_str_normalize_ospath): normalize to Normalization Form C
using CFString.
Fri Aug 9 10:53:57 2013 Kazuki Tsujimoto <kazuki@callcc.net>
* time.c (get_timeval, get_new_timeval): use rb_obj_class()

View file

@ -3061,6 +3061,8 @@ AS_CASE("$enable_shared", [yes], [
LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "' $(XLDFLAGS)'
LIBRUBY_SO='lib$(RUBY_SO_NAME).dylib'
LIBRUBY_ALIASES='lib$(RUBY_BASE_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_INSTALL_NAME).dylib'
RUBY_APPEND_OPTION(XLDFLAGS, [-framework CoreFoundation])
RUBY_APPEND_OPTION(LIBRUBYARG_STATIC, [-framework CoreFoundation])
],
[interix*], [
LIBRUBYARG_SHARED='-L. -L${libdir} -l$(RUBY_SO_NAME)'

28
file.c
View file

@ -19,6 +19,9 @@
#include <sys/cygwin.h>
#include <wchar.h>
#endif
#ifdef __APPLE__
#include <CoreFoundation/CFString.h>
#endif
#include "ruby/ruby.h"
#include "ruby/io.h"
@ -244,12 +247,25 @@ rb_str_encode_ospath(VALUE path)
VALUE
rb_str_normalize_ospath(const char *ptr, long len)
{
rb_encoding *utf8mac = rb_enc_from_index(ENCINDEX_UTF8_MAC);
if (utf8mac) {
return rb_str_conv_enc(rb_tainted_str_new(ptr, len),
utf8mac, rb_utf8_encoding());
}
return Qnil;
VALUE str;
CFIndex buflen = 0;
CFRange all;
CFStringRef s = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
(const UInt8 *)ptr, len,
kCFStringEncodingUTF8, FALSE,
kCFAllocatorNull);
CFMutableStringRef m = CFStringCreateMutableCopy(kCFAllocatorDefault, len, s);
CFStringNormalize(m, kCFStringNormalizationFormC);
all = CFRangeMake(0, CFStringGetLength(m));
CFStringGetBytes(m, all, kCFStringEncodingUTF8, '?', FALSE, NULL, 0, &buflen);
str = rb_enc_str_new(0, buflen, rb_utf8_encoding());
CFStringGetBytes(m, all, kCFStringEncodingUTF8, '?', FALSE, (UInt8 *)RSTRING_PTR(str),
buflen, &buflen);
rb_str_set_len(str, buflen);
CFRelease(m);
CFRelease(s);
return str;
}
#endif

View file

@ -237,6 +237,8 @@ class TestProcess < Test::Unit::TestCase
MANDATORY_ENVS << 'LD_PRELOAD'
when /mswin|mingw/
MANDATORY_ENVS.concat(%w[HOME USER TMPDIR])
when /darwin/
MANDATORY_ENVS.concat(ENV.keys.grep(/\A__CF_/))
end
if e = RbConfig::CONFIG['LIBPATHENV']
MANDATORY_ENVS << e