Skip to content

Commit 05fab47

Browse files
committed
Internal symbols renamed to avoid potential naming conflicts with standard headers.
1 parent db8b3d1 commit 05fab47

File tree

2 files changed

+54
-54
lines changed

2 files changed

+54
-54
lines changed

str.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void str_free(const str s)
6060
}
6161

6262
// version of str_free() for str_auto macro
63-
void _str_free(const str* const ps)
63+
void str_free_auto(const str* const ps)
6464
{
6565
if(ps)
6666
str_free(*ps);
@@ -88,7 +88,7 @@ void str_swap(str* const s1, str* const s2)
8888
}
8989

9090
// empty string
91-
const char* const _empty_string = "";
91+
const char* const str_empty_string = "";
9292

9393
// string comparison ---------------------------------------------------------------------
9494
// compare two strings lexicographically
@@ -141,10 +141,10 @@ bool str_has_suffix(const str s, const str suffix)
141141
// create a reference to the given range of chars
142142
str str_ref_chars(const char* const s, const size_t n)
143143
{
144-
return (s && n > 0) ? ((str){ s, _ref_info(n) }) : str_null;
144+
return (s && n > 0) ? ((str){ s, str_ref_info(n) }) : str_null;
145145
}
146146

147-
str _str_ref_from_ptr(const char* const s)
147+
str str_ref_from_ptr(const char* const s)
148148
{
149149
return s ? str_ref_chars(s, strlen(s)) : str_null;
150150
}
@@ -161,7 +161,7 @@ str str_acquire_chars(const char* const s, const size_t n)
161161
return str_null;
162162
}
163163

164-
return (str){ s, _owner_info(n) };
164+
return (str){ s, str_owner_info(n) };
165165
}
166166

167167
// take ownership of the given C string
@@ -171,7 +171,7 @@ str str_acquire(const char* const s)
171171
}
172172

173173
// allocate a copy of the given string
174-
int _str_dup(str* const dest, const str s)
174+
int str_dup_impl(str* const dest, const str s)
175175
{
176176
const size_t n = str_len(s);
177177

@@ -311,7 +311,7 @@ size_t total_length(const str* src, size_t count)
311311
}
312312

