X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Flibpspp%2Fstr.h;h=cd7cdb05ad754f7d2cc9697e8c0dcad322519b8d;hb=945fd370f9fb880b310fb88f868ad47c2ae84533;hp=0b50b0310ee2d166a99d8340427f42b7ac27ee98;hpb=cf4da7ffcb1c9f1016c4fa013deb8ce40c431e19;p=pspp-builds.git diff --git a/src/libpspp/str.h b/src/libpspp/str.h index 0b50b031..cd7cdb05 100644 --- a/src/libpspp/str.h +++ b/src/libpspp/str.h @@ -20,11 +20,13 @@ #if !str_h #define str_h 1 +#include #include #include #include #include +#include "compiler.h" #include "memcasecmp.h" #include "memmem.h" #include "snprintf.h" @@ -59,6 +61,8 @@ void str_copy_trunc (char *, size_t, const char *); void str_copy_buf_trunc (char *, size_t, const char *, size_t); void str_uppercase (char *); void str_lowercase (char *); + +char *spprintf (char *dst, const char *format, ...); /* Fixed-length strings. */ struct fixed_string @@ -106,28 +110,45 @@ ls_end (const struct fixed_string *st) struct string { + char *string; /* String data, not necessarily null terminated. */ size_t length; /* Length, not including a null terminator. */ size_t capacity; /* Allocated capacity, not including one extra byte allocated for null terminator. */ - char *string; /* String data, not necessarily null - terminated. */ }; +#define DS_INITIALIZER {NULL, 0, 0} + /* Constructors, destructors. */ +void ds_init (struct string *); +void ds_init_substring (struct string *, + const struct string *src, size_t start, size_t cnt); void ds_create (struct string *, const char *); -void ds_init (struct string *, size_t); void ds_destroy (struct string *); void ds_swap (struct string *, struct string *); -/* Copy, shrink, extend. */ -void ds_replace (struct string *, const char *); +/* Replacement. */ +void ds_assign_string (struct string *, const struct string *); +void ds_assign_substring (struct string *, + const struct string *, size_t start, size_t cnt); +void ds_assign_buffer (struct string *, const char *, size_t); +void ds_assign_c_str (struct string *, const char *); + +/* Shrink, extend. */ void ds_clear (struct string *); void ds_extend (struct string *, size_t); void ds_shrink (struct string *); void ds_truncate (struct string *, size_t); + +/* Padding, trimming. */ void ds_rpad (struct string *, size_t length, char pad); int ds_rtrim_spaces (struct string *); +int ds_ltrim_spaces (struct string *); +void ds_trim_spaces (struct string *); bool ds_chomp (struct string *, char); +bool ds_separate (const struct string *src, struct string *token, + const char *delimiters, size_t *save_idx); +bool ds_tokenize (const struct string *src, struct string *token, + const char *delimiters, size_t *save_idx); /* Inspectors. */ bool ds_is_empty (const struct string *); @@ -136,21 +157,25 @@ char *ds_c_str (const struct string *); char *ds_data (const struct string *); char *ds_end (const struct string *); size_t ds_capacity (const struct string *); +int ds_at (const struct string *, size_t idx); int ds_first (const struct string *); int ds_last (const struct string *); +size_t ds_span (const struct string *st, size_t ofs, const char skip_set[]); +size_t ds_cspan (const struct string *st, size_t ofs, const char stop_set[]); /* File input. */ -struct file_locator; -int ds_gets (struct string *, FILE *); -int ds_get_config_line (FILE *, struct string *, struct file_locator *); +bool ds_gets (struct string *, FILE *); +bool ds_get_config_line (FILE *, struct string *, int *line_number); /* Append. */ void ds_putc (struct string *, int ch); +void ds_putc_multiple (struct string *, int ch, size_t); void ds_puts (struct string *, const char *); void ds_concat (struct string *, const char *, size_t); void ds_vprintf (struct string *st, const char *, va_list); void ds_printf (struct string *, const char *, ...) PRINTF_FORMAT (2, 3); +char *ds_append_uninit (struct string *st, size_t incr); #if __GNUC__ > 1 extern inline void @@ -167,13 +192,6 @@ ds_length (const struct string *st) return st->length; } -extern inline char * -ds_c_str (const struct string *st) -{ - ((char *) st->string)[st->length] = '\0'; - return st->string; -} - extern inline char * ds_data (const struct string *st) { @@ -187,22 +205,4 @@ ds_end (const struct string *st) } #endif -#define nsprintf sprintf -#define nvsprintf vsprintf - -/* Formats FORMAT into DST, as with sprintf(), and returns the - address of the terminating null written to DST. */ -static inline char * -spprintf (char *dst, const char *format, ...) -{ - va_list args; - int count; - - va_start (args, format); - count = nvsprintf (dst, format, args); - va_end (args); - - return dst + count; -} - #endif /* str_h */