SDDSlib
Loading...
Searching...
No Matches
trim_spaces.c
Go to the documentation of this file.
1/**
2 * @file trim_spaces.c
3 * @brief Implementation of trim_spaces function..
4 *
5 * @copyright
6 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
7 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
8 *
9 * @license
10 * This file is distributed under the terms of the Software License Agreement
11 * found in the file LICENSE included with this distribution.
12 *
13 * @author M. Borland, C Saunders, R. Soliday
14 */
15
16#include "mdb.h"
17
18/**
19 * @brief Trims leading and trailing spaces from a string.
20 *
21 * This function removes all leading and trailing space characters from the
22 * input string `s` by modifying it in place. It returns a pointer to the
23 * trimmed string.
24 *
25 * @param s The string to be trimmed.
26 * @return A pointer to the trimmed string.
27 */
28char *trim_spaces(char *s) {
29 char *ptr;
30 if (strlen(s) == 0)
31 return (s);
32 ptr = s;
33 while (*ptr == ' ')
34 ptr++;
35 if (ptr != s)
36 strcpy_ss(s, ptr);
37 ptr = s + strlen(s) - 1;
38 while (*ptr == ' ' && ptr != s)
39 ptr--;
40 *++ptr = 0;
41 return (s);
42}
char * strcpy_ss(char *dest, const char *src)
Safely copies a string, handling memory overlap.
Definition str_copy.c:34
char * trim_spaces(char *s)
Trims leading and trailing spaces from a string.
Definition trim_spaces.c:28