SDDSlib
Loading...
Searching...
No Matches
delete_bnd.c
Go to the documentation of this file.
1/**
2 * @file delete_bnd.c
3 * @brief Implementation of string manipulation routine.
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#include <ctype.h>
18
19/**
20 * @brief Deletes bounding characters from a string.
21 *
22 * Removes all leading and trailing characters from the string `s` that are present in the string `t`.
23 *
24 * @param s The string to be modified.
25 * @param t The string containing bounding characters to remove from `s`.
26 * @return The modified string `s`.
27 */
28char *delete_bounding(s, t) char *s, *t;
29{
30 register char *ptr1, *ptr0, *ptrt;
31
32 if (!s)
33 return (s);
34 ptr0 = s;
35 while (*ptr0) {
36 ptrt = t;
37 while (*ptrt && *ptrt != *ptr0)
38 ptrt++;
39 if (*ptrt == *ptr0)
40 ptr0++;
41 else
42 break;
43 }
44
45 ptr1 = ptr0 + strlen(ptr0) - 1;
46 while (ptr1 != ptr0) {
47 ptrt = t;
48 while (*ptrt && *ptrt != *ptr1)
49 ptrt++;
50 if (*ptrt == *ptr1)
51 ptr1--;
52 else
53 break;
54 }
55
56 *++ptr1 = 0;
57 strcpy_ss(s, ptr0);
58 return (s);
59}
char * delete_bounding(char *s, char *t)
Deletes bounding characters from a string.
Definition delete_bnd.c:28
char * strcpy_ss(char *dest, const char *src)
Safely copies a string, handling memory overlap.
Definition str_copy.c:34