mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-16 06:45:59 +00:00
Minor cleanup
This commit is contained in:
@@ -53,46 +53,6 @@ void SDL_CancelClipboardData(Uint32 sequence)
|
||||
_this->clipboard_userdata = NULL;
|
||||
}
|
||||
|
||||
char **SDL_GetClipboardMimeTypes(size_t *num_mime_types)
|
||||
{
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
if (!_this) {
|
||||
SDL_SetError("Video subsystem must be initialized to query clipboard mime types");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t allocSize = sizeof(char *);
|
||||
for (size_t i = 0; i < _this->num_clipboard_mime_types; i++) {
|
||||
allocSize += strlen(_this->clipboard_mime_types[i]) + 1 + sizeof(char *);
|
||||
}
|
||||
|
||||
char *ret = SDL_malloc(allocSize);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
char **pointers = (char **)ret;
|
||||
ret += (_this->num_clipboard_mime_types + 1) * sizeof(char *);
|
||||
|
||||
for (size_t i = 0; i < _this->num_clipboard_mime_types; i++) {
|
||||
pointers[i] = ret;
|
||||
|
||||
char *mime_type = _this->clipboard_mime_types[i];
|
||||
/* copy the whole string including the terminating null char */
|
||||
char c;
|
||||
do {
|
||||
c = *mime_type;
|
||||
*ret = c;
|
||||
ret++;
|
||||
mime_type++;
|
||||
} while (c != 0);
|
||||
}
|
||||
|
||||
pointers[_this->num_clipboard_mime_types] = NULL;
|
||||
if (num_mime_types)
|
||||
*num_mime_types = _this->num_clipboard_mime_types;
|
||||
return pointers;
|
||||
}
|
||||
|
||||
bool SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types)
|
||||
{
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
@@ -272,6 +232,46 @@ bool SDL_HasClipboardData(const char *mime_type)
|
||||
}
|
||||
}
|
||||
|
||||
char **SDL_GetClipboardMimeTypes(size_t *num_mime_types)
|
||||
{
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
|
||||
if (!_this) {
|
||||
SDL_SetError("Video subsystem must be initialized to query clipboard mime types");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t allocSize = sizeof(char *);
|
||||
for (size_t i = 0; i < _this->num_clipboard_mime_types; i++) {
|
||||
allocSize += sizeof(char *) + SDL_strlen(_this->clipboard_mime_types[i]) + 1;
|
||||
}
|
||||
|
||||
char *ret = (char *)SDL_malloc(allocSize);
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char **result = (char **)ret;
|
||||
ret += sizeof(char *) * (_this->num_clipboard_mime_types + 1);
|
||||
|
||||
for (size_t i = 0; i < _this->num_clipboard_mime_types; i++) {
|
||||
result[i] = ret;
|
||||
|
||||
const char *mime_type = _this->clipboard_mime_types[i];
|
||||
// Copy the whole string including the terminating null char
|
||||
char c;
|
||||
do {
|
||||
c = *ret++ = *mime_type++;
|
||||
} while (c != '\0');
|
||||
}
|
||||
result[_this->num_clipboard_mime_types] = NULL;
|
||||
|
||||
if (num_mime_types) {
|
||||
*num_mime_types = _this->num_clipboard_mime_types;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Clipboard text
|
||||
|
||||
bool SDL_IsTextMimeType(const char *mime_type)
|
||||
|
Reference in New Issue
Block a user