changeset 23835:ad04307ef465

(Fw32_get_clipboard_data): Do not delete isolated CR characters, only convert CRLF to LF.
author Geoff Voelker <voelker@cs.washington.edu>
date Wed, 09 Dec 1998 00:03:09 +0000
parents ce563c147515
children 60713925e762
files src/w32select.c
diffstat 1 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/w32select.c	Tue Dec 08 23:56:14 1998 +0000
+++ b/src/w32select.c	Wed Dec 09 00:03:09 1998 +0000
@@ -130,9 +130,9 @@
       {
 	/* No multibyte character in OBJ.  We need not encode it.  */
 
-	/* need to know final size after '\r' chars are inserted (the
+	/* Need to know final size after CR chars are inserted (the
 	   standard CF_TEXT clipboard format uses CRLF line endings,
-	   while Emacs uses just LF internally) */
+	   while Emacs uses just LF internally).  */
 
 	truelen = nbytes;
 	dst = src;
@@ -249,7 +249,7 @@
     unsigned char *dst;
     int nbytes;
     int truelen;
-    int require_encoding = 0;
+    int require_decoding = 0;
     
     if ((src = (unsigned char *) GlobalLock (htext)) == NULL)
       goto closeclip;
@@ -264,7 +264,7 @@
 #endif
 	)
       {
-	/* If the clipboard data contains any 8-bit Latin-1 code, we
+	/* If the clipboard data contains any non-ascii code, we
 	   need to decode it.  */
 	int i;
 
@@ -272,13 +272,13 @@
 	  {
 	    if (src[i] >= 0x80)
 	      {
-		require_encoding = 1;
+		require_decoding = 1;
 		break;
 	      }
 	  }
       }
     
-    if (require_encoding)
+    if (require_decoding)
       {
 	int bufsize;
 	unsigned char *buf;
@@ -302,23 +302,25 @@
       }
     else
       {
-	/* need to know final size after '\r' chars are removed because
-	   we can't change the string size manually, and doing an extra
-	   copy is silly */
+	/* Need to know final size after CR chars are removed because we
+	   can't change the string size manually, and doing an extra
+	   copy is silly.  Note that we only remove CR when it appears
+	   as part of CRLF.  */
 
 	truelen = nbytes;
 	dst = src;
 	/* avoid using strchr because it recomputes the length everytime */
 	while ((dst = memchr (dst, '\r', nbytes - (dst - src))) != NULL)
 	  {
-	    truelen--;
+	    if (dst[1] == '\n')	/* safe because of trailing '\0' */
+	      truelen--;
 	    dst++;
 	  }
 
 	ret = make_uninit_string (truelen);
 
-	/* convert CRLF line endings (the standard CF_TEXT clipboard
-	   format) to LF endings as used internally by Emacs */
+	/* Convert CRLF line endings (the standard CF_TEXT clipboard
+	   format) to LF endings as used internally by Emacs.  */
 
 	dst = XSTRING (ret)->data;
 	while (1)
@@ -331,9 +333,11 @@
 		/* copied one line ending with '\r' */
 		int copied = next - dst;
 		nbytes -= copied;
-		dst += copied - 1;		/* overwrite '\r' */
+		dst += copied;
 		src += copied;
-	      }	    
+		if (*src == '\n')
+		  dst--;	/* overwrite '\r' with '\n' */
+	      }
 	    else
 	      /* copied remaining partial line -> now finished */
 	      break;