Răsfoiți Sursa

If there is a sequence of \r\n eat the \r and emit only \n.

mingodad 13 ani în urmă
părinte
comite
78a386f709
1 a modificat fișierele cu 16 adăugiri și 5 ștergeri
  1. 16 5
      sqstdlib/sqstdstring.cpp

+ 16 - 5
sqstdlib/sqstdstring.cpp

@@ -110,14 +110,18 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
                     SQChar *ts2 = (SQChar*)ts;
                     SQChar *ts2 = (SQChar*)ts;
                       while (size--) {
                       while (size--) {
                         ++addlen;
                         ++addlen;
-                        if (*ts2 == '"' || *ts2 == '\\') {
+                        if (*ts2 == '\r' && *(ts2+1) == '\n' ) {
+                          ++addlen;
+                          ++ts2; //eat \r and output only \n
+                        }
+                        else if (*ts2 == '"' || *ts2 == '\\' || *ts2 == '\n') {
                           ++addlen;
                           ++addlen;
                         }
                         }
                         else if (*ts2 == '\0' || iscntrl(uchar(*ts2))) {
                         else if (*ts2 == '\0' || iscntrl(uchar(*ts2))) {
                           SQChar buff[10];
                           SQChar buff[10];
                           addlen += scsprintf(buff, "\\x%x", (int)uchar(*ts2))-1; //-1 because we already added the original char to the sum
                           addlen += scsprintf(buff, "\\x%x", (int)uchar(*ts2))-1; //-1 because we already added the original char to the sum
                         }
                         }
-                        ts2++;
+                        ++ts2;
                       }
                       }
 
 
                       ts2 = (SQChar*)i; //save the i position using pointer as integer
                       ts2 = (SQChar*)i; //save the i position using pointer as integer
@@ -129,10 +133,17 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
                       ts2 = &dest[(int)ts2]; //use saved i position saved on pointer as integer
                       ts2 = &dest[(int)ts2]; //use saved i position saved on pointer as integer
                       *ts2++ = '"';
                       *ts2++ = '"';
                       while (size--) {
                       while (size--) {
+                        if (*ts == '\r' && *(ts+1) == '\n' ) {
+                          ++ts; //eat \r and output only \n
+                        }
                         if (*ts == '"' || *ts == '\\') {
                         if (*ts == '"' || *ts == '\\') {
                             *ts2++ = '\\';
                             *ts2++ = '\\';
                             *ts2++ = *ts;
                             *ts2++ = *ts;
                         }
                         }
+                        else if (*ts == '\n') {
+                            *ts2++ = '\\';
+                            *ts2++ = 'n';
+                        }
                         else if (*ts == '\0' || iscntrl(uchar(*ts))) {
                         else if (*ts == '\0' || iscntrl(uchar(*ts))) {
                           SQChar buff[10];
                           SQChar buff[10];
                           int iw;
                           int iw;
@@ -141,12 +152,12 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
                         }
                         }
                         else
                         else
                             *ts2++ = *ts;
                             *ts2++ = *ts;
-                        ts++;
+                        ++ts;
                       }
                       }
                       *ts2++ = '"';
                       *ts2++ = '"';
 
 
-                      n++;
-                      nparam ++;
+                      ++n;
+                      ++nparam;
                       continue;
                       continue;
                 }
                 }
                 else
                 else