str.h revision 513928e1d3eb3943c535732d693eadc387a4c2c3
5e0ce63bb65db34d7f48b34bbb5545fa791781c4Timo Sirainen#ifndef STR_H
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#define STR_H
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstring_t *str_new(pool_t pool, size_t initial_size);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstring_t *t_str_new(size_t initial_size);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* Allocate a constant string using the given str as the input data.
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen str pointer is saved directly, so it must not be freed until the returned
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen string is no longer used. len must contain strlen(str). */
daf029d2a627daa39d05507140f385162828172eTimo Sirainenstring_t *str_new_const(pool_t pool, const char *str, size_t len);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstring_t *t_str_new_const(const char *str, size_t len);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid str_free(string_t **str);
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenchar *str_free_without_data(string_t **str);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
daf029d2a627daa39d05507140f385162828172eTimo Sirainenconst char *str_c(string_t *str);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenconst unsigned char *str_data(const string_t *str) ATTR_PURE;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenchar *str_c_modifiable(string_t *str);
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainensize_t str_len(const string_t *str) ATTR_PURE;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenbool str_equals(const string_t *str1, const string_t *str2) ATTR_PURE;
daf029d2a627daa39d05507140f385162828172eTimo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* Append string/character */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid str_append(string_t *str, const char *cstr);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid str_append_n(string_t *str, const void *cstr, size_t max_len);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid str_append_data(string_t *str, const void *data, size_t len);
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainenvoid str_append_c(string_t *str, unsigned char chr);
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainenvoid str_append_str(string_t *dest, const string_t *src);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Append printf()-like data */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid str_printfa(string_t *str, const char *fmt, ...)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen ATTR_FORMAT(2, 3);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid str_vprintfa(string_t *str, const char *fmt, va_list args)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen ATTR_FORMAT(2, 0);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenvoid str_insert(string_t *str, size_t pos, const char *cstr);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid str_delete(string_t *str, size_t pos, size_t len);
daf029d2a627daa39d05507140f385162828172eTimo Sirainenvoid str_truncate(string_t *str, size_t len);
daf029d2a627daa39d05507140f385162828172eTimo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#endif
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen