1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "memcasecmp.h"
36 #include "vsnprintf.h"
37 #include "xvasprintf.h"
43 #define strrchr rindex
48 void buf_reverse (char *, size_t);
49 char *buf_find_reverse (const char *, size_t, const char *, size_t);
50 int buf_compare_case (const char *, const char *, size_t);
51 int buf_compare_rpad (const char *, size_t, const char *, size_t);
52 void buf_copy_rpad (char *, size_t, const char *, size_t);
53 void buf_copy_str_lpad (char *, size_t, const char *);
54 void buf_copy_str_rpad (char *, size_t, const char *);
56 int str_compare_rpad (const char *, const char *);
57 void str_copy_rpad (char *, size_t, const char *);
58 void str_copy_trunc (char *, size_t, const char *);
59 void str_copy_buf_trunc (char *, size_t, const char *, size_t);
60 void str_uppercase (char *);
61 void str_lowercase (char *);
63 /* Fixed-length strings. */
70 void ls_create (struct fixed_string *, const char *);
71 void ls_create_buffer (struct fixed_string *,
72 const char *, size_t len);
73 void ls_init (struct fixed_string *, const char *, size_t);
74 void ls_shallow_copy (struct fixed_string *, const struct fixed_string *);
75 void ls_destroy (struct fixed_string *);
77 void ls_null (struct fixed_string *);
78 int ls_null_p (const struct fixed_string *);
79 int ls_empty_p (const struct fixed_string *);
81 size_t ls_length (const struct fixed_string *);
82 char *ls_c_str (const struct fixed_string *);
83 char *ls_end (const struct fixed_string *);
87 ls_length (const struct fixed_string *st)
93 ls_c_str (const struct fixed_string *st)
99 ls_end (const struct fixed_string *st)
101 return st->string + st->length;
105 /* Variable length strings. */
109 size_t length; /* Length, not including a null terminator. */
110 size_t capacity; /* Allocated capacity, not including one
111 extra byte allocated for null terminator. */
112 char *string; /* String data, not necessarily null
116 /* Constructors, destructors. */
117 void ds_create (struct string *, const char *);
118 void ds_init (struct string *, size_t);
119 void ds_destroy (struct string *);
120 void ds_swap (struct string *, struct string *);
122 /* Copy, shrink, extend. */
123 void ds_replace (struct string *, const char *);
124 void ds_clear (struct string *);
125 void ds_extend (struct string *, size_t);
126 void ds_shrink (struct string *);
127 void ds_truncate (struct string *, size_t);
128 void ds_rpad (struct string *, size_t length, char pad);
129 int ds_rtrim_spaces (struct string *);
130 bool ds_chomp (struct string *, char);
133 bool ds_is_empty (const struct string *);
134 size_t ds_length (const struct string *);
135 char *ds_c_str (const struct string *);
136 char *ds_data (const struct string *);
137 char *ds_end (const struct string *);
138 size_t ds_capacity (const struct string *);
139 int ds_first (const struct string *);
140 int ds_last (const struct string *);
144 int ds_gets (struct string *, FILE *);
145 int ds_get_config_line (FILE *, struct string *, struct file_locator *);
148 void ds_putc (struct string *, int ch);
149 void ds_puts (struct string *, const char *);
150 void ds_concat (struct string *, const char *, size_t);
151 void ds_vprintf (struct string *st, const char *, va_list);
152 void ds_printf (struct string *, const char *, ...)
153 PRINTF_FORMAT (2, 3);
157 ds_putc (struct string *st, int ch)
159 if (st->length == st->capacity)
160 ds_extend (st, st->length + 1);
161 st->string[st->length++] = ch;
165 ds_length (const struct string *st)
171 ds_c_str (const struct string *st)
173 ((char *) st->string)[st->length] = '\0';
178 ds_data (const struct string *st)
184 ds_end (const struct string *st)
186 return st->string + st->length;
190 #define nsprintf sprintf
191 #define nvsprintf vsprintf
193 /* Formats FORMAT into DST, as with sprintf(), and returns the
194 address of the terminating null written to DST. */
196 spprintf (char *dst, const char *format, ...)
201 va_start (args, format);
202 count = nvsprintf (dst, format, args);