Permalink
Browse files

CFStringGetCString returns UTF8, so make UTF8 ruby strings

  • Loading branch information...
1 parent 0a3ba4f commit 4a226c7fc1f7480fdd4f9d8218780d7cba5aee4d @drbrain committed Mar 25, 2011
Showing with 13 additions and 6 deletions.
  1. +13 −6 ext/pasteboard/pasteboard.c
View
19 ext/pasteboard/pasteboard.c
@@ -28,19 +28,26 @@ static VALUE utf16_internal_flavor;
static VALUE
string_ref_to_value(CFStringRef ref) {
+ VALUE string = Qnil;
char buffer[BUFSIZE];
- const char * string = NULL;
+ const char * str = NULL;
- string = CFStringGetCStringPtr(ref, kCFStringEncodingUTF8);
+ str = CFStringGetCStringPtr(ref, kCFStringEncodingUTF8);
- if (string == NULL)
+ if (str == NULL)
if (CFStringGetCString(ref, buffer, BUFSIZE, kCFStringEncodingUTF8))
- string = buffer;
+ str = buffer;
- if (string == NULL) /* HACK buffer was too small */
+ if (str == NULL) /* HACK buffer was too small */
return Qnil;
- return rb_str_new2(string);
+ string = rb_str_new2(str);
+
+#if HAVE_RB_STR_ENCODE
+ rb_enc_associate(string, rb_to_encoding(utf8_encoding));
+#endif
+
+ return string;
}
static char *

0 comments on commit 4a226c7

Please sign in to comment.