313313
// concatenate strings
314-
int _str_cat_range(str* const dest, const str* src, size_t count)
314+
int str_cat_range_impl(str* const dest, const str* src, size_t count)
315315
{
316316
if(!src)
317317
{
@@ -344,7 +344,7 @@ int _str_cat_range(str* const dest, const str* src, size_t count)
344344
}
345345

346346
// writing to file descriptor
347-
int _str_cpy_to_fd(const int fd, const str s)
347+
int str_cpy_to_fd(const int fd, const str s)
348348
{
349349
size_t n = str_len(s);
350350
const void* p = str_ptr(s);
@@ -363,7 +363,7 @@ int _str_cpy_to_fd(const int fd, const str s)
363363
}
364364

365365
// writing to byte stream
366-
int _str_cpy_to_stream(FILE* const stream, const str s)
366+
int str_cpy_to_stream(FILE* const stream, const str s)
367367
{
368368
const size_t n = str_len(s);
369369

@@ -412,7 +412,7 @@ struct iovec* vec_append_nonempty(struct iovec* const pv, const str s)
412412
return str_is_empty(s) ? pv : vec_append(pv, s);
413413
}
414414

415-
int _str_cat_range_to_fd(const int fd, const str* src, size_t count)
415+
int str_cat_range_to_fd(const int fd, const str* src, size_t count)
416416
{
417417
if(!src)
418418
return 0;
@@ -440,7 +440,7 @@ int _str_cat_range_to_fd(const int fd, const str* src, size_t count)
440440
return 0;
441441
}
442442

443-
int _str_cat_range_to_stream(FILE* const stream, const str* src, size_t count)
443+
int str_cat_range_to_stream(FILE* const stream, const str* src, size_t count)
444444
{
445445
if(!src)
446446
return 0;
@@ -454,7 +454,7 @@ int _str_cat_range_to_stream(FILE* const stream, const str* src, size_t count)
454454
}
455455

456456
// join strings
457-
int _str_join_range(str* const dest, const str sep, const str* src, size_t count)
457+
int str_join_range_impl(str* const dest, const str sep, const str* src, size_t count)
458458
{
459459
// test for simple cases
460460
if(str_is_empty(sep))
@@ -487,7 +487,7 @@ int _str_join_range(str* const dest, const str sep, const str* src, size_t count
487487
return 0;
488488
}
489489

490-
int _str_join_range_to_fd(const int fd, const str sep, const str* src, size_t count)
490+
int str_join_range_to_fd(const int fd, const str sep, const str* src, size_t count)
491491
{
492492
if(str_is_empty(sep))
493493
return str_cat_range(fd, src, count);
@@ -523,7 +523,7 @@ int _str_join_range_to_fd(const int fd, const str sep, const str* src, size_t co
523523
return 0;
524524
}
525525

526-
int _str_join_range_to_stream(FILE* const stream, const str sep, const str* src, size_t count)
526+
int str_join_range_to_stream(FILE* const stream, const str sep, const str* src, size_t count)
527527
{
528528
if(str_is_empty(sep))
529529
return str_cat_range(stream, src, count);
@@ -656,7 +656,7 @@ size_t str_unique_range(str* const array, const size_t count)
656656
// string iterator function
657657
#ifdef __STDC_UTF_32__
658658

659-
char32_t _cp_iterator_next(_cp_iterator* const it)
659+
char32_t str_cp_iterator_next(str_cp_iterator* const it)
660660
{
661661
if(it->curr >= it->end)
662662
return CPI_END_OF_STRING;

str.h

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ typedef struct
5050
#define str_null ((str){ 0, 0 })
5151

5252
// 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)
5555

5656
// string properties ----------------------------------------------------------------------
5757
// length of the string
@@ -62,9 +62,9 @@ size_t str_len(const str s) { return s.info >> 1; }
6262
static inline
6363
const char* str_ptr(const str s)
6464
{
65-
extern const char* const _empty_string;
65+
extern const char* const str_empty_string;
6666

67-
return s.ptr ? s.ptr : _empty_string;
67+
return s.ptr ? s.ptr : str_empty_string;
6868
}
6969

7070
// end of the string
@@ -88,9 +88,9 @@ bool str_is_ref(const str s) { return !str_is_owner(s); }
8888
void str_free(const str s);
8989

9090
// automatic cleanup
91-
void _str_free(const str* const ps);
91+
void str_free_auto(const str* const ps);
9292

93-
#define str_auto str __attribute__((cleanup(_str_free)))
93+
#define str_auto str __attribute__((cleanup(str_free_auto)))
9494

9595
// string movements -----------------------------------------------------------------------
9696
// free target string, then assign the new value to it
@@ -135,29 +135,29 @@ bool str_has_suffix(const str s, const str suffix);
135135

136136
// string composition ------------------------------------------------------------------
137137
// 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);
141141

142142
// copy string
143143
#define str_cpy(dest, src) \
144144
_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 \
148148
)((dest), (src))
149149

150150
// 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);
154154

155155
// concatenate range of strings
156156
#define str_cat_range(dest, src, count) \
157157
_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 \
161161
)((dest), (src), (count))
162162

163163
// concatenate string arguments
@@ -168,16 +168,16 @@ int _str_cat_range_to_stream(FILE* const stream, const str* src, size_t count);
168168
})
169169

170170
// 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);
174174

175175
// join strings around the separator
176176
#define str_join_range(dest, sep, src, count) \
177177
_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 \
181181
)((dest), (sep), (src), (count))
182182

183183
// 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,
189189

190190
// constructors ----------------------------------------------------------------------------
191191
// 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) })
193193

194194
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 }; }
196196

197-
str _str_ref_from_ptr(const char* const s);
197+
str str_ref_from_ptr(const char* const s);
198198

199199
// string reference from anything
200200
#define str_ref(s) \
201201
_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 \
205205
)(s)
206206

207207
// 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);
246246

247247
// iterator
248248
#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__))
250250

251251
// iterator error codes
252252
#define CPI_END_OF_STRING ((char32_t)-1)
253253
#define CPI_ERR_INCOMPLETE_SEQ ((char32_t)-2)
254254
#define CPI_ERR_INVALID_ENCODING ((char32_t)-3)
255255

256256
// 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;)
259259

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
262262

263263
typedef struct
264264
{
265265
const char* curr;
266266
const char* const end;
267267
mbstate_t state;
268-
} _cp_iterator;
268+
} str_cp_iterator;
269269

270270
static inline
271-
_cp_iterator _make_cp_iterator(const str s)
271+
str_cp_iterator str_make_cp_iterator(const str s)
272272
{
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) };
274274
}
275275

276-
char32_t _cp_iterator_next(_cp_iterator* const it);
276+
char32_t str_cp_iterator_next(str_cp_iterator* const it);
277277

278278
#endif // ifdef __STDC_UTF_32__
279279

0 commit comments

Comments
 (0)