bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila#include "lib.h"
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila#include "str.h"
16161da6716cb679e315d59146fa3d5a93b4f031Aki Tuomi#include "buffer.h"
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila#include "unichar.h"
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila#include "fts-filter-private.h"
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila#include "fts-filter-common.h"
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila#include "fts-tokenizer-common.h"
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovilavoid fts_filter_truncate_token(string_t *token, size_t max_length)
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila{
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila if (str_len(token) <= max_length)
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila return;
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila size_t len = max_length;
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila fts_tokenizer_delete_trailing_partial_char(token->data, &len);
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila str_truncate(token, len);
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila i_assert(len <= max_length);
5fcd30add8dcf4d883978cce3e39f3a89184f1e5Teemu Huovila}