str-sanitize.c revision 6aadd1c52e6b291d47b47b4f4063e9bc8ccf0784
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Copyright (c) 2004-2015 Dovecot authors, see the included COPYING file */
9c6a09aa16095ff72837799a37e0e3b3e93bb3d8Timo Sirainenstatic size_t str_sanitize_skip_start(const char *src, size_t max_bytes)
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainen for (i = 0; i < max_bytes && src[i] != '\0'; ) {
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainen int len = uni_utf8_get_char_n(src+i, max_bytes-i, &chr);
f37ecd72aad9b806aae83f71bacafdce32146945Timo Sirainenstatic void str_sanitize_truncate_char(string_t *dest, unsigned int initial_pos)
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainen /* truncate UTF-8 sequence. */
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainen while (len > 0 && (data[len-1] & 0xc0) == 0x80)
b68b98e1545bad8af9cb58ef89e8d7f6e16577beAki Tuomivoid str_sanitize_append(string_t *dest, const char *src, size_t max_bytes)
b68b98e1545bad8af9cb58ef89e8d7f6e16577beAki Tuomi int len = uni_utf8_get_char_n(src+i, max_bytes-i, &chr);
b68b98e1545bad8af9cb58ef89e8d7f6e16577beAki Tuomi break; /* input ended too early */
541f258d86b2db26efd5670883966183b4fb6323Timo Sirainen /* invalid UTF-8 */
541f258d86b2db26efd5670883966183b4fb6323Timo Sirainenconst char *str_sanitize(const char *src, size_t max_bytes)