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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.