This documentation is for Dovecot v1.x, see wiki2 for v2.x documentation.

Dynamic Strings

lib/str.h describes Dovecot's dynamically growing strings. Strings are actually only a simple wrapper on top of buffers. Even the string_t type is only a typedef of buffer_t, so it's possible to use buffer_*() functions with strings (although it's ugly so it should be avoided).

Once you're done modifying a string with str_*() functions, you can get it out as a NUL-terminated string with str_c() or str_c_modifiable(). These pointers shouldn't be accessed after modifying the string again, they could have moved elsewhere in memory and they're no longer guaranteed to be NUL-terminated.


  string_t *str = t_str_new(64);

  str_append(str, "hello world");
  str_printfa(str, "\nand %u", str_len(str));

  printf("%s\n", str_c(str));
} T_END;

String Handling Functions

lib/strfuncs.h contains a lot of functions intended to make string handling easier. They use C's NUL-terminated strings instead of Dovecot's dynamic strings.

String Escaping

lib/strescape.h contains functions to escape and unescape <">. <'> and <\> characters in strings using <\> character.\

Dovecot's internal protocols are often line-based with TAB as the field separator. This file also contains functions to escape and unescape such data.

None: Design/Strings (last edited 2010-01-17 01:47:07 by PascalVolk)