From 4501f8134f42043e27ebab95ee5133f4b8c76efd Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Sun, 22 Mar 2026 00:49:37 +0100 Subject: begun thinkering how to refactor (cleanup) CSV parser --- include/qntan/Qntan.h | 54 ++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'include/qntan/Qntan.h') diff --git a/include/qntan/Qntan.h b/include/qntan/Qntan.h index fd7783d..d5ada3a 100644 --- a/include/qntan/Qntan.h +++ b/include/qntan/Qntan.h @@ -1003,38 +1003,44 @@ struct Qntan_Networker { struct Qntan_CsvDec { /**/ + void (*reset)( struct Qntan_CsvDec** ); + /* Throws away parsing state and prepares to begin parsing on a new input + * document. + */ void (*write)( struct Qntan_CsvDec**, void const*buf, int buf_len, int flgs, void(*onDone)(int ret,Qntan_Cls), Qntan_Cls ); - /* @param flgs - * 0x4 set means this is last chunk. - * Any other bit set is UNDEFINED BEHAVIOR! + /* Write more data to the csv parser. Another `write` call MUST ONLY + * happen after `onDone` of the previous call marks completion of + * the previous action. + * @param flgs + * 0x4 set means this is last chunk. All other bits MUST be set + * to zero. */ }; struct Qntan_CsvDec_Mentor { - /**/ - void (*onCsvDocEnd)( Qntan_Cls ); - /* TODO doc - */ - void (*onEntityBeg)( Qntan_Cls ); - /* TODO doc - */ - void (*onEntityEnd)( Qntan_Cls ); - /* TODO doc - */ - void (*onAttrBeg)( Qntan_Cls ); - /* TODO doc - */ - void (*onAttrEnd)( Qntan_Cls ); - /* TODO doc - */ - void (*onChunkNaked)( char const*buf, int buf_len, Qntan_Cls ); - /* TODO doc - */ - void (*onChunkQuoted)( char const*buf, int buf_len, Qntan_Cls ); - /* TODO doc + /* WARN: Passed buffers only remain valid upon return. + */ + void (*onChunk)( struct Qntan_CsvDec_Mentor**, + int64_t row, int64_t col, char const*buf, int buf_len, unsigned flg, + void(*onDone)(Qntan_Cls), Qntan_Cls ); + /* Called repeatedly with chunks of data. `row` is the ONE-based row + * number (so 1st row has nr 1). `col` is the ONE-based column number (so + * 1st colum is nr 1). `flg & 4` indicates this is the last buffer + * for this cell. + */ +// TODO void (*onChunkRaw)( struct Qntan_CsvDec_Mentor**, +// TODO int64_t row, int64_t col, char const*buf, int buf_len, unsigned flg, +// TODO void(*onDone)(Qntan_Cls), Qntan_Cls ); +// TODO /* Same as `onChunk`. BUT: Quotations will not be removed, but will +// TODO * be as found in the original document. +// TODO */ + void (*onEnd)( struct Qntan_CsvDec_Mentor**, int err, char*emsg ); + /* Called ONCE at end. with err `0` on success. `err` is a negated + * error number on erorr. In this case, `emsg` MAY contains error + * details in case of error. */ }; -- cgit v1.3.1 From c9820f0a82b0240a30d12eadd90e0f1c3e042f2c Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Sun, 22 Mar 2026 14:23:27 +0100 Subject: Add vt redirect macros for CSV related types. --- include/qntan/Qntan.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/qntan/Qntan.h') diff --git a/include/qntan/Qntan.h b/include/qntan/Qntan.h index d5ada3a..e532f91 100644 --- a/include/qntan/Qntan.h +++ b/include/qntan/Qntan.h @@ -1001,6 +1001,13 @@ struct Qntan_Networker { +#ifndef Qntan_CsvDec_reset +# define Qntan_CsvDec_reset(A) (*A)->reset(A) +#endif +#ifndef Qntan_CsvDec_write +# define Qntan_CsvDec_write(A, B, C, D, E, F) (*A)->write(A, B, C, D, E, F) +#endif + struct Qntan_CsvDec { /**/ void (*reset)( struct Qntan_CsvDec** ); @@ -1019,6 +1026,12 @@ struct Qntan_CsvDec { */ }; +#ifndef Qntan_CsvDec_Mentor_onChunk +# define Qntan_CsvDec_Mentor_onChunk(A, B, C, D, E, F, G, H) (*A)->onChunk(A, B, C, D, E, F, G, H) +#endif +#ifndef Qntan_CsvDec_Mentor_onEnd +# define Qntan_CsvDec_Mentor_onEnd(A, B, C, D, E, F, G, H) (*A)->onEnd(A, B, C, D, E, F, G, H) +#endif struct Qntan_CsvDec_Mentor { /* WARN: Passed buffers only remain valid upon return. -- cgit v1.3.1 From 451ea93bae88e6ac8566f80d029748513d0c5725 Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Sun, 22 Mar 2026 19:51:42 +0100 Subject: Make `flg` arg just an `int`. --- include/qntan/Qntan.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/qntan/Qntan.h') diff --git a/include/qntan/Qntan.h b/include/qntan/Qntan.h index e532f91..a998031 100644 --- a/include/qntan/Qntan.h +++ b/include/qntan/Qntan.h @@ -1037,7 +1037,7 @@ struct Qntan_CsvDec_Mentor { /* WARN: Passed buffers only remain valid upon return. */ void (*onChunk)( struct Qntan_CsvDec_Mentor**, - int64_t row, int64_t col, char const*buf, int buf_len, unsigned flg, + int64_t row, int64_t col, char const*buf, int buf_len, int flg, void(*onDone)(Qntan_Cls), Qntan_Cls ); /* Called repeatedly with chunks of data. `row` is the ONE-based row * number (so 1st row has nr 1). `col` is the ONE-based column number (so -- cgit v1.3.1