You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
#if !str_h
#define str_h 1
char *strtok_r (char *, const char *, char **);
#endif
-#if !HAVE_STPCPY && !__linux__
+#if !HAVE_STPCPY
char *stpcpy (char *dest, const char *src);
#endif
void st_bare_pad_copy (char *dest, const char *src, size_t n);
void st_bare_pad_len_copy (char *dest, const char *src, size_t n, size_t len);
void st_pad_copy (char *dest, const char *src, size_t n);
+void st_trim_copy (char *dest, const char *src, size_t n);
+void st_uppercase (char *);
\f
-/* Lengthed strings. */
-struct len_string
+/* Fixed-length strings. */
+struct fixed_string
{
char *string;
size_t length;
};
-struct pool;
-void ls_create (struct pool *, struct len_string *, const char *);
-void ls_create_buffer (struct pool *, struct len_string *,
+void ls_create (struct fixed_string *, const char *);
+void ls_create_buffer (struct fixed_string *,
const char *, size_t len);
-void ls_init (struct len_string *, const char *, size_t);
-void ls_shallow_copy (struct len_string *, const struct len_string *);
-void ls_destroy (struct pool *, struct len_string *);
+void ls_init (struct fixed_string *, const char *, size_t);
+void ls_shallow_copy (struct fixed_string *, const struct fixed_string *);
+void ls_destroy (struct fixed_string *);
-void ls_null (struct len_string *);
-int ls_null_p (const struct len_string *);
-int ls_empty_p (const struct len_string *);
+void ls_null (struct fixed_string *);
+int ls_null_p (const struct fixed_string *);
+int ls_empty_p (const struct fixed_string *);
-size_t ls_length (const struct len_string *);
-char *ls_value (const struct len_string *);
-char *ls_end (const struct len_string *);
+size_t ls_length (const struct fixed_string *);
+char *ls_c_str (const struct fixed_string *);
+char *ls_end (const struct fixed_string *);
+
+#if __GNUC__ > 1
+extern inline size_t
+ls_length (const struct fixed_string *st)
+{
+ return st->length;
+}
+
+extern inline char *
+ls_c_str (const struct fixed_string *st)
+{
+ return st->string;
+}
+
+extern inline char *
+ls_end (const struct fixed_string *st)
+{
+ return st->string + st->length;
+}
+#endif
\f
-/* Dynamic strings. */
+/* Variable length strings. */
struct string
{
- struct pool *pool;
- size_t length;
- size_t size;
- char *string;
+ 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. */
};
-void ds_create (struct pool *, struct string *, const char *);
-void ds_init (struct pool *, struct string *, size_t size);
-void ds_replace (struct string *, const char *);
+/* Constructors, destructors. */
+void ds_create (struct string *, const char *);
+void ds_init (struct string *, size_t);
void ds_destroy (struct string *);
+
+/* Copy, shrink, extend. */
+void ds_replace (struct string *, const char *);
void ds_clear (struct string *);
-void ds_extend (struct string *, size_t min_size);
+void ds_extend (struct string *, size_t);
void ds_shrink (struct string *);
-void ds_truncate (struct string *, size_t length);
+void ds_truncate (struct string *, size_t);
+void ds_rpad (struct string *, size_t length, char pad);
+/* Inspectors. */
size_t ds_length (const struct string *);
-char *ds_value (const struct string *);
+char *ds_c_str (const struct string *);
+char *ds_data (const struct string *);
char *ds_end (const struct string *);
-size_t ds_size (const struct string *);
+size_t ds_capacity (const struct string *);
+/* File input. */
struct file_locator;
-int ds_getline (struct string *st, FILE *stream);
+int ds_gets (struct string *, FILE *);
int ds_get_config_line (FILE *, struct string *, struct file_locator *);
-void ds_putchar (struct string *, int ch);
-void ds_concat (struct string *, const char *);
-void ds_concat_buffer (struct string *, const char *buf, size_t len);
-void ds_vprintf (struct string *st, const char *format, va_list args);
+
+/* Append. */
+void ds_putc (struct string *, int ch);
+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);
#if __GNUC__ > 1
extern inline void
-ds_putchar (struct string *st, int ch)
+ds_putc (struct string *st, int ch)
{
- if (st->length == st->size)
+ if (st->length == st->capacity)
ds_extend (st, st->length + 1);
st->string[st->length++] = ch;
}
}
extern inline char *
-ds_value (const struct string *st)
+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)
+{
+ return st->string;
+}
+
extern inline char *
ds_end (const struct string *st)
{