C Standard Library Extensions  1.2.3
cxstrutils.h
1 /*
2  * This file is part of the ESO C Extension Library
3  * Copyright (C) 2001-2017 European Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
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 St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef CX_STRUTILS_H
21 #define CX_STRUTILS_H
22 
23 #include <stdarg.h>
24 #include <cxtypes.h>
25 
26 CX_BEGIN_DECLS
27 
28 /*
29  * String comparison functions.
30  */
31 
32 cxint cx_strcasecmp(const cxchar *, const cxchar *);
33 cxint cx_strncasecmp(const cxchar *, const cxchar *, cxsize);
34 cxint cx_strempty(const cxchar *, const cxchar *);
35 
36 
37 /*
38  * Utility functions modifing their string argument
39  */
40 
41 cxchar *cx_strlower(cxchar *);
42 cxchar *cx_strupper(cxchar *);
43 
44 cxchar *cx_strtrim(cxchar *);
45 cxchar *cx_strrtrim(cxchar *);
46 cxchar *cx_strstrip(cxchar *);
47 
48 
49 /*
50  * Utility functions which do not create a new string
51  */
52 
53 cxchar *cx_strskip(const cxchar *, cxint (*)(cxint));
54 
55 
56 /*
57  * Utilities returning a newly allocated string.
58  */
59 
60 cxchar *cx_strdup(const cxchar *);
61 cxchar *cx_strndup(const cxchar *, cxsize);
62 cxchar *cx_strvdupf(const cxchar *, va_list) CX_GNUC_PRINTF(1, 0);
63 
64 cxchar *cx_stpcpy(cxchar *, const cxchar *);
65 
66 cxchar **cx_strsplit(const cxchar *, const cxchar *, cxint);
67 void cx_strfreev(cxchar **sarray);
68 
69 cxchar *cx_strjoinv(const cxchar *, cxchar **);
70 
71 CX_END_DECLS
72 
73 #endif /* CX_STRUTILS_H */
cx_strvdupf
cxchar * cx_strvdupf(const cxchar *format, va_list args)
Create a string from a variable-length argument list under format control.
Definition: cxstrutils.c:556
cx_strtrim
cxchar * cx_strtrim(cxchar *string)
Remove leading whitespace characters from a string.
Definition: cxstrutils.c:396
cx_stpcpy
cxchar * cx_stpcpy(cxchar *dest, const cxchar *src)
Copy a string returning a pointer to its end.
Definition: cxstrutils.c:588
cx_vasprintf
cxint cx_vasprintf(cxchar **string, const cxchar *format, va_list args)
Write formatted output to a newly allocated string with a variable-length argument list.
Definition: cxutils.c:380
cx_strncasecmp
cxint cx_strncasecmp(const cxchar *s1, const cxchar *s2, cxsize n)
Compare the first n characters of two strings ignoring the case of ASCII characters.
Definition: cxstrutils.c:246
cx_strndup
cxchar * cx_strndup(const cxchar *string, cxsize n)
Duplicate the first n charactes of a string.
Definition: cxstrutils.c:522
cx_slist_new
cx_slist * cx_slist_new(void)
Create a new list without any elements.
Definition: cxslist.c:710
cx_slist_get
cxptr cx_slist_get(const cx_slist *list, cx_slist_const_iterator position)
Get the data at a given iterator position.
Definition: cxslist.c:962
cx_strjoinv
cxchar * cx_strjoinv(const cxchar *separator, cxchar **sarray)
Join strings from an array of strings.
Definition: cxstrutils.c:736
cx_malloc
cxptr cx_malloc(cxsize nbytes)
Allocate nbytes bytes.
Definition: cxmemory.c:280
cx_slist_delete
void cx_slist_delete(cx_slist *list)
Destroy a list.
Definition: cxslist.c:734
cx_strlower
cxchar * cx_strlower(cxchar *s)
Convert all uppercase characters in a string into lowercase characters.
Definition: cxstrutils.c:332
cx_strempty
cxint cx_strempty(const cxchar *string, const cxchar *pattern)
Test if a string represents an empty string.
Definition: cxstrutils.c:298
cx_slist_begin
cx_slist_iterator cx_slist_begin(const cx_slist *list)
Get list iterator to the beginning of a list.
Definition: cxslist.c:580
cx_free
void cx_free(cxptr memory)
Memory block deallocation.
Definition: cxmemory.c:486
cx_calloc
cxptr cx_calloc(cxsize natoms, cxsize nbytes)
Allocate memory for natoms elements of size size.
Definition: cxmemory.c:380
cx_slist_next
cx_slist_iterator cx_slist_next(const cx_slist *list, cx_slist_const_iterator position)
Get a list iterator to the next list element.
Definition: cxslist.c:632
cx_strfreev
void cx_strfreev(cxchar **sarray)
Deallocate a NULL terminated string array.
Definition: cxstrutils.c:609
cx_strskip
cxchar * cx_strskip(const cxchar *string, int(*ctype)(int))
Locate the first character in a string that does not belong to a given character class.
Definition: cxstrutils.c:472
cx_slist_push_front
void cx_slist_push_front(cx_slist *list, cxcptr data)
Insert data at the beginning of a list.
Definition: cxslist.c:1029
cx_strupper
cxchar * cx_strupper(cxchar *s)
Convert all lowercase characters in a string into uppercase characters.
Definition: cxstrutils.c:365
cx_strstrip
cxchar * cx_strstrip(cxchar *string)
Remove leading and trailing whitespace characters from a string.
Definition: cxstrutils.c:442
cx_strcasecmp
cxint cx_strcasecmp(const cxchar *s1, const cxchar *s2)
Compare two strings ignoring the case of ASCII characters.
Definition: cxstrutils.c:203
cx_strsplit
cxchar ** cx_strsplit(const cxchar *string, const cxchar *delimiter, cxint max_tokens)
Split a string into pieces at a given delimiter.
Definition: cxstrutils.c:654
cx_strrtrim
cxchar * cx_strrtrim(cxchar *string)
Remove trailing whitespace characters from a string.
Definition: cxstrutils.c:419
cx_slist_end
cx_slist_iterator cx_slist_end(const cx_slist *list)
Get a list iterator to the end of a list.
Definition: cxslist.c:604
cx_strdup
cxchar * cx_strdup(const cxchar *string)
Duplicate a string.
Definition: cxstrutils.c:497