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
30 #include "memcasecmp.h"
38 #include "vsnprintf.h"
39 #include "xvasprintf.h"
45 #define strrchr rindex
50 void buf_reverse (char *, size_t);
51 char *buf_find_reverse (const char *, size_t, const char *, size_t);
52 int buf_compare_case (const char *, const char *, size_t);
53 int buf_compare_rpad (const char *, size_t, const char *, size_t);
54 void buf_copy_rpad (char *, size_t, const char *, size_t);
55 void buf_copy_str_lpad (char *, size_t, const char *);
56 void buf_copy_str_rpad (char *, size_t, const char *);
58 int str_compare_rpad (const char *, const char *);
59 void str_copy_rpad (char *, size_t, const char *);
60 void str_copy_trunc (char *, size_t, const char *);
61 void str_copy_buf_trunc (char *, size_t, const char *, size_t);
62 void str_uppercase (char *);
63 void str_lowercase (char *);
65 /* Fixed-length strings. */
72 void ls_create (struct fixed_string *, const char *);
73 void ls_create_buffer (struct fixed_string *,
74 const char *, size_t len);
75 void ls_init (struct fixed_string *, const char *, size_t);
76 void ls_shallow_copy (struct fixed_string *, const struct fixed_string *);
77 void ls_destroy (struct fixed_string *);
79 void ls_null (struct fixed_string *);
80 int ls_null_p (const struct fixed_string *);
81 int ls_empty_p (const struct fixed_string *);
83 size_t ls_length (const struct fixed_string *);
84 char *ls_c_str (const struct fixed_string *);
85 char *ls_end (const struct fixed_string *);
89 ls_length (const struct fixed_string *st)
95 ls_c_str (const struct fixed_string *st)
101 ls_end (const struct fixed_string *st)
103 return st->string + st->length;
107 /* Variable length strings. */
111 size_t length; /* Length, not including a null terminator. */
112 size_t capacity; /* Allocated capacity, not including one
113 extra byte allocated for null terminator. */
114 char *string; /* String data, not necessarily null
118 /* Constructors, destructors. */
119 void ds_create (struct string *, const char *);
120 void ds_init (struct string *, size_t);
121 void ds_destroy (struct string *);
122 void ds_swap (struct string *, struct string *);
124 /* Copy, shrink, extend. */
125 void ds_replace (struct string *, const char *);
126 void ds_clear (struct string *);
127 void ds_extend (struct string *, size_t);
128 void ds_shrink (struct string *);
129 void ds_truncate (struct string *, size_t);
130 void ds_rpad (struct string *, size_t length, char pad);
131 int ds_rtrim_spaces (struct string *);
132 int ds_ltrim_spaces (struct string *st);
134 bool ds_chomp (struct string *, char);
137 bool ds_is_empty (const struct string *);
138 size_t ds_length (const struct string *);
139 char *ds_c_str (const struct string *);
140 char *ds_data (const struct string *);
141 char *ds_end (const struct string *);
142 size_t ds_capacity (const struct string *);
143 int ds_first (const struct string *);
144 int ds_last (const struct string *);
148 int ds_gets (struct string *, FILE *);
149 int ds_get_config_line (FILE *, struct string *, struct file_locator *);
152 void ds_putc (struct string *, int ch);
153 void ds_puts (struct string *, const char *);
154 void ds_concat (struct string *, const char *, size_t);
155 void ds_vprintf (struct string *st, const char *, va_list);
156 void ds_printf (struct string *, const char *, ...)
157 PRINTF_FORMAT (2, 3);
161 ds_putc (struct string *st, int ch)
163 if (st->length == st->capacity)
164 ds_extend (st, st->length + 1);
165 st->string[st->length++] = ch;
169 ds_length (const struct string *st)
175 ds_c_str (const struct string *st)
178 ((char *) st->string)[st->length] = '\0';
183 ds_data (const struct string *st)
189 ds_end (const struct string *st)
191 return st->string + st->length;
195 #define nsprintf sprintf
196 #define nvsprintf vsprintf
198 /* Formats FORMAT into DST, as with sprintf(), and returns the
199 address of the terminating null written to DST. */
201 spprintf (char *dst, const char *format, ...)
206 va_start (args, format);
207 count = nvsprintf (dst, format, args);
213 int ds_find(const struct string *st, const char cs[]);
215 int ds_n_find(const struct string *st, const char cs[]);
217 void ds_create_substr(struct string *dst, const struct string *src,
218 int first, int last);