Coverage Report

Created: 2024-02-25 06:34

/src/kamailio/src/core/trim.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2001-2003 FhG Fokus
3
 *
4
 * This file is part of Kamailio, a free SIP server.
5
 *
6
 * Kamailio is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version
10
 *
11
 * Kamailio is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
#ifndef TRIM_H
22
#define TRIM_H
23
24
#include "str.h"
25
26
27
/*!
28
 * This switch-case statement is used in
29
 * trim_leading and trim_trailing. You can
30
 * define characters that should be skipped
31
 * here.
32
 */
33
#define TRIM_SWITCH(c) \
34
365k
  switch(c) {        \
35
9.61k
    case ' ':      \
36
21.0k
    case '\t':     \
37
42.0k
    case '\r':     \
38
46.0k
    case '\n':     \
39
46.0k
      break;     \
40
42.0k
                       \
41
319k
    default:       \
42
319k
      return;    \
43
365k
  }
44
45
46
/*
47
 * Remove any leading whitechars, like spaces,
48
 * horizontal tabs, carriage returns and line
49
 * feeds
50
 *
51
 * WARNING: String descriptor structure will be
52
 *          modified ! Make a copy otherwise you
53
 *          might be unable to free _s->s for
54
 *          example !
55
 *
56
 */
57
static inline void trim_leading(str *_s)
58
307k
{
59
348k
  for(; _s->len > 0; _s->len--, _s->s++) {
60
343k
    TRIM_SWITCH(*(_s->s));
61
40.5k
  }
62
307k
}
parse_contact.c:trim_leading
Line
Count
Source
58
4.01k
{
59
5.21k
  for(; _s->len > 0; _s->len--, _s->s++) {
60
5.18k
    TRIM_SWITCH(*(_s->s));
61
1.19k
  }
62
4.01k
}
Unexecuted instantiation: parse_methods.c:trim_leading
parse_privacy.c:trim_leading
Line
Count
Source
58
993
{
59
2.06k
  for(; _s->len > 0; _s->len--, _s->s++) {
60
1.73k
    TRIM_SWITCH(*(_s->s));
61
1.07k
  }
62
993
}
parse_rr.c:trim_leading
Line
Count
Source
58
24.3k
{
59
31.0k
  for(; _s->len > 0; _s->len--, _s->s++) {
60
29.7k
    TRIM_SWITCH(*(_s->s));
61
6.69k
  }
62
24.3k
}
Unexecuted instantiation: ppcfg.c:trim_leading
Unexecuted instantiation: select_core.c:trim_leading
Unexecuted instantiation: sr_module.c:trim_leading
Unexecuted instantiation: strutils.c:trim_leading
Unexecuted instantiation: tcp_read.c:trim_leading
contact.c:trim_leading
Line
Count
Source
58
17.4k
{
59
30.9k
  for(; _s->len > 0; _s->len--, _s->s++) {
60
30.8k
    TRIM_SWITCH(*(_s->s));
61
13.5k
  }
62
17.4k
}
Unexecuted instantiation: digest_parser.c:trim_leading
Unexecuted instantiation: ip_addr.c:trim_leading
Unexecuted instantiation: kemi.c:trim_leading
Unexecuted instantiation: mod_fix.c:trim_leading
Unexecuted instantiation: param_parser.c:trim_leading
Unexecuted instantiation: parse_body.c:trim_leading
Unexecuted instantiation: parse_event.c:trim_leading
Unexecuted instantiation: parse_expires.c:trim_leading
parse_param.c:trim_leading
Line
Count
Source
58
260k
{
59
279k
  for(; _s->len > 0; _s->len--, _s->s++) {
60
275k
    TRIM_SWITCH(*(_s->s));
61
18.0k
  }
62
260k
}
Unexecuted instantiation: parse_sipifmatch.c:trim_leading
Unexecuted instantiation: parse_subscription_state.c:trim_leading
63
64
65
/*
66
 * Remove any trailing white char, like spaces,
67
 * horizontal tabs, carriage returns and line feeds
68
 *
69
 * WARNING: String descriptor structure will be
70
 *          modified ! Make a copy otherwise you
71
 *          might be unable to free _s->s for
72
 *          example !
73
 */
