@@ -50,8 +50,8 @@ typedef struct
50
50
#define str_null ((str){ 0, 0 })
51
51
52
52
// helper macros
53
- #define _ref_info (n ) ((n) << 1)
54
- #define _owner_info (n ) (_ref_info (n) | 1)
53
+ #define str_ref_info (n ) ((n) << 1)
54
+ #define str_owner_info (n ) (str_ref_info (n) | 1)
55
55
56
56
// string properties ----------------------------------------------------------------------
57
57
// length of the string
@@ -62,9 +62,9 @@ size_t str_len(const str s) { return s.info >> 1; }
62
62
static inline
63
63
const char * str_ptr (const str s )
64
64
{
65
- extern const char * const _empty_string ;
65
+ extern const char * const str_empty_string ;
66
66
67
- return s .ptr ? s .ptr : _empty_string ;
67
+ return s .ptr ? s .ptr : str_empty_string ;
68
68
}
69
69
70
70
// end of the string
@@ -88,9 +88,9 @@ bool str_is_ref(const str s) { return !str_is_owner(s); }
88
88
void str_free (const str s );
89
89
90
90
// automatic cleanup
91
- void _str_free (const str * const ps );
91
+ void str_free_auto (const str * const ps );
92
92
93
- #define str_auto str __attribute__((cleanup(_str_free )))
93
+ #define str_auto str __attribute__((cleanup(str_free_auto )))
94
94
95
95
// string movements -----------------------------------------------------------------------
96
96
// free target string, then assign the new value to it
@@ -135,29 +135,29 @@ bool str_has_suffix(const str s, const str suffix);
135
135
136
136
// string composition ------------------------------------------------------------------
137
137
// implementation helpers
138
- int _str_dup (str * const dest , const str s );
139
- int _str_cpy_to_fd (const int fd , const str s );
140
- int _str_cpy_to_stream (FILE * const stream , const str s );
138
+ int str_dup_impl (str * const dest , const str s );
139
+ int str_cpy_to_fd (const int fd , const str s );
140
+ int str_cpy_to_stream (FILE * const stream , const str s );
141
141
142
142
// copy string
143
143
#define str_cpy (dest , src ) \
144
144
_Generic((dest), \
145
- str*: _str_dup , \
146
- int: _str_cpy_to_fd , \
147
- FILE*: _str_cpy_to_stream \
145
+ str*: str_dup_impl , \
146
+ int: str_cpy_to_fd , \
147
+ FILE*: str_cpy_to_stream \
148
148
)((dest), (src))
149
149
150
150
// implementation helpers
151
- int _str_cat_range (str * const dest , const str * src , size_t count );
152
- int _str_cat_range_to_fd (const int fd , const str * src , size_t count );
153
- int _str_cat_range_to_stream (FILE * const stream , const str * src , size_t count );
151
+ int str_cat_range_impl (str * const dest , const str * src , size_t count );
152
+ int str_cat_range_to_fd (const int fd , const str * src , size_t count );
153
+ int str_cat_range_to_stream (FILE * const stream , const str * src , size_t count );
154
154
155
155
// concatenate range of strings
156
156
#define str_cat_range (dest , src , count ) \
157
157
_Generic((dest), \
158
- str*: _str_cat_range , \
159
- int: _str_cat_range_to_fd , \
160
- FILE*: _str_cat_range_to_stream \
158
+ str*: str_cat_range_impl , \
159
+ int: str_cat_range_to_fd , \
160
+ FILE*: str_cat_range_to_stream \
161
161
)((dest), (src), (count))
162
162
163
163
// concatenate string arguments
@@ -168,16 +168,16 @@ int _str_cat_range_to_stream(FILE* const stream, const str* src, size_t count);
168
168
})
169
169
170
170
// implementation helpers
171
- int _str_join_range (str * const dest , const str sep , const str * src , size_t count );
172
- int _str_join_range_to_fd (const int fd , const str sep , const str * src , size_t count );
173
- int _str_join_range_to_stream (FILE * const stream , const str sep , const str * src , size_t count );
171
+ int str_join_range_impl (str * const dest , const str sep , const str * src , size_t count );
172
+ int str_join_range_to_fd (const int fd , const str sep , const str * src , size_t count );
173
+ int str_join_range_to_stream (FILE * const stream , const str sep , const str * src , size_t count );
174
174
175
175
// join strings around the separator
176
176
#define str_join_range (dest , sep , src , count ) \
177
177
_Generic((dest), \
178
- str*: _str_join_range , \
179
- int: _str_join_range_to_fd , \
180
- FILE*: _str_join_range_to_stream \
178
+ str*: str_join_range_impl , \
179
+ int: str_join_range_to_fd , \
180
+ FILE*: str_join_range_to_stream \
181
181
)((dest), (sep), (src), (count))
182
182
183
183
// join string arguments around the separator
@@ -189,19 +189,19 @@ int _str_join_range_to_stream(FILE* const stream, const str sep, const str* src,
189
189
190
190
// constructors ----------------------------------------------------------------------------
191
191
// string reference from a string literal
192
- #define str_lit (s ) ((str){ "" s, _ref_info (sizeof(s) - 1) })
192
+ #define str_lit (s ) ((str){ "" s, str_ref_info (sizeof(s) - 1) })
193
193
194
194
static inline
195
- str _str_ref (const str s ) { return (str ){ s .ptr , s .info & ~(size_t )1 }; }
195
+ str str_ref_impl (const str s ) { return (str ){ s .ptr , s .info & ~(size_t )1 }; }
196
196
197
- str _str_ref_from_ptr (const char * const s );
197
+ str str_ref_from_ptr (const char * const s );
198
198
199
199
// string reference from anything
200
200
#define str_ref (s ) \
201
201
_Generic((s), \
202
- str: _str_ref , \
203
- char*: _str_ref_from_ptr , \
204
- const char*: _str_ref_from_ptr \
202
+ str: str_ref_impl , \
203
+ char*: str_ref_from_ptr , \
204
+ const char*: str_ref_from_ptr \
205
205
)(s)
206
206
207
207
// create a reference to the given range of chars
@@ -246,34 +246,34 @@ size_t str_unique_range(str* const array, const size_t count);
246
246
247
247
// iterator
248
248
#define for_each_codepoint (var , src ) \
249
- _for_each_cp ((var), (src), _CAT(__it_ , __COUNTER__))
249
+ for_each_cp ((var), (src), CAT1(inner_it_ , __COUNTER__))
250
250
251
251
// iterator error codes
252
252
#define CPI_END_OF_STRING ((char32_t)-1)
253
253
#define CPI_ERR_INCOMPLETE_SEQ ((char32_t)-2)
254
254
#define CPI_ERR_INVALID_ENCODING ((char32_t)-3)
255
255
256
256
// implementation
257
- #define _for_each_cp (var , src , it ) \
258
- for(_cp_iterator it = _make_cp_iterator (src); (var = _cp_iterator_next (&it)) <= 0x10FFFFu;)
257
+ #define for_each_cp (var , src , it ) \
258
+ for(str_cp_iterator it = str_make_cp_iterator (src); (var = str_cp_iterator_next (&it)) <= 0x10FFFFu;)
259
259
260
- #define _CAT (x , y ) __CAT (x, y)
261
- #define __CAT (x , y ) x ## y
260
+ #define CAT1 (x , y ) CAT2 (x, y)
261
+ #define CAT2 (x , y ) x ## y
262
262
263
263
typedef struct
264
264
{
265
265
const char * curr ;
266
266
const char * const end ;
267
267
mbstate_t state ;
268
- } _cp_iterator ;
268
+ } str_cp_iterator ;
269
269
270
270
static inline
271
- _cp_iterator _make_cp_iterator (const str s )
271
+ str_cp_iterator str_make_cp_iterator (const str s )
272
272
{
273
- return (_cp_iterator ){ .curr = str_ptr (s ), .end = str_end (s ) };
273
+ return (str_cp_iterator ){ .curr = str_ptr (s ), .end = str_end (s ) };
274
274
}
275
275
276
- char32_t _cp_iterator_next ( _cp_iterator * const it );
276
+ char32_t str_cp_iterator_next ( str_cp_iterator * const it );
277
277
278
278
#endif // ifdef __STDC_UTF_32__
279
279
0 commit comments