--- parser3/src/lib/cord/include/cord.h 2003/07/24 11:31:22 1.2 +++ parser3/src/lib/cord/include/cord.h 2009/07/16 09:18:55 1.8 @@ -74,6 +74,13 @@ typedef const char * CORD; /* Is a nonempty cord represented as a C string? */ #define CORD_IS_STRING(s) (*(s) != '\0') +/* Allows struct Concatenation modification on merge in CORD_cat, + thus all source Concatenation structs must be prepared for this */ +#define CORD_CAT_OPTIMIZATION + +/* Caches CORD_chars result to avoide useless allocations */ +#define CORD_CHARS_CACHE + /* Concatenate two cords. If the arguments are C strings, they may */ /* not be subsequently altered. */ CORD CORD_cat(CORD x, CORD y); @@ -90,6 +97,12 @@ CORD CORD_cat(CORD x, CORD y); */ CORD CORD_cat_char_star(CORD x, const char * y, size_t leny); +#ifdef CORD_CAT_OPTIMIZATION +void CORD_concatenation_protect(CORD x); +CORD CORD_cat_optimized(CORD x, CORD y); +CORD CORD_cat_char_star_optimized(CORD x, const char * y, size_t leny); +#endif + /* Compute the length of a cord */ size_t CORD_len(CORD x); @@ -99,9 +112,12 @@ typedef char (* CORD_fn)(size_t i, void /* Turn a functional description into a cord. */ CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len); +/* Turn a functional description into a cord, only conjunction&func. */ +CORD CORD_from_fn_gen(CORD_fn fn, void * client_data, size_t len); + /* Return the substring (subcord really) of x with length at most n, */ /* starting at position i. (The initial character has position 0.) */ -CORD CORD_substr(CORD x, size_t i, size_t n); +CORD CORD_substr(CORD x, size_t i, size_t n, size_t len); /* Return the argument, but rebalanced to allow more efficient */ /* character retrieval, substring operations, and comparisons. */ @@ -122,6 +138,10 @@ CORD CORD_balance(CORD x); /* Function to iteratively apply to individual characters in cord. */ typedef int (* CORD_iter_fn)(char c, void * client_data); +/* Function to iteratively apply to individual block in cord. */ +typedef int (* CORD_block_iter_fn)(char c, size_t len, void* client_data); + + /* Function to apply to substrings of a cord. Each substring is a */ /* a C character string, not a general cord. */ typedef int (* CORD_batched_iter_fn)(const char * s, void * client_data); @@ -138,6 +158,9 @@ typedef int (* CORD_batched_iter_fn)(con int CORD_iter5(CORD x, size_t i, CORD_iter_fn f1, CORD_batched_iter_fn f2, void * client_data); +/* iterate over function block in cord */ +int CORD_block_iter(CORD x, size_t i, CORD_block_iter_fn f1, void * client_data); + /* A simpler version that starts at 0, and without f2: */ int CORD_iter(CORD x, CORD_iter_fn f1, void * client_data); # define CORD_iter(x, f1, cd) CORD_iter5(x, 0, f1, CORD_NO_FN, cd) @@ -209,7 +232,6 @@ void CORD_dump(CORD x); /* Concatenate a character to the end of a cord. */ CORD CORD_cat_char(CORD x, char c); - /* Concatenate n cords. */ CORD CORD_catn(int n, /* CORD */ ...); @@ -226,7 +248,7 @@ int CORD_ncmp(CORD x, size_t x_start, CO /* Find the first occurrence of s in x at position start or later. */ /* Return the position of the first character of s in x, or */ /* CORD_NOT_FOUND if there is none. */ -size_t CORD_str(CORD x, size_t start, CORD s); +size_t CORD_str(CORD x, size_t start, CORD s, size_t xlen); /* Return a cord consisting of i copies of (possibly NUL) c. Dangerous */ /* in conjunction with CORD_to_char_star. */ @@ -263,7 +285,7 @@ CORD CORD_from_file_lazy(FILE * f); /* Turn a cord into a C string. The result shares no structure with */ /* x, and is thus modifiable. */ -char * CORD_to_char_star(CORD x); +char * CORD_to_char_star(CORD x, size_t len); /* Turn a C string into a CORD. The C string is copied, and so may */ /* subsequently be modified. */ @@ -271,7 +293,7 @@ CORD CORD_from_char_star(const char *s); /* Identical to the above, but the result may share structure with */ /* the argument and is thus not modifiable. */ -const char * CORD_to_const_char_star(CORD x); +const char * CORD_to_const_char_star(CORD x, size_t len); /* Write a cord to a file, starting at the current position. No */ /* trailing NULs are newlines are added. */