Module: SFML::Clipboard
- Defined in:
- ext/window/clipboard.c,
ext/window/clipboard.c
Overview
Access to the system clipboard, as plain text or Unicode text.
Class Method Summary collapse
-
.string ⇒ String
Returns the current system clipboard contents as a plain String.
-
.string=(value) ⇒ String
Sets the system clipboard to
value. -
.unicode_string ⇒ String
Returns the current system clipboard contents, decoding UTF-32 to UTF-8.
-
.unicode_string=(value) ⇒ String
Sets the system clipboard to
value, encoding it to UTF-32 first.
Class Method Details
.string ⇒ String
Returns the current system clipboard contents as a plain String.
36 37 38 39 40 |
# File 'ext/window/clipboard.c', line 36
static VALUE Clipboard_get_string(VALUE module) {
const char* string = sfClipboard_getString();
return rb_utf8_str_new_cstr(string != NULL ? string : "");
}
|
.string=(value) ⇒ String
Sets the system clipboard to value.
49 50 51 52 |
# File 'ext/window/clipboard.c', line 49
static VALUE Clipboard_set_string(VALUE module, VALUE rb_text) {
sfClipboard_setString(StringValueCStr(rb_text));
return rb_text;
}
|
.unicode_string ⇒ String
Returns the current system clipboard contents, decoding UTF-32 to UTF-8.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'ext/window/clipboard.c', line 61
static VALUE Clipboard_get_unicode_string(VALUE module) {
const sfChar32* chars = sfClipboard_getUnicodeString();
VALUE string = rb_utf8_str_new("", 0);
if (chars == NULL) {
return string;
}
for (size_t i = 0; chars[i] != 0; i++) {
char buffer[4];
int length;
unicode_char_to_utf8(chars[i], buffer, &length);
rb_str_cat(string, buffer, length);
}
return string;
}
|
.unicode_string=(value) ⇒ String
Sets the system clipboard to value, encoding it to UTF-32 first.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'ext/window/clipboard.c', line 87
static VALUE Clipboard_set_unicode_string(VALUE module, VALUE rb_text) {
VALUE codepoints;
long count;
sfChar32* chars;
StringValue(rb_text);
codepoints = rb_funcall(rb_text, rb_intern("codepoints"), 0);
count = RARRAY_LEN(codepoints);
chars = ALLOC_N(sfChar32, count + 1);
for (long i = 0; i < count; i++) {
chars[i] = (sfChar32)NUM2UINT(rb_ary_entry(codepoints, i));
}
chars[count] = 0;
sfClipboard_setUnicodeString(chars);
xfree(chars);
return rb_text;
}
|