Looking at cx_Parse + stuff, some thoughts and questions arise:
- Is it necessary to fiddle with the cache? Just undef _cache on perl side to enforce parameter changes; this ought to be a rare event? Stashing an opaque C struct avoids needless copying.
- Then what about unicode whitespace characters?
- quote_char, escape_char, etc., could be ints and default to -1 when undefined. Easier to test against. However ...
- Have you tried writing this thing as an fsm?
enum { TXT, BIN, WSPACE, UTF8, QUOT, ESC, SEP, CR, NL_EOLX, ..., NN };
enum { EXFIELD, INFIELD = 1*NN, INQUOT = 2*NN, CRSEEN = 3*NN } state;
while ((c = getc()) != EOF) {
int ctype = cached->xlat[c];
if () ... /* perhaps peel the most likely case(s) */
switch (state + ctype) {
case WSPACE: continue; /* nop: allow_whitespace test in xlat[] */
case BIN: error(); /* again, resolved when constructing xlat[] */
case TXT: state = INFIELD; putc(c); continue;
case INFIELD+TXT: case INQUOT+TXT: case INQUOT+SEP: ... putc(c);
...
case UTF8: case INFIELD+UTF8: ...accumulate/xlat...
case CRSEEN+NL_EOLX: ...; state = 0; continue;
case CRSEEN+...: error();
default: error();
}
...
Or possibly:
enum { EXFIELD, INFIELD = 0x100, INQUOT = 0x200, CRS = 0x300 } sta
+te;
...
int action = cached->xlat[state + c];
decode(action);
...
Ultimately, the (handful of) UTF sequences may also be resolved by walking trie-like state tables.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.