Tue, 30 Aug 2022 19:56:07 +0200
start implementing string functions
576
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | * \file string.h |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | * \brief Strings that know their length. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | * \author Mike Becker |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | * \author Olaf Wintermann |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | * \version 3.0 |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | * \copyright 2-Clause BSD License |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | #ifndef UCX_STRING_H |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | #define UCX_STRING_H |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | #include "common.h" |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
41 | #include "allocator.h" |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | * The UCX string structure. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | */ |
577
26447d59a5ab
wrong position of struct identifier
Mike Becker <universe@uap-core.de>
parents:
576
diff
changeset
|
46 | struct cx_mutstr_s { |
576
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | * A pointer to the string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | * \note The string is not necessarily \c NULL terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | * Always use the length. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | char *ptr; |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | /** The length of the string */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | size_t length; |
577
26447d59a5ab
wrong position of struct identifier
Mike Becker <universe@uap-core.de>
parents:
576
diff
changeset
|
55 | }; |
576
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | * A mutable string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | typedef struct cx_mutstr_s cxmutstr; |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
61 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | * The UCX string structure for immutable (constant) strings. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | */ |
577
26447d59a5ab
wrong position of struct identifier
Mike Becker <universe@uap-core.de>
parents:
576
diff
changeset
|
65 | struct cx_string_s { |
576
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | * A pointer to the immutable string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | * \note The string is not necessarily \c NULL terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | * Always use the length. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | char const *ptr; |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | /** The length of the string */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | size_t length; |
577
26447d59a5ab
wrong position of struct identifier
Mike Becker <universe@uap-core.de>
parents:
576
diff
changeset
|
74 | }; |
576
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
75 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | * An immutable string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | typedef struct cx_string_s cxstring; |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | #ifdef __cplusplus |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | extern "C" { |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | #endif |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | * Wraps a mutable string that must be zero-terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | * The length is implicitly inferred by using a call to \c strlen(). |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | * As a special case, a \c NULL argument is treated like an empty string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | * \note the wrapped string will share the specified pointer to the string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
93 | * If you do want a copy, use cx_strdup() on the return value of this function. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
94 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
95 | * If you need to wrap a constant string, use cx_str(). |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
96 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | * @param cstring the string to wrap, must be zero-terminated (or \c NULL) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | * @return the wrapped string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | * @see cx_mutstrn() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | cxmutstr cx_mutstr(char *cstring); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
105 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | * Wraps a string that does not need to be zero-terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | * The argument may be \c NULL if the length is zero. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | * \note the wrapped string will share the specified pointer to the string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | * If you do want a copy, use cx_strdup() on the return value of this function. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
113 | * If you need to wrap a constant string, use cx_strn(). |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | * @param cstring the string to wrap (or \c NULL, if the length is zero) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | * @param length the length of the string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | * @return the wrapped string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
118 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
119 | * @see cx_mutstr() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | cxmutstr cx_mutstrn( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
123 | char *cstring, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | size_t length |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
125 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
126 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | * Wraps a string that must be zero-terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
129 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
130 | * The length is implicitly inferred by using a call to \c strlen(). |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | * As a special case, a \c NULL argument is treated like an empty string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
132 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
133 | * \note the wrapped string will share the specified pointer to the string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | * If you do want a copy, use cx_strdup() on the return value of this function. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | * If you need to wrap a non-constant string, use cx_mutstr(). |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
137 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
138 | * @param cstring the string to wrap, must be zero-terminated (or \c NULL) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
139 | * @return the wrapped string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | * @see cx_strn() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
143 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | cxstring cx_str(char const *cstring); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
147 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
148 | * Wraps a string that does not need to be zero-terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | * The argument may be \c NULL if the length is zero. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | * \note the wrapped string will share the specified pointer to the string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | * If you do want a copy, use cx_strdup() on the return value of this function. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
155 | * If you need to wrap a non-constant string, use cx_mutstrn(). |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | * @param cstring the string to wrap (or \c NULL, if the length is zero) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | * @param length the length of the string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | * @return the wrapped string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
160 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
161 | * @see cx_str() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
162 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
163 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
164 | cxstring cx_strn( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | char const *cstring, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
166 | size_t length |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
168 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
170 | * Casts a mutable string to an immutable string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
171 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
172 | * \note This is not seriously a cast. Instead you get a copy |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
173 | * of the struct with the desired pointer type. Both structs still |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
174 | * point to the same location, though! |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
175 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
176 | * @param str the mutable string to cast |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
177 | * @return an immutable copy of the string pointer |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
179 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
180 | cxstring cx_strcast(cxmutstr str); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
181 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
182 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
183 | * Passes the pointer in this string to \c free(). |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
184 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
185 | * The pointer in the struct is set to \c NULL and the length is set to zero. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
186 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
187 | * \note There is no implementation for cxstring, because it is unlikely that |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
188 | * you ever have a \c char \c const* you are really supposed to free. If you |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
189 | * encounter such situation, you should double-check your code. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
190 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
191 | * @param str the string to free |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
192 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
193 | void cx_strfree(cxmutstr *str); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
194 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
195 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
196 | * Returns the accumulated length of all specified strings. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
197 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
198 | * \attention if the count argument is larger than the number of the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
199 | * specified strings, the behavior is undefined. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
200 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
201 | * @param count the total number of specified strings |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
202 | * @param ... all strings |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
203 | * @return the accumulated length of all strings |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
204 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
206 | size_t cx_strlen( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
207 | size_t count, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
208 | ... |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
209 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
210 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
211 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | * Concatenates two or more strings. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
213 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | * The resulting string will be allocated by the specified allocator. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
215 | * So developers \em must pass the return value to cx_strfree() eventually. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
216 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
217 | * \note It is guaranteed that there is only one allocation. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
219 | * @param alloc the allocator to use |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
220 | * @param count the total number of strings to concatenate |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | * @param ... all strings |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
222 | * @return the concatenated string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
223 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
224 | __attribute__((__warn_unused_result__, __nonnull__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
225 | cxmutstr cx_strcat_a( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
226 | CxAllocator *alloc, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
227 | size_t count, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
228 | ... |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
229 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
230 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
231 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
232 | * Concatenates two or more strings. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
233 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
234 | * The resulting string will be allocated by standard \c malloc(). |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
235 | * So developers \em must pass the return value to cx_strfree() eventually. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
236 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
237 | * @param count the total number of strings to concatenate |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
238 | * @param ... all strings |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
239 | * @return the concatenated string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
240 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
241 | #define cx_strcat(count, ...) \ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
242 | cx_strcat_a(cxDefaultAllocator, count, __VA_ARGS__) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
243 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
245 | * Returns a substring starting at the specified location. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
246 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
247 | * \attention the new string references the same memory area as the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
248 | * input string and is usually \em not zero-terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
249 | * Use cx_strdup() to get a copy. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
250 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
251 | * @param string input string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
252 | * @param start start location of the substring |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
253 | * @return a substring of \p string starting at \p start |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
254 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
255 | * @see cx_strsubsl() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
256 | * @see cx_strsubs_m() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
257 | * @see cx_strsubsl_m() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
258 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
259 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
260 | cxstring cx_strsubs( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
261 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
262 | size_t start |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
263 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
264 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
265 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
266 | * Returns a substring starting at the specified location. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
267 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
268 | * The returned string will be limited to \p length bytes or the number |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
269 | * of bytes available in \p string, whichever is smaller. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
270 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
271 | * \attention the new string references the same memory area as the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
272 | * input string and is usually \em not zero-terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
273 | * Use cx_strdup() to get a copy. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
274 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
275 | * @param string input string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
276 | * @param start start location of the substring |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
277 | * @param length the maximum length of the returned string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
278 | * @return a substring of \p string starting at \p start |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
279 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
280 | * @see cx_strsubs() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
281 | * @see cx_strsubs_m() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
282 | * @see cx_strsubsl_m() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
283 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
284 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
285 | cxstring cx_strsubsl( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
286 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
287 | size_t start, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
288 | size_t length |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
289 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
290 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
291 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
292 | * Returns a substring starting at the specified location. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
293 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
294 | * \attention the new string references the same memory area as the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
295 | * input string and is usually \em not zero-terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
296 | * Use cx_strdup() to get a copy. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
297 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
298 | * @param string input string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
299 | * @param start start location of the substring |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
300 | * @return a substring of \p string starting at \p start |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
301 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
302 | * @see cx_strsubsl_m() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
303 | * @see cx_strsubs() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
304 | * @see cx_strsubsl() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
305 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
306 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
307 | cxmutstr cx_strsubs_m( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
308 | cxmutstr string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
309 | size_t start |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
310 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
311 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
312 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
313 | * Returns a substring starting at the specified location. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
314 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
315 | * The returned string will be limited to \p length bytes or the number |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
316 | * of bytes available in \p string, whichever is smaller. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
317 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
318 | * \attention the new string references the same memory area as the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
319 | * input string and is usually \em not zero-terminated. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
320 | * Use cx_strdup() to get a copy. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
321 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
322 | * @param string input string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
323 | * @param start start location of the substring |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
324 | * @param length the maximum length of the returned string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
325 | * @return a substring of \p string starting at \p start |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
326 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
327 | * @see cx_strsubs_m() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
328 | * @see cx_strsubs() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
329 | * @see cx_strsubsl() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
330 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
331 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
332 | cxmutstr cx_strsubsl_m( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
333 | cxmutstr string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
334 | size_t start, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
335 | size_t length |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
336 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
337 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
338 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
339 | * Returns a substring starting at the location of the first occurrence of the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
340 | * specified character. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
341 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
342 | * If the string does not contain the character, an empty string is returned. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
343 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
344 | * @param string the string where to locate the character |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
345 | * @param chr the character to locate |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
346 | * @return a substring starting at the first location of \p chr |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
347 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
348 | * @see cx_strchr_m() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
349 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
350 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
351 | cxstring cx_strchr( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
352 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
353 | int chr |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
354 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
355 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
356 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
357 | * Returns a substring starting at the location of the first occurrence of the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
358 | * specified character. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
359 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
360 | * If the string does not contain the character, an empty string is returned. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
361 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
362 | * @param string the string where to locate the character |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
363 | * @param chr the character to locate |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
364 | * @return a substring starting at the first location of \p chr |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
365 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
366 | * @see cx_strchr() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
367 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
368 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
369 | cxmutstr cx_strchr_m( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
370 | cxmutstr string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
371 | int chr |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
372 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
373 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
374 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
375 | * Returns a substring starting at the location of the last occurrence of the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
376 | * specified character. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
377 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
378 | * If the string does not contain the character, an empty string is returned. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
379 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
380 | * @param string the string where to locate the character |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
381 | * @param chr the character to locate |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
382 | * @return a substring starting at the last location of \p chr |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
383 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
384 | * @see cx_strrchr_m() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
385 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
386 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
387 | cxstring cx_strrchr( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
388 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
389 | int chr |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
390 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
391 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
392 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
393 | * Returns a substring starting at the location of the last occurrence of the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
394 | * specified character. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
395 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
396 | * If the string does not contain the character, an empty string is returned. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
397 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
398 | * @param string the string where to locate the character |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
399 | * @param chr the character to locate |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
400 | * @return a substring starting at the last location of \p chr |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
401 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
402 | * @see cx_strrchr() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
403 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
404 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
405 | cxmutstr cx_strrchr_m( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
406 | cxmutstr string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
407 | int chr |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
408 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
409 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
410 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
411 | * Returns a substring starting at the location of the first occurrence of the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
412 | * specified string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
413 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
414 | * If \p haystack does not contain \p needle, an empty string is returned. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
415 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
416 | * If \p needle is an empty string, the complete \p haystack is |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
417 | * returned. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
418 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
419 | * @param haystack the string to be scanned |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
420 | * @param needle string containing the sequence of characters to match |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
421 | * @return a substring starting at the first occurrence of |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
422 | * \p needle, or an empty string, if the sequence is not |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
423 | * contained |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
424 | * @see cx_strstr_m() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
425 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
426 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
427 | cxstring cx_strstr( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
428 | cxstring haystack, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
429 | cxstring needle |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
430 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
431 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
432 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
433 | * Returns a substring starting at the location of the first occurrence of the |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
434 | * specified string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
435 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
436 | * If \p haystack does not contain \p needle, an empty string is returned. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
437 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
438 | * If \p needle is an empty string, the complete \p haystack is |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
439 | * returned. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
440 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
441 | * @param haystack the string to be scanned |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
442 | * @param needle string containing the sequence of characters to match |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
443 | * @return a substring starting at the first occurrence of |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
444 | * \p needle, or an empty string, if the sequence is not |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
445 | * contained |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
446 | * @see cx_strstr() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
447 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
448 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
449 | cxmutstr cx_strstr_m( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
450 | cxmutstr haystack, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
451 | cxstring needle |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
452 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
453 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
454 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
455 | * Splits a given string using a delimiter string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
456 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
457 | * \note The resulting array contains strings that point to the source |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
458 | * \p string. Use cx_strdup() to get copies. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
459 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
460 | * @param string the string to split |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
461 | * @param delim the delimiter |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
462 | * @param limit the maximum number of split items |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
463 | * @param output a pre-allocated array of at least \p limit length |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
464 | * @return the actual number of split items |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
465 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
466 | __attribute__((__warn_unused_result__, __nonnull__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
467 | size_t cx_strsplit( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
468 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
469 | cxstring delim, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
470 | size_t limit, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
471 | cxstring *output |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
472 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
473 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
474 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
475 | * Splits a given string using a delimiter string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
476 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
477 | * The array pointed to by \p output will be allocated by \p allocator. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
478 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
479 | * \note The resulting array contains strings that point to the source |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
480 | * \p string. Use cx_strdup() to get copies. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
481 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
482 | * \attention If allocation fails, the \c NULL pointer will be written to |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
483 | * \p output and the number returned will be zero. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
484 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
485 | * @param allocator the allocator to use for allocating the resulting array |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
486 | * @param string the string to split |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
487 | * @param delim the delimiter |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
488 | * @param limit the maximum number of split items |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
489 | * @param output a pointer where the address of the allocated array shall be |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
490 | * written to |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
491 | * @return the actual number of split items |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
492 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
493 | __attribute__((__warn_unused_result__, __nonnull__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
494 | size_t cx_strsplit_a( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
495 | CxAllocator *allocator, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
496 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
497 | cxstring delim, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
498 | size_t limit, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
499 | cxstring **output |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
500 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
501 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
502 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
503 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
504 | * Splits a given string using a delimiter string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
505 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
506 | * \note The resulting array contains strings that point to the source |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
507 | * \p string. Use cx_strdup() to get copies. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
508 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
509 | * @param string the string to split |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
510 | * @param delim the delimiter |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
511 | * @param limit the maximum number of split items |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
512 | * @param output a pre-allocated array of at least \p limit length |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
513 | * @return the actual number of split items |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
514 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
515 | __attribute__((__warn_unused_result__, __nonnull__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
516 | size_t cx_strsplit_m( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
517 | cxmutstr string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
518 | cxstring delim, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
519 | size_t limit, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
520 | cxmutstr *output |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
521 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
522 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
523 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
524 | * Splits a given string using a delimiter string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
525 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
526 | * The array pointed to by \p output will be allocated by \p allocator. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
527 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
528 | * \note The resulting array contains strings that point to the source |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
529 | * \p string. Use cx_strdup() to get copies. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
530 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
531 | * \attention If allocation fails, the \c NULL pointer will be written to |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
532 | * \p output and the number returned will be zero. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
533 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
534 | * @param allocator the allocator to use for allocating the resulting array |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
535 | * @param string the string to split |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
536 | * @param delim the delimiter |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
537 | * @param limit the maximum number of split items |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
538 | * @param output a pointer where the address of the allocated array shall be |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
539 | * written to |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
540 | * @return the actual number of split items |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
541 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
542 | __attribute__((__warn_unused_result__, __nonnull__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
543 | size_t cx_strsplit_ma( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
544 | CxAllocator *allocator, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
545 | cxmutstr string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
546 | cxstring delim, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
547 | size_t limit, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
548 | cxmutstr **output |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
549 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
550 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
551 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
552 | * Compares two strings. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
553 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
554 | * @param s1 the first string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
555 | * @param s2 the second string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
556 | * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
557 | * than \p s2, zero if both strings equal |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
558 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
559 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
560 | int cx_strcmp( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
561 | cxstring s1, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
562 | cxstring s2 |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
563 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
564 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
565 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
566 | * Compares two strings ignoring case. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
567 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
568 | * @param s1 the first string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
569 | * @param s2 the second string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
570 | * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
571 | * than \p s2, zero if both strings equal ignoring case |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
572 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
573 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
574 | int cx_strcasecmp( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
575 | cxstring s1, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
576 | cxstring s2 |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
577 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
578 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
579 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
580 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
581 | * Creates a duplicate of the specified string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
582 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
583 | * The new string will contain a copy allocated by \p allocator. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
584 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
585 | * \note The returned string is guaranteed to be zero-terminated and can safely |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
586 | * be passed to other APIs. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
587 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
588 | * @param allocator the allocator to use |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
589 | * @param string the string to duplicate |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
590 | * @return a duplicate of the string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
591 | * @see cx_strdup() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
592 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
593 | __attribute__((__warn_unused_result__, __nonnull__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
594 | cxmutstr cx_strdup_a( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
595 | CxAllocator *allocator, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
596 | cxstring string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
597 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
598 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
599 | /** |
578
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
600 | * Creates a duplicate of the specified string. |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
601 | * |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
602 | * The new string will contain a copy allocated by standard |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
603 | * \c malloc(). So developers \em must pass the return value to cx_strfree(). |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
604 | * |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
605 | * \note The returned string is guaranteed to be zero-terminated and can safely |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
606 | * be passed to other APIs. |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
607 | * |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
608 | * @param string the string to duplicate |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
609 | * @return a duplicate of the string |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
610 | * @see cx_strdup_a() |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
611 | */ |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
612 | #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
613 | |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
614 | /** |
576
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
615 | * Omits leading and trailing spaces. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
616 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
617 | * \note the returned string references the same memory, thus you |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
618 | * must \em not free the returned memory. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
619 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
620 | * @param string the string that shall be trimmed |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
621 | * @return the trimmed string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
622 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
623 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
624 | cxstring cx_strtrim(cxstring string); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
625 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
626 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
627 | * Omits leading and trailing spaces. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
628 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
629 | * \note the returned string references the same memory, thus you |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
630 | * must \em not free the returned memory. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
631 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
632 | * @param string the string that shall be trimmed |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
633 | * @return the trimmed string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
634 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
635 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
636 | cxmutstr cx_strtrim_m(cxmutstr string); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
637 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
638 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
639 | * Checks, if a string has a specific prefix. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
640 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
641 | * @param string the string to check |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
642 | * @param prefix the prefix the string should have |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
643 | * @return \c true, if and only if the string has the specified prefix, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
644 | * \c false otherwise |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
645 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
646 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
647 | bool cx_strprefix( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
648 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
649 | cxstring prefix |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
650 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
651 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
652 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
653 | * Checks, if a string has a specific suffix. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
654 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
655 | * @param string the string to check |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
656 | * @param suffix the suffix the string should have |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
657 | * @return \c true, if and only if the string has the specified suffix, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
658 | * \c false otherwise |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
659 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
660 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
661 | int cx_strsuffix( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
662 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
663 | cxstring suffix |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
664 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
665 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
666 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
667 | * Checks, if a string has a specific prefix, ignoring the case. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
668 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
669 | * @param string the string to check |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
670 | * @param prefix the prefix the string should have |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
671 | * @return \c true, if and only if the string has the specified prefix, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
672 | * \c false otherwise |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
673 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
674 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
675 | int cx_strcaseprefix( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
676 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
677 | cxstring prefix |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
678 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
679 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
680 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
681 | * Checks, if a string has a specific suffix, ignoring the case. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
682 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
683 | * @param string the string to check |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
684 | * @param suffix the suffix the string should have |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
685 | * @return \c true, if and only if the string has the specified suffix, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
686 | * \c false otherwise |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
687 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
688 | __attribute__((__warn_unused_result__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
689 | int cx_strcasesuffix( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
690 | cxstring string, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
691 | cxstring suffix |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
692 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
693 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
694 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
695 | * Converts the string to lower case. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
696 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
697 | * The change is made in-place. If you want a copy, use cx_strdup(), first. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
698 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
699 | * @param string the string to modify |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
700 | * @see cx_strdup() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
701 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
702 | void cx_strlower(cxmutstr string); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
703 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
704 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
705 | * Converts the string to upper case. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
706 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
707 | * The change is made in-place. If you want a copy, use cx_strdup(), first. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
708 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
709 | * @param string the string to modify |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
710 | * @see cx_strdup() |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
711 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
712 | void cx_strupper(cxmutstr string); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
713 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
714 | /** |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
715 | * Replaces a pattern in a string with another string. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
716 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
717 | * The pattern is taken literally and is no regular expression. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
718 | * Replaces at most \p replmax occurrences. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
719 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
720 | * The returned string will be allocated by \p allocator. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
721 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
722 | * If allocation fails, or the input string is empty, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
723 | * the returned string will point to \c NULL. |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
724 | * |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
725 | * @param allocator the allocator to use |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
726 | * @param str the string where replacements should be applied |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
727 | * @param pattern the pattern to search for |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
728 | * @param replacement the replacement string |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
729 | * @param replmax maximum number of replacements |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
730 | * @return the resulting string after applying the replacements |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
731 | */ |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
732 | __attribute__((__warn_unused_result__, __nonnull__)) |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
733 | cxmutstr cx_strreplace_a( |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
734 | CxAllocator *allocator, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
735 | cxstring str, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
736 | cxstring pattern, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
737 | cxstring replacement, |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
738 | size_t replmax |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
739 | ); |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
740 | |
578
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
741 | /** |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
742 | * Replaces a pattern in a string with another string. |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
743 | * |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
744 | * The pattern is taken literally and is no regular expression. |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
745 | * Replaces at most \p replmax occurrences. |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
746 | * |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
747 | * The returned string will be allocated by \c malloc() and \em must be passed |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
748 | * to cx_strfree() eventually. |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
749 | * |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
750 | * If allocation fails, or the input string is empty, |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
751 | * the returned string will point to \c NULL. |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
752 | * |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
753 | * @param str the string where replacements should be applied |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
754 | * @param pattern the pattern to search for |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
755 | * @param replacement the replacement string |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
756 | * @param replmax maximum number of replacements |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
757 | * @return the resulting string after applying the replacements |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
758 | */ |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
759 | #define cx_strreplace(str, pattern, replacement, replmax) \ |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
760 | cx_strreplace_a(cxDefaultAllocator, str, pattern, replacement, replmax) |
0b2c0cb280a9
some function can be macros using the default allocator
Mike Becker <universe@uap-core.de>
parents:
577
diff
changeset
|
761 | |
576
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
762 | #ifdef __cplusplus |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
763 | } // extern "C" |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
764 | #endif |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
765 | |
ba0c4ff6698e
first proposal for the string header
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
766 | #endif //UCX_STRING_H |