Skip to content

Commit

Permalink
CFStringGetCString returns UTF8, so make UTF8 ruby strings
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Mar 25, 2011
1 parent 0a3ba4f commit 4a226c7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ext/pasteboard/pasteboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down

0 comments on commit 4a226c7

Please sign in to comment.