MCPcopy Create free account
hub / github.com/numpy/numpy / fromfile_skip_separator

Function fromfile_skip_separator

numpy/core/src/multiarray/ctors.c:221–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221static int
222fromfile_skip_separator(FILE **fp, const char *sep, void *NPY_UNUSED(stream_data))
223{
224 int result = 0;
225 const char *sep_start = sep;
226
227 while (1) {
228 int c = fgetc(*fp);
229
230 if (c == EOF) {
231 result = -1;
232 break;
233 }
234 else if (*sep == '\0') {
235 ungetc(c, *fp);
236 if (sep != sep_start) {
237 /* matched separator */
238 result = 0;
239 break;
240 }
241 else {
242 /* separator was whitespace wildcard that didn't match */
243 result = -2;
244 break;
245 }
246 }
247 else if (*sep == ' ') {
248 /* whitespace wildcard */
249 if (!isspace(c)) {
250 sep++;
251 sep_start++;
252 ungetc(c, *fp);
253 }
254 else if (sep == sep_start) {
255 sep_start--;
256 }
257 }
258 else if (*sep != c) {
259 ungetc(c, *fp);
260 result = -2;
261 break;
262 }
263 else {
264 sep++;
265 }
266 }
267 return result;
268}
269
270/*
271 * Change a sub-array field to the base descriptor

Callers

nothing calls this directly

Calls 1

isspaceFunction · 0.85

Tested by

no test coverage detected