--- parser3/src/lib/cord/include/cord.h 2003/07/24 11:31:22 1.2 +++ parser3/src/lib/cord/include/cord.h 2013/07/21 13:37:47 1.9 @@ -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. */ @@ -291,42 +313,4 @@ size_t CORD_chr(CORD x, size_t i, int c) /* must be < CORD_len(x). */ size_t CORD_rchr(CORD x, size_t i, int c); - -/* The following are also not primitive, but are implemented in */ -/* cordprnt.c. They provide functionality similar to the ANSI C */ -/* functions with corresponding names, but with the following */ -/* additions and changes: */ -/* 1. A %r conversion specification specifies a CORD argument. Field */ -/* width, precision, etc. have the same semantics as for %s. */ -/* (Note that %c,%C, and %S were already taken.) */ -/* 2. The format string is represented as a CORD. */ -/* 3. CORD_sprintf and CORD_vsprintf assign the result through the 1st */ /* argument. Unlike their ANSI C versions, there is no need to guess */ -/* the correct buffer size. */ -/* 4. Most of the conversions are implement through the native */ -/* vsprintf. Hence they are usually no faster, and */ -/* idiosyncracies of the native printf are preserved. However, */ -/* CORD arguments to CORD_sprintf and CORD_vsprintf are NOT copied; */ -/* the result shares the original structure. This may make them */ -/* very efficient in some unusual applications. */ -/* The format string is copied. */ -/* All functions return the number of characters generated or -1 on */ -/* error. This complies with the ANSI standard, but is inconsistent */ -/* with some older implementations of sprintf. */ - -/* The implementation of these is probably less portable than the rest */ -/* of this package. */ - -#ifndef CORD_NO_IO - -#include - -int CORD_sprintf(CORD * out, CORD format, ...); -int CORD_vsprintf(CORD * out, CORD format, va_list args); -int CORD_fprintf(FILE * f, CORD format, ...); -int CORD_vfprintf(FILE * f, CORD format, va_list args); -int CORD_printf(CORD format, ...); -int CORD_vprintf(CORD format, va_list args); - -#endif /* CORD_NO_IO */ - # endif /* CORD_H */