Author: manolo
Date: 2010-12-11 06:59:22 -0800 (Sat, 11 Dec 2010)
New Revision: 8009
Log:
Better algorithm for function convert_crlf().

Modified:
   branches/branch-1.3/src/Fl_x.cxx

Modified: branches/branch-1.3/src/Fl_x.cxx
===================================================================
--- branches/branch-1.3/src/Fl_x.cxx    2010-12-11 14:39:07 UTC (rev 8008)
+++ branches/branch-1.3/src/Fl_x.cxx    2010-12-11 14:59:22 UTC (rev 8009)
@@ -280,15 +280,13 @@
 
 // replace \r\n by \n
 static void convert_crlf(unsigned char *string, long& len) {
-  unsigned char *p = string, *q = p + len;
-  while (p + 1 < q) {
-    if (*p == '\r' && *(p + 1) == '\n') {
-      memmove(p, p + 1, q - p - 1);
-      q--;
-      len--;
-    }
-    p++;
+  unsigned char *a, *b;
+  a = b = string;
+  while (*a) { 
+    if (*a == '\r' && a[1] == '\n') { a++; len--; }
+    else *b++ = *a++;
   }
+  *b = 0;
 }
 
 ////////////////////////////////////////////////////////////////
@@ -571,7 +569,6 @@
   }
 }
 
-
 void fl_open_display() {
   if (fl_display) return;
 
@@ -977,8 +974,8 @@
       if (!remaining) break;
     }
     if (buffer) {
-      convert_crlf(buffer, bytesread);
       buffer[bytesread] = 0;
+      convert_crlf(buffer, bytesread);
     }
     Fl::e_text = buffer ? (char*)buffer : (char *)"";
     Fl::e_length = bytesread;

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to