Changeset 815 for trunk/superstring/include/superstring/superstring.h
- Timestamp:
- 03/28/08 22:32:22 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/superstring/include/superstring/superstring.h
r812 r815 114 114 }; 115 115 116 typedef struct _superstring_jumbo_ * superstring_jumbo;117 116 typedef struct _superstring_small_ * superstring; 118 117 … … 198 197 /* Get the C representation of a superstring value. */ 199 198 static inline const unsigned char *ss_cstring(superstring str) { 200 if (str == NULL) 199 if (str == NULL) { 200 ss_errno = SS_ERROR_INVALID_PARAMETER; 201 201 return NULL; 202 202 } 203 204 ss_errno = SS_ERROR_SUCCESS; 203 205 return (str->flags & SUPERSTRING_JUMBO ? 204 206 ((const unsigned char *)str) + sizeof(struct _superstring_jumbo_) : … … 208 210 /* Retrieve the length or size of a string */ 209 211 static inline size_t ss_length(superstring str) { 210 if (str == NULL) 212 if (str == NULL) { 213 ss_errno = SS_ERROR_INVALID_PARAMETER; 211 214 return 0; /* bad answer.. */ 212 215 } 216 217 ss_errno = SS_ERROR_SUCCESS; 213 218 return (size_t)(str->flags & SUPERSTRING_JUMBO ? 214 ((s uperstring_jumbo)str)->len :219 ((struct _superstring_jumbo_ *)str)->len : 215 220 str->len); 216 221 } 217 222 218 223 static inline size_t ss_size(superstring str) { 219 if (str == NULL) 224 if (str == NULL) { 225 ss_errno = SS_ERROR_INVALID_PARAMETER; 220 226 return 0; /* bad answer.. */ 221 227 } 228 229 ss_errno = SS_ERROR_SUCCESS; 222 230 return (size_t)(str->flags & SUPERSTRING_JUMBO ? 223 ((s uperstring_jumbo)str)->size :231 ((struct _superstring_jumbo_ *)str)->size : 224 232 str->size); 233 } 234 235 /* Retrieve or set the character at 'offset' in the string */ 236 static 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 } 245 static 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); 225 255 } 226 256 … … 249 279 250 280 /*****************************************************************************/ 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. */ 284 int ss_trim_ex(superstring str, size_t length, char fill); 285 static 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) 293 int ss_append_ex(superstring *lstr, superstring rstr, int flags, size_t length); 294 295 /* Append a string with no concern for length */ 296 static inline int ss_append(superstring *lstr, superstring rstr) { 297 return ss_append_ex(lstr, rstr, 0, 0); 298 } 299 static 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' */ 304 static inline int ss_nappend(superstring *lstr, superstring rstr, 305 size_t length) { 306 return ss_append_ex(lstr, rstr, 0, length); 307 } 308 static 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 /*****************************************************************************/ 251 314 /* Comparison function, with various wrappers: 252 315 - 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.
