Ignore:
Timestamp:
03/28/08 22:32:22 (4 years ago)
Author:
wd
Message:

Interrim update for superstring bits.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/superstring/include/superstring/superstring.h

    r812 r815  
    114114}; 
    115115 
    116 typedef struct _superstring_jumbo_ * superstring_jumbo; 
    117116typedef struct _superstring_small_ * superstring; 
    118117 
     
    198197/* Get the C representation of a superstring value. */ 
    199198static inline const unsigned char *ss_cstring(superstring str) { 
    200     if (str == NULL) 
     199    if (str == NULL) { 
     200        ss_errno = SS_ERROR_INVALID_PARAMETER; 
    201201        return NULL; 
    202  
     202    } 
     203 
     204    ss_errno = SS_ERROR_SUCCESS; 
    203205    return (str->flags & SUPERSTRING_JUMBO ? 
    204206            ((const unsigned char *)str) + sizeof(struct _superstring_jumbo_) : 
     
    208210/* Retrieve the length or size of a string */ 
    209211static inline size_t ss_length(superstring str) { 
    210     if (str == NULL) 
     212    if (str == NULL) { 
     213        ss_errno = SS_ERROR_INVALID_PARAMETER; 
    211214        return 0; /* bad answer.. */ 
    212  
     215    } 
     216 
     217    ss_errno = SS_ERROR_SUCCESS; 
    213218    return (size_t)(str->flags & SUPERSTRING_JUMBO ? 
    214             ((superstring_jumbo)str)->len : 
     219            ((struct _superstring_jumbo_ *)str)->len : 
    215220            str->len); 
    216221} 
    217222 
    218223static inline size_t ss_size(superstring str) { 
    219     if (str == NULL) 
     224    if (str == NULL) { 
     225        ss_errno = SS_ERROR_INVALID_PARAMETER; 
    220226        return 0; /* bad answer.. */ 
    221  
     227    } 
     228 
     229    ss_errno = SS_ERROR_SUCCESS; 
    222230    return (size_t)(str->flags & SUPERSTRING_JUMBO ? 
    223             ((superstring_jumbo)str)->size : 
     231            ((struct _superstring_jumbo_ *)str)->size : 
    224232            str->size); 
     233} 
     234 
     235/* Retrieve or set the character at 'offset' in the string */ 
     236static inline unsigned char ss_char(superstring str, size_t index) { 
     237    if (str == NULL || index >= str->len) { 
     238        ss_errno = SS_ERROR_INVALID_PARAMETER; 
     239        return 0; 
     240    } 
     241    return (str->flags & SUPERSTRING_JUMBO ? 
     242            *((unsigned char *)str + sizeof(struct _superstring_jumbo_) + index) : 
     243            *((unsigned char *)str + sizeof(struct _superstring_small_) + index)); 
     244} 
     245static inline int ss_setchar(superstring str, size_t index, char c) { 
     246    if (str == NULL || index >= str->len) 
     247        return (ss_errno = SS_ERROR_INVALID_PARAMETER); 
     248 
     249    if (str->flags & SUPERSTRING_JUMBO) 
     250        *((unsigned char *)str + sizeof(struct _superstring_jumbo_) + index) = c; 
     251    else 
     252        *((unsigned char *)str + sizeof(struct _superstring_small_) + index) = c; 
     253 
     254    return (ss_errno = SS_ERROR_SUCCESS); 
    225255} 
    226256 
     
    249279 
    250280/*****************************************************************************/ 
     281/* Shorten or lengthen a superstring by trimming or appending data.  For 
     282 * trim, if the length is greater than the current length spaces (or a 
     283 * specified character) are appended as necessary. */ 
     284int ss_trim_ex(superstring str, size_t length, char fill); 
     285static inline int ss_trim(superstring str, size_t length) { 
     286    return ss_trim_ex(str, length, ' '); 
     287} 
     288 
     289/*****************************************************************************/ 
     290/* Append data to a superstring.  There are several variants provided which 
     291 * allow for setting maximum string length, using C strings, etc */ 
     292#define SS_APPEND_CSTRING           (0x80000000) 
     293int ss_append_ex(superstring *lstr, superstring rstr, int flags, size_t length); 
     294 
     295/* Append a string with no concern for length */ 
     296static inline int ss_append(superstring *lstr, superstring rstr) { 
     297    return ss_append_ex(lstr, rstr, 0, 0); 
     298} 
     299static inline int ss_append_cs(superstring *lstr, const unsigned char *rstr) { 
     300    return ss_append_ex(lstr, (superstring)rstr, SS_APPEND_CSTRING, 0); 
     301} 
     302 
     303/* Append a string but do not allow lstr to exceed 'length' */ 
     304static inline int ss_nappend(superstring *lstr, superstring rstr, 
     305        size_t length) { 
     306    return ss_append_ex(lstr, rstr, 0, length); 
     307} 
     308static inline int ss_nappend_cs(superstring *lstr, const unsigned char *rstr, 
     309        size_t length) { 
     310    return ss_append_ex(lstr, (superstring)rstr, SS_APPEND_CSTRING, length); 
     311} 
     312 
     313/*****************************************************************************/ 
    251314/* Comparison function, with various wrappers: 
    252315   - ss_compare_ex: Compare with flags and length.  If length is 0 it will be 
Note: See TracChangeset for help on using the changeset viewer.