aboutsummaryrefslogtreecommitdiff
path: root/fbwarn/src/extString.c
blob: abe672835a8ea6f0cb79bc78f9b9340f57b79bba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

char *strlwr(char *str)
{
  unsigned char *p = (unsigned char *)str;

  while (*p) {
     *p = tolower((unsigned char)*p);
      p++;
  }

  return str;
}

char *trim(char *str)
{
  char *result = strdup(str);
  char *end;

  while(isspace((unsigned char)*result)) result++;

  if(*result == 0)
    return result;

  end = result + strlen(result) - 1;
  while(end > result && isspace((unsigned char)*end)) end--;

  // Write new null terminator character
  end[1] = '\0';

  return result;
}