Permalink
Browse files

Dir.glob: convert paths to unicode normalization form C

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4991 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent b452bea commit 5640f805d471b2da7f54fca7842f7e700154a9b6 @lrz lrz committed Dec 7, 2010
Showing with 25 additions and 1 deletion.
  1. +4 −1 dir.c
  2. +2 −0 encoding.h
  3. +19 −0 string.c
View
5 dir.c
@@ -15,6 +15,7 @@
#include "ruby/node.h"
#include "ruby/util.h"
#include "vm.h"
+#include "encoding.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -1391,7 +1392,9 @@ rb_glob(const char *path, void (*func)(const char *, VALUE), VALUE arg)
static void
push_pattern(const char *path, VALUE ary)
{
- rb_ary_push(ary, rb_tainted_str_new2(path));
+ VALUE str = rstr_new_path(path);
+ OBJ_TAINT(str);
+ rb_ary_push(ary, str);
}
int
View
2 encoding.h
@@ -368,6 +368,8 @@ str_check_ascii_compatible(VALUE str)
}
}
+VALUE rstr_new_path(const char *path);
+
#if defined(__cplusplus)
} // extern "C"
#endif
View
19 string.c
@@ -6724,3 +6724,22 @@ rb_str_modify(VALUE obj)
rb_raise(rb_eArgError, "can't modify NSString");
}
}
+
+VALUE
+rstr_new_path(const char *path)
+{
+ // XXX this should be rewritten using ICU (utrans.h?) to avoid creating
+ // these 2 temporary CFStrings.
+ CFStringRef tmp = CFStringCreateWithFileSystemRepresentation(NULL, path);
+ assert(tmp != NULL);
+
+ CFMutableStringRef tmp2 = CFStringCreateMutableCopy(NULL, 0, tmp);
+ assert(tmp2 != NULL);
+ CFRelease(tmp);
+ CFStringNormalize(tmp2, kCFStringNormalizationFormC);
+
+ rb_str_t *str = str_new_from_cfstring(tmp2);
+ CFRelease(tmp2);
+
+ return (VALUE)str;
+}

0 comments on commit 5640f80

Please sign in to comment.