1 /* This file is part of GNU Mailutils
2 Copyright (C) 2009-2021 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library. If not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <stdlib.h>
22 #include <string.h>
23 #include <mailutils/types.h>
24 #include <mailutils/cctype.h>
25 #include <mailutils/cstr.h>
26
27 size_t
mu_rtrim_class(char * str,int class)28 mu_rtrim_class (char *str, int class)
29 {
30 size_t len;
31
32 if (!*str)
33 return 0;
34 for (len = strlen (str); len > 0 && mu_c_is_class (str[len-1], class); len--)
35 ;
36 str[len] = 0;
37 return len;
38 }
39
40 size_t
mu_rtrim_cset(char * str,const char * cset)41 mu_rtrim_cset (char *str, const char *cset)
42 {
43 size_t len;
44
45 if (!*str)
46 return 0;
47 for (len = strlen (str); len > 0 && strchr (cset, str[len-1]) != NULL; len--)
48 ;
49 str[len] = 0;
50 return len;
51 }
52