74
static inline void trim_trailing(str *_s)
75
23.9k
{
76
29.5k
  for(; _s->len > 0; _s->len--) {
77
22.1k
    TRIM_SWITCH(_s->s[_s->len - 1]);
78
5.57k
  }
79
23.9k
}
Unexecuted instantiation: parse_contact.c:trim_trailing
Unexecuted instantiation: parse_methods.c:trim_trailing
Unexecuted instantiation: parse_privacy.c:trim_trailing
Unexecuted instantiation: parse_rr.c:trim_trailing
Unexecuted instantiation: ppcfg.c:trim_trailing
Unexecuted instantiation: select_core.c:trim_trailing
Unexecuted instantiation: sr_module.c:trim_trailing
Unexecuted instantiation: strutils.c:trim_trailing
Unexecuted instantiation: tcp_read.c:trim_trailing
contact.c:trim_trailing
Line
Count
Source
75
23.9k
{
76
29.5k
  for(; _s->len > 0; _s->len--) {
77
22.1k
    TRIM_SWITCH(_s->s[_s->len - 1]);
78
5.57k
  }
79
23.9k
}
Unexecuted instantiation: digest_parser.c:trim_trailing
Unexecuted instantiation: ip_addr.c:trim_trailing
Unexecuted instantiation: kemi.c:trim_trailing
Unexecuted instantiation: mod_fix.c:trim_trailing
Unexecuted instantiation: param_parser.c:trim_trailing
Unexecuted instantiation: parse_body.c:trim_trailing
Unexecuted instantiation: parse_event.c:trim_trailing
Unexecuted instantiation: parse_expires.c:trim_trailing
Unexecuted instantiation: parse_param.c:trim_trailing
Unexecuted instantiation: parse_sipifmatch.c:trim_trailing
Unexecuted instantiation: parse_subscription_state.c:trim_trailing
80
81
82
/*
83
 * Do trim_leading and trim_trailing
84
 *
85
 * WARNING: String structure will be modified !
86
 *          Make a copy otherwise you might be
87
 *          unable to free _s->s for example !
88
 */
89
static inline void trim(str *_s)
90
7.95k
{
91
7.95k
  trim_leading(_s);
92
7.95k
  trim_trailing(_s);
93
7.95k
}
Unexecuted instantiation: parse_contact.c:trim
Unexecuted instantiation: parse_methods.c:trim
Unexecuted instantiation: parse_privacy.c:trim
Unexecuted instantiation: parse_rr.c:trim
Unexecuted instantiation: ppcfg.c:trim
Unexecuted instantiation: select_core.c:trim
Unexecuted instantiation: sr_module.c:trim
Unexecuted instantiation: strutils.c:trim
Unexecuted instantiation: tcp_read.c:trim
contact.c:trim
Line
Count
Source
90
7.95k
{
91
7.95k
  trim_leading(_s);
92
7.95k
  trim_trailing(_s);
93
7.95k
}
Unexecuted instantiation: digest_parser.c:trim
Unexecuted instantiation: ip_addr.c:trim
Unexecuted instantiation: kemi.c:trim
Unexecuted instantiation: mod_fix.c:trim
Unexecuted instantiation: param_parser.c:trim
Unexecuted instantiation: parse_body.c:trim
Unexecuted instantiation: parse_event.c:trim
Unexecuted instantiation: parse_expires.c:trim
Unexecuted instantiation: parse_param.c:trim
Unexecuted instantiation: parse_sipifmatch.c:trim
Unexecuted instantiation: parse_subscription_state.c:trim
94
95
96
/*
97
 * right and left space trimming
98
 *
99
 * WARNING: String structure will be modified !
100
 *          Make a copy otherwise you might be
101
 *          unable to free _s_->s for example !
102
 */
103
#define trim_spaces_lr(_s_)                                            \
104
  do {                                                               \
105
    for(; (_s_).s[(_s_).len - 1] == ' '; (_s_).s[--(_s_).len] = 0) \
106
      ;                                                          \
107
    for(; (_s_).s[0] == ' '; (_s_).s = (_s_).s + 1, (_s_).len--)   \
108
      ;                                                          \
109
                                                                       \
110
  } while(0);
111
112
/*
113
 * right and left zero trimming
114
 *
115
 * WARNING: String structure will be modified !
116
 *          Make a copy otherwise you might be
117
 *          unable to free _s_->s for example !
118
 */
119
#define trim_zeros_lr(_s_)                                                  \
120
  do {                                                                    \
121
    for(; (_s_)->s[(_s_)->len - 1] == '\0'; (_s_)->s[--(_s_)->len] = 0) \
122
      ;                                                               \
123
    for(; (_s_)->s[0] == '\0'; (_s_)->s = (_s_)->s + 1, (_s_)->len--)   \
124
      ;                                                               \
125
                                                                            \
126
  } while(0);
127
128
#endif /* TRIM_H */