aboutsummaryrefslogtreecommitdiffstats
path: root/vncviewer
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2016-01-22 16:40:59 +0100
committerPierre Ossman <ossman@cendio.se>2019-07-01 10:49:15 +0200
commit56fa7821560a60db39195e8c81d16b46e8f972c2 (patch)
treecc2013baaa127f3e6db22de64155b0fd0c85c4a9 /vncviewer
parent66f1db543b425f6fe64d437477e6f78924ec57be (diff)
downloadtigervnc-56fa7821560a60db39195e8c81d16b46e8f972c2.tar.gz
tigervnc-56fa7821560a60db39195e8c81d16b46e8f972c2.zip
Add UTF-8 to/from ISO 8859-1 conversion routines
We convert between UTF-8 and ISO 8859-1 (latin 1) in several places so create some common routines for this.
Diffstat (limited to 'vncviewer')
-rw-r--r--vncviewer/Viewport.cxx42
-rw-r--r--vncviewer/Viewport.h4
2 files changed, 15 insertions, 31 deletions
diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx
index 5e495992..151ecb47 100644
--- a/vncviewer/Viewport.cxx
+++ b/vncviewer/Viewport.cxx
@@ -235,25 +235,17 @@ void Viewport::updateWindow()
void Viewport::serverCutText(const char* str)
{
char *buffer;
- int size, ret;
+ size_t len;
clearPendingClipboard();
if (!acceptClipboard)
return;
- size = fl_utf8froma(NULL, 0, str, strlen(str));
- if (size <= 0)
- return;
-
- size++;
-
- buffer = new char[size];
+ buffer = latin1ToUTF8(str);
+ len = strlen(buffer);
- ret = fl_utf8froma(buffer, size, str, strlen(str));
- assert(ret < size);
-
- vlog.debug("Got clipboard data (%d bytes)", (int)strlen(buffer));
+ vlog.debug("Got clipboard data (%d bytes)", (int)len);
if (!hasFocus()) {
pendingServerCutText = buffer;
@@ -264,11 +256,11 @@ void Viewport::serverCutText(const char* str)
// dump the data into both variants.
#if !defined(WIN32) && !defined(__APPLE__)
if (setPrimary)
- Fl::copy(buffer, ret, 0);
+ Fl::copy(buffer, len, 0);
#endif
- Fl::copy(buffer, ret, 1);
+ Fl::copy(buffer, len, 1);
- delete [] buffer;
+ strFree(buffer);
}
static const char * dotcursor_xpm[] = {
@@ -550,27 +542,19 @@ void Viewport::resize(int x, int y, int w, int h)
int Viewport::handle(int event)
{
char *buffer, *filtered;
- int ret;
int buttonMask, wheelMask;
DownMap::const_iterator iter;
switch (event) {
case FL_PASTE:
- buffer = new char[Fl::event_length() + 1];
-
clearPendingClipboard();
- // This is documented as to ASCII, but actually does to 8859-1
- ret = fl_utf8toa(Fl::event_text(), Fl::event_length(), buffer,
- Fl::event_length() + 1);
- assert(ret < (Fl::event_length() + 1));
- filtered = convertLF(buffer, ret);
- delete [] buffer;
+ buffer = utf8ToLatin1(Fl::event_text(), Fl::event_length());
+ filtered = convertLF(buffer);
+ strFree(buffer);
if (!hasFocus()) {
- pendingClientCutText = new char[strlen(filtered) + 1];
- strcpy((char*)pendingClientCutText, filtered);
- strFree(filtered);
+ pendingClientCutText = filtered;
return 1;
}
@@ -747,9 +731,9 @@ void Viewport::handleClipboardChange(int source, void *data)
void Viewport::clearPendingClipboard()
{
- delete [] pendingServerCutText;
+ strFree(pendingServerCutText);
pendingServerCutText = NULL;
- delete [] pendingClientCutText;
+ strFree(pendingClientCutText);
pendingClientCutText = NULL;
}
diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h
index c2c9872e..8b9b469b 100644
--- a/vncviewer/Viewport.h
+++ b/vncviewer/Viewport.h
@@ -114,8 +114,8 @@ private:
bool firstLEDState;
- const char* pendingServerCutText;
- const char* pendingClientCutText;
+ char* pendingServerCutText;
+ char* pendingClientCutText;
rdr::U32 menuKeySym;
int menuKeyCode, menuKeyFLTK;