annotate src/lib/str.h @ 22664:fea53c2725c0

director: Fix director_max_parallel_moves/kicks type Should be uint, not time.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 09 Nov 2017 12:24:16 +0200
parents bda524026533
children 7f2568b494ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6410
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 4719
diff changeset
1 #ifndef STR_H
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 4719
diff changeset
2 #define STR_H
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
21019
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
4 #include "buffer.h"
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
5
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
6 string_t *str_new(pool_t pool, size_t initial_size);
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
7 string_t *t_str_new(size_t initial_size);
8007
b3dd6db685a4 Added str_new_const().
Timo Sirainen <tss@iki.fi>
parents: 7912
diff changeset
8 /* Allocate a constant string using the given str as the input data.
b3dd6db685a4 Added str_new_const().
Timo Sirainen <tss@iki.fi>
parents: 7912
diff changeset
9 str pointer is saved directly, so it must not be freed until the returned
b3dd6db685a4 Added str_new_const().
Timo Sirainen <tss@iki.fi>
parents: 7912
diff changeset
10 string is no longer used. len must contain strlen(str). */
b3dd6db685a4 Added str_new_const().
Timo Sirainen <tss@iki.fi>
parents: 7912
diff changeset
11 string_t *str_new_const(pool_t pool, const char *str, size_t len);
8263
c1568782774e Added t_str_new_const().
Timo Sirainen <tss@iki.fi>
parents: 8007
diff changeset
12 string_t *t_str_new_const(const char *str, size_t len);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 2839
diff changeset
13 void str_free(string_t **str);
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 2839
diff changeset
14 char *str_free_without_data(string_t **str);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
16 const char *str_c(string_t *str);
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
17 char *str_c_modifiable(string_t *str);
7912
81806d402514 Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents: 6967
diff changeset
18 bool str_equals(const string_t *str1, const string_t *str2) ATTR_PURE;
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
21019
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
20 static inline const unsigned char *str_data(const string_t *str)
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
21 {
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
22 return str->data;
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
23 }
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
24 static inline size_t str_len(const string_t *str)
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
25 {
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
26 return str->used;
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
27 }
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
28
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 /* Append string/character */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
30 void str_append_n(string_t *str, const void *cstr, size_t max_len);
21019
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
31
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
32 static inline void str_append(string_t *str, const char *cstr)
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
33 {
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
34 buffer_append(str, cstr, strlen(cstr));
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
35 }
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
36 static inline void str_append_data(string_t *str, const void *data, size_t len)
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
37 {
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
38 buffer_append(str, data, len);
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
39 }
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
40
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
41 static inline void str_append_c(string_t *str, unsigned char chr)
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
42 {
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
43 buffer_append_c(str, chr);
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
44 }
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
45
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
46 static inline void str_append_str(string_t *dest, const string_t *src)
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
47 {
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
48 buffer_append(dest, src->data, src->used);
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
49 }
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 /* Append printf()-like data */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
52 void str_printfa(string_t *str, const char *fmt, ...)
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6410
diff changeset
53 ATTR_FORMAT(2, 3);
4719
1995cb3763db Added sentinel GCC attribute to *_strconcat() functions. Added
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
54 void str_vprintfa(string_t *str, const char *fmt, va_list args)
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6410
diff changeset
55 ATTR_FORMAT(2, 0);
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56
21019
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
57 static inline void str_insert(string_t *str, size_t pos, const char *cstr)
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
58 {
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
59 buffer_insert(str, pos, cstr, strlen(cstr));
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
60 }
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
61
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
62 static inline void str_delete(string_t *str, size_t pos, size_t len)
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
63 {
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
64 buffer_delete(str, pos, len);
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
65 }
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
66
21021
bda524026533 lib: Fix str_truncate() when string size is already smaller.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21019
diff changeset
67 /* Truncate the string to specified length. If it's already smaller,
bda524026533 lib: Fix str_truncate() when string size is already smaller.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21019
diff changeset
68 do nothing. */
21019
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
69 static inline void str_truncate(string_t *str, size_t len)
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
70 {
21021
bda524026533 lib: Fix str_truncate() when string size is already smaller.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21019
diff changeset
71 if (str_len(str) > len)
bda524026533 lib: Fix str_truncate() when string size is already smaller.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21019
diff changeset
72 buffer_set_used_size(str, len);
21019
b1e73bc7129c lib: Make str_*() inline which are simple buffer_* wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 17318
diff changeset
73 }
833
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74
41ec8cadd238 Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 #endif