Escape input string suitable for COPY.
If no characters require escaping, simply return the input pointer. Otherwise return a new allocated string.
Definition at line 119 of file shp2pgsql-core.c.
120{
121
122
123
124
125
126
127
128
129
130 char *result;
131 char *ptr, *optr;
132 int toescape = 0;
133 size_t size;
134
136
137
138 while (*ptr)
139 {
140 if (*ptr == '\t' || *ptr == '\\' || *ptr == '\n' || *ptr == '\r')
141 toescape++;
142
143 ptr++;
144 }
145
146
147 if (toescape == 0)
149
150 size = ptr -
str + toescape + 1;
151 result = calloc(1, size);
152 optr = result;
154
155 while (*ptr)
156 {
157 if ( *ptr == '\t' || *ptr == '\\' || *ptr == '\n' || *ptr == '\r' )
158 *optr++ = '\\';
159
160 *optr++ = *ptr++;
161 }
162
163 *optr = '\0';
164
165 return result;
166}
References str.
Referenced by ShpLoaderGenerateSQLRowStatement().