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

Function tokenizer_core

numpy/core/src/multiarray/textreading/tokenize.cpp:114–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112
113template <typename UCS>
114static inline int
115tokenizer_core(tokenizer_state *ts, parser_config *const config)
116{
117 UCS *pos = (UCS *)ts->pos;
118 UCS *stop = (UCS *)ts->end;
119 UCS *chunk_start;
120
121 if (ts->state == TOKENIZE_CHECK_QUOTED) {
122 /* before we can check for quotes, strip leading whitespace */
123 if (config->ignore_leading_whitespace) {
124 while (pos < stop && Py_UNICODE_ISSPACE(*pos) &&
125 *pos != '\r' && *pos != '\n') {
126 pos++;
127 }
128 if (pos == stop) {
129 ts->pos = (char *)pos;
130 return 0;
131 }
132 }
133
134 /* Setting chunk effectively starts the field */
135 if (*pos == config->quote) {
136 ts->fields[ts->num_fields - 1].quoted = true;
137 ts->state = TOKENIZE_QUOTED;
138 pos++; /* TOKENIZE_QUOTED is OK with pos == stop */
139 }
140 else {
141 /* Set to TOKENIZE_QUOTED or TOKENIZE_QUOTED_WHITESPACE */
142 ts->state = ts->unquoted_state;
143 }
144 }
145
146 switch (ts->state) {
147 case TOKENIZE_UNQUOTED:
148 chunk_start = pos;
149 for (; pos < stop; pos++) {
150 if (*pos == '\r') {
151 ts->state = TOKENIZE_EAT_CRLF;
152 break;
153 }
154 else if (*pos == '\n') {
155 ts->state = TOKENIZE_LINE_END;
156 break;
157 }
158 else if (*pos == config->delimiter) {
159 ts->state = TOKENIZE_INIT;
160 break;
161 }
162 else if (*pos == config->comment) {
163 ts->state = TOKENIZE_GOTO_LINE_END;
164 break;
165 }
166 }
167 if (copy_to_field_buffer(ts, chunk_start, pos) < 0) {
168 return -1;
169 }
170 pos++;
171 break;

Callers

nothing calls this directly

Calls 1

copy_to_field_bufferFunction · 0.85

Tested by

no test coverage detected