[前][次][番号順一覧][スレッド一覧]

ruby-changes:30379

From: nobu <ko1@a...>
Date: Fri, 9 Aug 2013 12:07:07 +0900 (JST)
Subject: [ruby-changes:30379] nobu:r42457 (trunk): file.c: normalize Form C

nobu	2013-08-09 12:06:53 +0900 (Fri, 09 Aug 2013)

  New Revision: 42457

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42457

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

  Modified files:
    trunk/ChangeLog
    trunk/configure.in
    trunk/file.c
    trunk/test/ruby/test_process.rb
Index: configure.in
===================================================================
--- configure.in	(revision 42456)
+++ configure.in	(revision 42457)
@@ -3061,6 +3061,8 @@ AS_CASE("$enable_shared", [yes], [ https://github.com/ruby/ruby/blob/trunk/configure.in#L3061
 	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)'
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42456)
+++ ChangeLog	(revision 42457)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Aug  9 12:06:49 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_str_normalize_ospath): normalize to Normalization Form C
+	  using CFString.
+
 Fri Aug  9 10:53:57 2013  Kazuki Tsujimoto  <kazuki@c...>
 
 	* time.c (get_timeval, get_new_timeval): use rb_obj_class()
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 42456)
+++ test/ruby/test_process.rb	(revision 42457)
@@ -237,6 +237,8 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L237
     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
Index: file.c
===================================================================
--- file.c	(revision 42456)
+++ file.c	(revision 42457)
@@ -19,6 +19,9 @@ https://github.com/ruby/ruby/blob/trunk/file.c#L19
 #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) https://github.com/ruby/ruby/blob/trunk/file.c#L247
 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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]