From 0bdebc66c634098e24258abcbc80403243356a5a Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 10 May 2017 15:28:12 -0500 Subject: [PATCH] winex11: Simplify the clipboard HTML export function. Signed-off-by: Alexandre Julliard --- dlls/winex11.drv/clipboard.c | 61 +++++++++++--------------------------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/dlls/winex11.drv/clipboard.c b/dlls/winex11.drv/clipboard.c index 4cb8cb84300..2566d019ac5 100644 --- a/dlls/winex11.drv/clipboard.c +++ b/dlls/winex11.drv/clipboard.c @@ -1293,28 +1293,6 @@ static BOOL export_enhmetafile( Display *display, Window win, Atom prop, Atom ta /************************************************************************** - * get_html_description_field - * - * Find the value of a field in an HTML Format description. - */ -static LPCSTR get_html_description_field(LPCSTR data, LPCSTR keyword) -{ - LPCSTR pos=data; - - while (pos && *pos && *pos != '<') - { - if (memcmp(pos, keyword, strlen(keyword)) == 0) - return pos+strlen(keyword); - - pos = strchr(pos, '\n'); - if (pos) pos++; - } - - return NULL; -} - - -/************************************************************************** * export_text_html * * Export HTML Format to text/html. @@ -1323,36 +1301,27 @@ static LPCSTR get_html_description_field(LPCSTR data, LPCSTR keyword) */ static BOOL export_text_html( Display *display, Window win, Atom prop, Atom target, HANDLE handle ) { - LPCSTR data, field_value; - UINT fragmentstart, fragmentend; - - data = GlobalLock( handle ); + const char *p, *data; + UINT start = 0, end = 0; + BOOL ret = TRUE; - /* read the important fields */ - field_value = get_html_description_field(data, "StartFragment:"); - if (!field_value) - { - ERR("Couldn't find StartFragment value\n"); - goto failed; - } - fragmentstart = atoi(field_value); + if (!(data = GlobalLock( handle ))) return FALSE; - field_value = get_html_description_field(data, "EndFragment:"); - if (!field_value) + p = data; + while (*p && *p != '<') { - ERR("Couldn't find EndFragment value\n"); - goto failed; + if (!strncmp( p, "StartFragment:", 14 )) start = atoi( p + 14 ); + else if (!strncmp( p, "EndFragment:", 12 )) end = atoi( p + 12 ); + if (!(p = strpbrk( p, "\r\n" ))) break; + while (*p == '\r' || *p == '\n') p++; } - fragmentend = atoi(field_value); - - /* export only the fragment */ - put_property( display, win, prop, target, 8, &data[fragmentstart], fragmentend - fragmentstart ); - GlobalUnlock( handle ); - return TRUE; + if (start && start < end && end <= GlobalSize( handle )) + put_property( display, win, prop, target, 8, data + start, end - start ); + else + ret = FALSE; -failed: GlobalUnlock( handle ); - return FALSE; + return ret; } -- 2.11.4.GIT