]> granicus.if.org Git - postgis/commitdiff
Patch to handle tab and CR better, from dfuhriman. (#203)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 24 Oct 2009 00:58:04 +0000 (00:58 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Sat, 24 Oct 2009 00:58:04 +0000 (00:58 +0000)
git-svn-id: http://svn.osgeo.org/postgis/branches/1.3@4678 b70326c6-7e19-0410-871a-916f4a2858ee

loader/shp2pgsql.c

index c7f88f94e31896167c1970924ba565103d7260e1..7dcd865dd225cd6a7c58a32543594f9b72262970 100644 (file)
@@ -185,6 +185,7 @@ make_good_string(char *str)
 
        while (*ptr) {
                if ( *ptr == '\t' || *ptr == '\\' ) toescape++;
+               if ( *ptr == '\r' || *ptr == '\n') toescape+=2;
                ptr++;
        }
 
@@ -197,8 +198,29 @@ make_good_string(char *str)
        optr=result;
        ptr=str;
        while (*ptr) {
-               if ( *ptr == '\t' || *ptr == '\\' ) *optr++='\\';
-               *optr++=*ptr++;
+         switch(*ptr) {
+            case('\t'):
+              *optr++='\\';
+              *optr++=*ptr++;
+              break;
+            case('\\'):
+              *optr++='\\';
+              *optr++=*ptr++;
+              break;
+            case('\r'):
+              *optr++='\\';
+              *optr++='r';
+              *optr=*ptr++;
+              break;
+            case('\n'):
+               *optr++='\\';
+               *optr++='n';
+               *optr=*ptr++;
+               break;
+            default:
+              *optr++=*ptr++;
+              continue;
+          }
        }
        *optr='\0';