2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
8 #include <toollib/vstring.h>
11 VS_New (const char * ini
)
13 String str
= new (struct _String
);
17 int len
= strlen (ini
) + 1;
19 str
->maxlen
= ALIGN(len
,8);
20 str
->buffer
= xmalloc (str
->maxlen
);
23 strcpy (str
->buffer
, ini
);
28 str
->buffer
= xmalloc (str
->maxlen
);
38 VS_Delete (String str
)
51 VS_AppendChar (String str
, int c
)
53 if (str
->len
+ 2 >= str
->maxlen
)
57 str
->buffer
= xrealloc (str
->buffer
, str
->maxlen
);
60 str
->buffer
[str
->len
++] = c
;
61 str
->buffer
[str
->len
] = 0;
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
);
81 VS_ToUpper (String str
)
85 for (t
=0; t
<str
->len
; t
++)
86 str
->buffer
[t
] = toupper (str
->buffer
[t
]);
90 VS_ToLower (String str
)
94 for (t
=0; t
<str
->len
; t
++)
95 str
->buffer
[t
] = tolower (str
->buffer
[t
]);
99 VS_SubString (const char * str
, int begin
, int len
)
107 return VS_New (NULL
);
119 nstr
= new (struct _String
);
121 nstr
->maxlen
= ALIGN(n
+1,8);
122 nstr
->buffer
= xmalloc (nstr
->maxlen
);
125 strncpy (nstr
->buffer
, str
+ begin
, n
);
132 strdupsub (const char * str
, int begin
, int len
)
142 if (begin
>= n
|| len
<= 0)
150 nstr
= xmalloc (n
+1);
152 strncpy (nstr
, str
+ begin
, n
);
159 stripquotes (const char * str
)
168 len
= strlen (str
+ begin
);
176 return strdupsub (str
, begin
, len
);
179 return xstrdup (str
);
183 stripws (const char * str
)
188 for (begin
=0; isspace (str
[begin
]); begin
++);
190 len
= strlen (str
+ begin
);
192 for (len
--; len
> 0 && isspace (str
[begin
+ len
]); len
--);
196 return strdupsub (str
, begin
, len
);
200 stripwsq (const char * str
)
205 for (begin
=0; isspace (str
[begin
]); begin
++);
207 if (str
[begin
] == '"')
210 len
= strlen (str
+ begin
);
212 for (len
--; len
> 0 && isspace (str
[begin
+ len
]); len
--);
214 if (str
[begin
+ len
] == '"')
219 return strdupsub (str
, begin
, len
);
223 strupper (char * str
)
227 for (ptr
=str
; *ptr
; ptr
++)
228 *ptr
= toupper (*ptr
);
234 strlower (char * str
)
238 for (ptr
=str
; *ptr
; ptr
++)
239 *ptr
= tolower (*ptr
);