Coverage Report

Created: 2025-07-11 06:14

/src/clib/deps/trim/trim.c
Line
Count
Source (jump to first uncovered line)
1
2
//
3
// trim.c
4
//
5
// Copyright (c) 2013 Stephen Mathieson
6
// MIT licensed
7
//
8
9
10
#include <ctype.h>
11
#include <string.h>
12
#include "trim.h"
13
14
0
char *trim_left(char *str) {
15
0
  int len = strlen(str);
16
0
  char *cur = str;
17
18
0
  while (*cur && isspace(*cur)) {
19
0
    ++cur;
20
0
    --len;
21
0
  }
22
23
0
  if (str != cur) {
24
0
    memmove(str, cur, len + 1);
25
0
  }
26
27
0
  return str;
28
0
}
29
30
0
char *trim_right(char *str) {
31
0
  int len = strlen(str);
32
0
  char *cur = str + len - 1;
33
34
0
  while (cur != str && isspace(*cur)) {
35
0
    --cur;
36
0
    --len;
37
0
  }
38
39
0
  cur[isspace(*cur) ? 0 : 1] = '\0';
40
41
0
  return str;
42
0
}
43
44
0
char *trim(char *str) {
45
0
  trim_right(str);
46
0
  trim_left(str);
47
0
  return str;
48
0
}