8 /* Extensible cords are strings that may be destructively appended to. */
9 /* They allow fast construction of cords from characters that are */
10 /* being read from a stream. */
12 * A client might look like:
25 * CORD_ec_append(x, c);
27 * result = CORD_balance(CORD_ec_to_cord(x));
29 * If a C string is desired as the final result, the call to CORD_balance
30 * may be replaced by a call to CORD_to_char_star.
34 # define CORD_BUFSZ 128
37 typedef struct CORD_ec_struct
{
40 char ec_buf
[CORD_BUFSZ
+1];
43 /* This structure represents the concatenation of ec_cord with */
44 /* ec_buf[0 ... (ec_bufptr-ec_buf-1)] */
46 /* Flush the buffer part of the extended chord into ec_cord. */
47 /* Note that this is almost the only real function, and it is */
48 /* implemented in 6 lines in cordxtra.c */
49 void CORD_ec_flush_buf(CORD_ec x
);
51 /* Convert an extensible cord to a cord. */
52 # define CORD_ec_to_cord(x) (CORD_ec_flush_buf(x), (x)[0].ec_cord)
54 /* Initialize an extensible cord. */
55 # define CORD_ec_init(x) ((x)[0].ec_cord = 0, (x)[0].ec_bufptr = (x)[0].ec_buf)
57 /* Append a character to an extensible cord. */
58 # define CORD_ec_append(x, c) \
60 if ((x)[0].ec_bufptr == (x)[0].ec_buf + CORD_BUFSZ) { \
61 CORD_ec_flush_buf(x); \
63 *((x)[0].ec_bufptr)++ = (c); \
66 /* Append a cord to an extensible cord. Structure remains shared with */
68 void CORD_ec_append_cord(CORD_ec x
, CORD s
);