• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aremmell / libsir / 1127

17 Oct 2023 03:23PM UTC coverage: 95.227% (-0.06%) from 95.288%
1127

Pull #340

gitlab-ci

johnsonjh
Appease Windows

Signed-off-by: Jeffrey H. Johnson <trnsz@pobox.com>
Pull Request #340: Add in-place string mangling utilities

55 of 55 new or added lines in 2 files covered. (100.0%)

3811 of 4002 relevant lines covered (95.23%)

504977.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.18
/src/sirutils.c
1
/**
2
 * @file sirutils.c
3
 *
4
 * @brief String utility functions
5
 *
6
 * Miscellanous utility functions operating on NULL-terminated strings.
7
 *
8
 * @author    Jeffrey H. Johnson \<trnsz@pobox.com\>
9
 * @date      2018-2023
10
 * @version   2.2.4
11
 * @copyright The MIT License (MIT)
12
 *
13
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
14
 * this software and associated documentation files (the "Software"), to deal in
15
 * the Software without restriction, including without limitation the rights to
16
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
17
 * the Software, and to permit persons to whom the Software is furnished to do so,
18
 * subject to the following conditions:
19
 *
20
 * The above copyright notice and this permission notice shall be included in all
21
 * copies or substantial portions of the Software.
22
 *
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
26
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
27
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
 */
30
#include "sir/utils.h"
31

32
char* sir_strremove(char *str, const char *sub) {
23✔
33

34
  const char* p;
35
  char* r;
36
  char* q;
37

38
  if (!sub)
23✔
39
      return str;
×
40

41
  if (*sub && (q = r = strstr(str, sub)) != NULL) {
23✔
42
      size_t len = strnlen(sub, strlen (str));
23✔
43

44
      while ((r = strstr(p = r + len, sub)) != NULL)
23✔
45
          while (p < r)
×
46
              *q++ = *p++;
×
47

48
      while ((*q++ = *p++) != '\0')
46✔
49
          continue;
23✔
50
  }
51

52
  return str;
20✔
53
}
54

55
char* sir_strsqueeze(char *str) {
23✔
56
  unsigned long j;
57

58
  for (unsigned i = j = 0; str[i]; ++i)
759✔
59
      if ((i > 0 && !isspace((unsigned char)(str[i - 1])))
736✔
60
                 || !isspace((unsigned char)(str[i])))
391✔
61
          str[j++] = str[i];
414✔
62

63
  str[j] = '\0';
23✔
64

65
  return str;
23✔
66
}
67

68
char* sir_strredact(char *str, const char *sub, const char c) {
46✔
69
  char *p;
70

71
  if (!sub || !c || !(p = strstr(str, sub)))
46✔
72
      return str;
20✔
73

74
  (void)memset(p, c, strnlen(sub, strlen (str)));
23✔
75

76
  return sir_strredact(str, sub, c);
23✔
77
}
78

79
char* sir_strreplace (char *str, const char c, const char n) {
23✔
80
  char *i = str;
20✔
81

82
  if (!c || !n)
23✔
83
      return str;
×
84

85
  while ((i = strchr(i, c)) != NULL)
46✔
86
      *i++ = n;
23✔
87

88
  return str;
20✔
89
}
90

91
size_t sir_strcreplace(char *str, const char c, const char n, int32_t max) {
23✔
92
  char*  i   = str;
20✔
93
  size_t cnt = 0;
20✔
94

95
  if (!c || !n || !max)
23✔
96
      return cnt;
×
97

98
  while (cnt < (size_t)max && (i = strchr(i, c)) != NULL) {
46✔
99
      *i++ = n;
23✔
100
      cnt++;
23✔
101
  }
102

103
  return cnt;
20✔
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc