C Standard Library Extensions  1.2.1
cxstring.h
1 /* $Id: cxstring.h,v 1.8 2011-02-21 14:15:31 rpalsa Exp $
2  *
3  * This file is part of the ESO C Extension Library
4  * Copyright (C) 2001-2011 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * $Author: rpalsa $
23  * $Date: 2011-02-21 14:15:31 $
24  * $Revision: 1.8 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifndef CX_STRING_H_
29 #define CX_STRING_H_ 1
30 
31 #include <stdarg.h>
32 #include <string.h>
33 #include <ctype.h>
34 
35 #include <cxtypes.h>
36 #include <cxmemory.h>
37 #include <cxmessages.h>
38 #include <cxutils.h>
39 
40 
41 CX_BEGIN_DECLS
42 
43 struct _cx_string_ {
44 
45  /* <private> */
46 
47  cxchar *data;
48  cxsize sz;
49 
50 };
51 
52 
60 typedef struct _cx_string_ cx_string;
61 
62 
63 /*
64  * Create, copy and destroy operations
65  */
66 
69 cx_string *cx_string_create(const cxchar *);
71 
72 /*
73  * Non modifying operations
74  */
75 
76 cxsize cx_string_size(const cx_string *);
77 cxbool cx_string_empty(const cx_string *);
78 
79 /*
80  * Data access
81  */
82 
83 const cxchar *cx_string_get(const cx_string *);
84 
85 /*
86  * Assignment operations
87  */
88 
89 void cx_string_set(cx_string *, const cxchar *);
90 
91 /*
92  * Modifying operations
93  */
94 void cx_string_resize(cx_string *, cxsize, cxchar);
95 void cx_string_extend(cx_string *, cxsize, cxchar);
96 
97 void cx_string_replace_character(cx_string *, cxsize, cxsize, cxchar, cxchar);
98 
104 
105 /*
106  * Inserting and removing elements
107  */
108 
109 cx_string *cx_string_prepend(cx_string *, const cxchar *);
110 cx_string *cx_string_append(cx_string *, const cxchar *);
111 cx_string *cx_string_insert(cx_string *, cxssize, const cxchar *);
112 cx_string *cx_string_erase(cx_string *, cxssize, cxssize);
114 
115 cx_string *cx_string_substr(const cx_string *, cxsize, cxsize);
116 
117 /*
118  * Comparison functions
119  */
120 
121 cxbool cx_string_equal (const cx_string *, const cx_string *);
122 cxint cx_string_compare(const cx_string *, const cx_string *);
123 cxint cx_string_casecmp(const cx_string *, const cx_string *);
124 cxint cx_string_ncasecmp(const cx_string *, const cx_string *, cxsize);
125 
126 /*
127  * Search functions
128  */
129 
130 cxsize cx_string_find_first_not_of(const cx_string *, const cxchar *);
131 cxsize cx_string_find_last_not_of(const cx_string *, const cxchar *);
132 
133 /*
134  * I/O functions
135  */
136 
138  const cxchar *, ...) CX_GNUC_PRINTF(2, 3);
140  const cxchar *, va_list) CX_GNUC_PRINTF(2, 0);
141 
142 /*
143  * Debugging utilities
144  */
145 
146 void cx_string_print(const cx_string *);
147 
148 CX_END_DECLS
149 
150 #endif /* CX_STRING_H */
void cx_string_replace_character(cx_string *, cxsize, cxsize, cxchar, cxchar)
Replace a given character with a new character in a portion of a string.
Definition: cxstring.c:1100
cxint cx_string_compare(const cx_string *, const cx_string *)
Compare two strings.
Definition: cxstring.c:910
void cx_string_extend(cx_string *, cxsize, cxchar)
Extend a string to a given length.
Definition: cxstring.c:1211
cx_string * cx_string_truncate(cx_string *, cxsize)
Truncate the string.
Definition: cxstring.c:836
cx_string * cx_string_create(const cxchar *)
Create a new string from a standard C string.
Definition: cxstring.c:286
cxbool cx_string_empty(const cx_string *)
Checks whether a string contains any characters.
Definition: cxstring.c:363
cx_string * cx_string_lower(cx_string *)
Converts the string into lowercase.
Definition: cxstring.c:484
cx_string * cx_string_prepend(cx_string *, const cxchar *)
Prepend an array of characters to the string.
Definition: cxstring.c:601
cx_string * cx_string_substr(const cx_string *, cxsize, cxsize)
Create a new string from a portion of a string.
Definition: cxstring.c:1355
cxint cx_string_ncasecmp(const cx_string *, const cx_string *, cxsize)
Compare the first n characters of two strings ignoring the case of characters.
Definition: cxstring.c:970
void cx_string_resize(cx_string *, cxsize, cxchar)
Resize a string to a given length.
Definition: cxstring.c:1155
cx_string * cx_string_insert(cx_string *, cxssize, const cxchar *)
Inserts a copy of a string at a given position.
Definition: cxstring.c:706
cxbool cx_string_equal(const cx_string *, const cx_string *)
Compare two cx_string for equality.
Definition: cxstring.c:865
cxint cxint void cx_string_print(const cx_string *)
Print the value of a cx_string to the standard output.
Definition: cxstring.c:1066
cx_string * cx_string_new(void)
Create a new, empty string container.
Definition: cxstring.c:240
void cx_string_set(cx_string *, const cxchar *)
Assign a value to a string.
Definition: cxstring.c:389
cx_string * cx_string_upper(cx_string *)
Converts the string into uppercase.
Definition: cxstring.c:449
cx_string * cx_string_copy(const cx_string *)
Create a copy a cx_string.
Definition: cxstring.c:258
cxsize cx_string_size(const cx_string *)
Computes the length of the string.
Definition: cxstring.c:340
cx_string * cx_string_strip(cx_string *)
Remove leading and trailing whitespaces from the string.
Definition: cxstring.c:573
cxsize cx_string_find_last_not_of(const cx_string *, const cxchar *)
Search a string for the last character that does not match any of the given characters.
Definition: cxstring.c:1299
cx_string * cx_string_trim(cx_string *)
Remove leading whitespaces from the string.
Definition: cxstring.c:519
cxint cx_string_vsprintf(cx_string *self, const cxchar *format, va_list args)
Write to the string from a variable-length argument list under format control.
Definition: cxstring.c:1044
cxint cx_string_sprintf(cx_string *self, const char *format,...)
Writes to a string under format control.
Definition: cxstring.c:1004
void cx_string_delete(cx_string *)
Destroy a string.
Definition: cxstring.c:313
cx_string * cx_string_append(cx_string *, const cxchar *)
Append an array of characters to the string.
Definition: cxstring.c:653
cx_string * cx_string_erase(cx_string *, cxssize, cxssize)
Erase a portion of the string.
Definition: cxstring.c:765
cxsize cx_string_find_first_not_of(const cx_string *, const cxchar *)
Search a string for the first character that does not match any of the given characters.
Definition: cxstring.c:1255
const cxchar * cx_string_get(const cx_string *)
Get the string's value.
Definition: cxstring.c:422
cx_string * cx_string_rtrim(cx_string *)
Remove trailing whitespaces from the string.
Definition: cxstring.c:546
struct _cx_string_ cx_string
The cx_string data type.
Definition: cxstring.h:60
cxint cx_string_casecmp(const cx_string *, const cx_string *)
Compare two strings ignoring the case of characters.
Definition: cxstring.c:935