mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-18 17:04:50 +00:00
multi-char IRS/IFS/IPS iterate
This commit is contained in:
parent
a5ca9235ac
commit
a7bc78414e
2 changed files with 14 additions and 9 deletions
|
|
@ -61,6 +61,8 @@ char* mlr_get_cline2(FILE* fp, char irs) {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// 0 1 2 3
|
||||
// a b c 0
|
||||
char* mlr_get_sline(FILE* fp, char* irs, int irslen) {
|
||||
size_t linecap = INITIAL_SIZE;
|
||||
char* restrict line = mlr_malloc_or_die(INITIAL_SIZE);
|
||||
|
|
@ -77,21 +79,22 @@ char* mlr_get_sline(FILE* fp, char* irs, int irslen) {
|
|||
p = line;
|
||||
}
|
||||
c = getc_unlocked(fp);
|
||||
if (c == irslast) {
|
||||
if (c == EOF) {
|
||||
if (p == line)
|
||||
eof = TRUE;
|
||||
*p = 0;
|
||||
break;
|
||||
} else if (c == irslast) {
|
||||
// Example: delim="abc". last='c'. Already have read "ab" into line. p-line=2.
|
||||
// Now reading 'c'.
|
||||
// xxx make a memeq
|
||||
// xxx make a memneq
|
||||
if (((p-line) >= irslenm1) && !strncmp(p-irslenm1, irs, irslenm1)) {
|
||||
p -= irslenm1;
|
||||
*p = 0;
|
||||
break;
|
||||
} else {
|
||||
*(p++) = c;
|
||||
}
|
||||
} else if (c == EOF) {
|
||||
if (p == line)
|
||||
eof = TRUE;
|
||||
*p = 0;
|
||||
break;
|
||||
} else {
|
||||
*(p++) = c;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,12 @@ typedef struct _lrec_reader_stdio_dkvp_state_t {
|
|||
char ifs;
|
||||
char ips;
|
||||
int irslen;
|
||||
int ifslen;
|
||||
int ipslen;
|
||||
int allow_repeat_ifs;
|
||||
} lrec_reader_stdio_dkvp_state_t;
|
||||
|
||||
// xxx line-reader: getline or getsline
|
||||
// xxx line-reader: getcline or getsline
|
||||
// xxx line-parser: single-char or multi-char
|
||||
// xxx UTx2x2
|
||||
|
||||
|
|
@ -39,8 +41,8 @@ static lrec_t* lrec_reader_stdio_dkvp_process_single_irs(void* pvstate, void* pv
|
|||
}
|
||||
|
||||
static lrec_t* lrec_reader_stdio_dkvp_process_multi_irs(void* pvstate, void* pvhandle, context_t* pctx) {
|
||||
FILE* input_stream = pvhandle;
|
||||
lrec_reader_stdio_dkvp_state_t* pstate = pvstate;
|
||||
FILE* input_stream = pvhandle;
|
||||
char* line = mlr_get_sline(input_stream, pstate->irs, pstate->irslen);
|
||||
if (line == NULL)
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue