Test initialisation of MUIA_List_AdjustWidth and MUIA_List_AdjustHeight, and
[AROS.git] / tools / toollib / vstring.c
blob7102ba6d8ee1dff47f96d56f742448957877529b
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
7 #include <ctype.h>
8 #include <toollib/vstring.h>
10 String
11 VS_New (const char * ini)
13 String str = new (struct _String);
15 if (ini && *ini)
17 int len = strlen (ini) + 1;
19 str->maxlen = ALIGN(len,8);
20 str->buffer = xmalloc (str->maxlen);
21 str->len = len;
23 strcpy (str->buffer, ini);
25 else
27 str->maxlen = 32;
28 str->buffer = xmalloc (str->maxlen);
29 str->len = 0;
31 str->buffer[0] = 0;
34 return str;
37 void
38 VS_Delete (String str)
40 cfree (str->buffer);
41 xfree (str);
44 void
45 VS_Clear (String str)
47 str->len = 0;
50 void
51 VS_AppendChar (String str, int c)
53 if (str->len + 2 >= str->maxlen)
55 str->maxlen += 32;
57 str->buffer = xrealloc (str->buffer, str->maxlen);
60 str->buffer[str->len ++] = c;
61 str->buffer[str->len] = 0;
64 void
65 VS_AppendString (String str, const char * app)
67 int len = strlen (app);
69 if (str->len + len + 1 >= str->maxlen)
71 str->maxlen = ALIGN(str->len+len+1,8);
73 str->buffer = xrealloc (str->buffer, str->maxlen);
76 strcpy (str->buffer + str->len, app);
77 str->len += len;
80 void
81 VS_ToUpper (String str)
83 int t;
85 for (t=0; t<str->len; t++)
86 str->buffer[t] = toupper (str->buffer[t]);
89 void
90 VS_ToLower (String str)
92 int t;
94 for (t=0; t<str->len; t++)
95 str->buffer[t] = tolower (str->buffer[t]);
98 String
99 VS_SubString (const char * str, int begin, int len)
101 int n;
102 String nstr;
104 n = strlen (str);
106 if (begin >= n)
107 return VS_New (NULL);
109 if (len == -1)
110 n -= begin;
111 else
113 if (begin+len > n)
114 n -= begin;
115 else
116 n = len;
119 nstr = new (struct _String);
121 nstr->maxlen = ALIGN(n+1,8);
122 nstr->buffer = xmalloc (nstr->maxlen);
123 nstr->len = n;
125 strncpy (nstr->buffer, str + begin, n);
126 nstr->buffer[n] = 0;
128 return nstr;
131 char *
132 strdupsub (const char * str, int begin, int len)
134 char * nstr;
135 int n;
137 if (!str)
138 return NULL;
140 n = strlen (str);
142 if (begin >= n || len <= 0)
143 return strdup ("");
145 if (begin+len > n)
146 n -= begin;
147 else
148 n = len;
150 nstr = xmalloc (n+1);
152 strncpy (nstr, str + begin, n);
153 nstr[n] = 0;
155 return nstr;
158 char *
159 stripquotes (const char * str)
161 int begin;
162 int len;
164 if (*str == '"')
166 begin = 1;
168 len = strlen (str + begin);
170 if (str[len] == '"')
171 len --;
173 if (len <= 0)
174 len = -1;
176 return strdupsub (str, begin, len);
179 return xstrdup (str);
182 char *
183 stripws (const char * str)
185 int begin;
186 int len;
188 for (begin=0; isspace (str[begin]); begin++);
190 len = strlen (str + begin);
192 for (len--; len > 0 && isspace (str[begin + len]); len --);
194 len ++;
196 return strdupsub (str, begin, len);
199 char *
200 stripwsq (const char * str)
202 int begin;
203 int len;
205 for (begin=0; isspace (str[begin]); begin++);
207 if (str[begin] == '"')
208 begin ++;
210 len = strlen (str + begin);
212 for (len--; len > 0 && isspace (str[begin + len]); len --);
214 if (str[begin + len] == '"')
215 len --;
217 len ++;
219 return strdupsub (str, begin, len);
222 char *
223 strupper (char * str)
225 char * ptr;
227 for (ptr=str; *ptr; ptr++)
228 *ptr = toupper (*ptr);
230 return str;
233 char *
234 strlower (char * str)
236 char *ptr;
238 for (ptr=str; *ptr; ptr++)
239 *ptr = tolower (*ptr);
241 return str;