aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
blob: 328a9cc7bb413c5a93439cdd7fe4c76c5123425f (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
35
36
37
38
/*
 * =====================================================================================
 *
 *       Filename:  util.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  01/28/2022 03:47:07 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

char* trimwhitespace(char* str) {
    char* end;

    // Trim leading spaces
    while(isspace((unsigned char) *str)) str++;

    if (*str == 0) // All spaces?
        return str;

    // trailing spaces
    end = str + strlen(str) -1;
    while (end > str && isspace((unsigned char)* end)) end--;

    end[1] = '\0';

    return str;
}