This documentation is for Dovecot v2.x, see wiki1 for v1.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). The decision of whether to use a string_t or a buffer_t is mainly for human readability: if the buffer's contents are (ASCII/UTF8) text use string_t, otherwise for binary data use buffer_t.

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.

Design/Strings (last edited 2016-04-08 06:19:33 by TimoSirainen)