C Standard Library Extensions 1.2.7
cxstring.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_STRING_H_
21#define CX_STRING_H_ 1
22
23#include <stdarg.h>
24#include <string.h>
25#include <ctype.h>
26
27#include <cxtypes.h>
28#include <cxmemory.h>
29#include <cxmessages.h>
30#include <cxutils.h>
31
32
33CX_BEGIN_DECLS
34
35struct _cx_string_
36{
37 /* <private> */
38
39 cxchar *data;
40 cxsize sz;
41};
42
43
50
51typedef struct _cx_string_ cx_string;
52
53
54/*
55 * Create, copy and destroy operations
56 */
57
60cx_string *cx_string_create(const cxchar *);
62
63/*
64 * Non modifying operations
65 */
66
67cxsize cx_string_size(const cx_string *);
68cxbool cx_string_empty(const cx_string *);
69
70/*
71 * Data access
72 */
73
74const cxchar *cx_string_get(const cx_string *);
75
76/*
77 * Assignment operations
78 */
79
80void cx_string_set(cx_string *, const cxchar *);
81
82/*
83 * Modifying operations
84 */
85void cx_string_resize(cx_string *, cxsize, cxchar);
86void cx_string_extend(cx_string *, cxsize, cxchar);
87
88void cx_string_replace_character(cx_string *, cxsize, cxsize, cxchar, cxchar);
89
95
96/*
97 * Inserting and removing elements
98 */
99
100cx_string *cx_string_prepend(cx_string *, const cxchar *);
101cx_string *cx_string_append(cx_string *, const cxchar *);
102cx_string *cx_string_insert(cx_string *, cxssize, const cxchar *);
103cx_string *cx_string_erase(cx_string *, cxssize, cxssize);
105
106cx_string *cx_string_substr(const cx_string *, cxsize, cxsize);
107
108/*
109 * Comparison functions
110 */
111
112cxbool cx_string_equal(const cx_string *, const cx_string *);
113cxint cx_string_compare(const cx_string *, const cx_string *);
114cxint cx_string_casecmp(const cx_string *, const cx_string *);
115cxint cx_string_ncasecmp(const cx_string *, const cx_string *, cxsize);
116
117/*
118 * Search functions
119 */
120
121cxsize cx_string_find_first_not_of(const cx_string *, const cxchar *);
122cxsize cx_string_find_last_not_of(const cx_string *, const cxchar *);
123
124/*
125 * I/O functions
126 */
127
128cxint cx_string_sprintf(cx_string *, const cxchar *, ...) CX_GNUC_PRINTF(2, 3);
129cxint cx_string_vsprintf(cx_string *, const cxchar *, va_list)
130 CX_GNUC_PRINTF(2, 0);
131
132/*
133 * Debugging utilities
134 */
135
136void cx_string_print(const cx_string *);
137
138CX_END_DECLS
139
140#endif /* CX_STRING_H */
cx_string * cx_string_upper(cx_string *)
Converts the string into uppercase.
Definition cxstring.c:413
cx_string * cx_string_create(const cxchar *)
Create a new string from a standard C string.
Definition cxstring.c:260
cx_string * cx_string_truncate(cx_string *, cxsize)
Truncate the string.
Definition cxstring.c:783
cx_string * cx_string_insert(cx_string *, cxssize, const cxchar *)
Inserts a copy of a string at a given position.
Definition cxstring.c:657
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:980
cxint cx_string_sprintf(cx_string *self, const char *format,...)
Writes to a string under format control.
Definition cxstring.c:942
cx_string * cx_string_append(cx_string *, const cxchar *)
Append an array of characters to the string.
Definition cxstring.c:605
cx_string * cx_string_substr(const cx_string *, cxsize, cxsize)
Create a new string from a portion of a string.
Definition cxstring.c:1268
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:1033
cxint cx_string_compare(const cx_string *, const cx_string *)
Compare two strings.
Definition cxstring.c:853
void cx_string_resize(cx_string *, cxsize, cxchar)
Resize a string to a given length.
Definition cxstring.c:1084
struct _cx_string_ cx_string
The cx_string data type.
Definition cxstring.h:51
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:1214
cx_string * cx_string_new(void)
Create a new, empty string container.
Definition cxstring.c:216
cx_string * cx_string_lower(cx_string *)
Converts the string into lowercase.
Definition cxstring.c:446
cx_string * cx_string_erase(cx_string *, cxssize, cxssize)
Erase a portion of the string.
Definition cxstring.c:714
const cxchar * cx_string_get(const cx_string *)
Get the string's value.
Definition cxstring.c:388
void cx_string_set(cx_string *, const cxchar *)
Assign a value to a string.
Definition cxstring.c:357
void cx_string_delete(cx_string *)
Destroy a string.
Definition cxstring.c:285
cx_string * cx_string_strip(cx_string *)
Remove leading and trailing whitespaces from the string.
Definition cxstring.c:529
cx_string * cx_string_trim(cx_string *)
Remove leading whitespaces from the string.
Definition cxstring.c:479
cx_string * cx_string_rtrim(cx_string *)
Remove trailing whitespaces from the string.
Definition cxstring.c:504
cxbool cx_string_empty(const cx_string *)
Checks whether a string contains any characters.
Definition cxstring.c:331
cx_string * cx_string_prepend(cx_string *, const cxchar *)
Prepend an array of characters to the string.
Definition cxstring.c:555
cx_string * cx_string_copy(const cx_string *)
Create a copy a cx_string.
Definition cxstring.c:232
cxbool cx_string_equal(const cx_string *, const cx_string *)
Compare two cx_string for equality.
Definition cxstring.c:810
void cx_string_print(const cx_string *string)
Print the value of a cx_string to the standard output.
Definition cxstring.c:1000
cxsize cx_string_size(const cx_string *)
Computes the length of the string.
Definition cxstring.c:310
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:1172
void cx_string_extend(cx_string *, cxsize, cxchar)
Extend a string to a given length.
Definition cxstring.c:1132
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:909
cxint cx_string_casecmp(const cx_string *, const cx_string *)
Compare two strings ignoring the case of characters.
Definition cxstring.c:876