PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ escape_copy_string()

char * escape_copy_string ( char *  str)

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 121 of file shp2pgsql-core.c.

122{
123 /*
124 * Escape the following characters by adding a preceding backslash
125 * tab, backslash, cr, lf
126 *
127 * 1. find # of escaped characters
128 * 2. make new string
129 *
130 */
131
132 char *result;
133 char *ptr, *optr;
134 int toescape = 0;
135 size_t size;
136
137 ptr = str;
138
139 /* Count how many characters we need to escape so we know the size of the string we need to return */
140 while (*ptr)
141 {
142 if (*ptr == '\t' || *ptr == '\\' || *ptr == '\n' || *ptr == '\r')
143 toescape++;
144
145 ptr++;
146 }
147
148 /* If we don't have to escape anything, simply return the input pointer */
149 if (toescape == 0)
150 return str;
151
152 size = ptr - str + toescape + 1;
153 result = calloc(1, size);
154 optr = result;
155 ptr = str;
156
157 while (*ptr)
158 {
159 if ( *ptr == '\t' || *ptr == '\\' || *ptr == '\n' || *ptr == '\r' )
160 *optr++ = '\\';
161
162 *optr++ = *ptr++;
163 }
164
165 *optr = '\0';
166
167 return result;
168}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
#define str(s)

References result, and str.

Referenced by ShpLoaderGenerateSQLRowStatement().

Here is the caller graph for this function: