#include "postgres_fe.h"
#include <ctype.h>
#include "common.h"
#include "stringutils.h"
Go to the source code of this file.
|
| char * | strtokx (const char *s, const char *whitespace, const char *delim, const char *quote, char escape, bool e_strings, bool del_quotes, int encoding) |
| |
| void | strip_quotes (char *source, char quote, char escape, int encoding) |
| |
| char * | quote_if_needed (const char *source, const char *entails_quote, char quote, char escape, bool force_quote, int encoding) |
| |
◆ quote_if_needed()
Definition at line 292 of file stringutils.c.
295{
296 const char *src;
297 char *ret;
300
303
306
308
309 while (*src)
310 {
313
315 {
318 }
319 else if (
c == escape)
320 {
323 }
326
330 }
331
334
336 {
339 }
340
341 return ret;
342}
#define Assert(condition)
int PQmblenBounded(const char *s, int encoding)
void * pg_malloc(size_t size)
static rewind_source * source
References Assert, encoding, fb(), free, i, pg_malloc(), PQmblenBounded(), and source.
◆ strip_quotes()
Definition at line 240 of file stringutils.c.
241{
242 char *src;
244
247
249
250 if (*src && *src == quote)
251 src++;
252
253 while (*src)
254 {
257
258 if (
c == quote && src[1] ==
'\0')
259 break;
260 else if (
c == quote && src[1] == quote)
261 src++;
262 else if (
c == escape && src[1] !=
'\0')
263 src++;
264
268 }
269
271}
References Assert, encoding, fb(), i, PQmblenBounded(), and source.
Referenced by parse_slash_copy(), and strtokx().
◆ strtokx()
Definition at line 52 of file stringutils.c.
60{
62
63 static char *
string =
NULL;
64
65
66
67 unsigned int offset;
69 char *p;
70
71 if (s)
72 {
74
75
76
77
78
79
83 }
84
87
88
90 start = &
string[offset];
91
92
94 {
95
100 }
101
102
104 {
105
106
107
108
109
110
111
113 if (*p != '\0')
114 {
117 *p = '\0';
118 string = p + 1;
119 }
120 else
121 {
122
123 string = p;
124 }
125
127 }
128
129
132 (*p == 'E' || *p == 'e') &&
133 p[1] == '\'')
134 {
135 quote = "'";
136 escape = '\\';
137 p++;
138 }
139
140
141 if (quote &&
strchr(quote, *p))
142 {
143
145
147 {
148 if (*p == escape && p[1] != '\0')
149 p++;
151 p++;
153 {
154 p++;
155 break;
156 }
157 }
158
159
160
161
162
163 if (*p != '\0')
164 {
167 *p = '\0';
168 string = p + 1;
169 }
170 else
171 {
172
173 string = p;
174 }
175
176
179
181 }
182
183
184
185
186
187
189
190 if (delim)
191 {
193
196 }
197
198 if (quote)
199 {
201
204 }
205
207
208
209
210
211
212 if (*p != '\0')
213 {
216 *p = '\0';
217 string = p + 1;
218 }
219 else
220 {
221
222 string = p;
223 }
224
226}
void strip_quotes(char *source, char quote, char escape, int encoding)
References encoding, fb(), free, pg_malloc(), PQmblenBounded(), start, storage, and strip_quotes().
Referenced by parse_slash_copy().