SDDS ToolKit Programs and Libraries for C and Python
Loading...
Searching...
No Matches
SDDS
mdblib
compress.c
Go to the documentation of this file.
1
/**
2
* @file compress.c
3
* @brief Implements a simple string compression utility.
4
*
5
* This file provides the `compressString` function, which removes consecutive
6
* duplicate characters from a string when those characters appear in a
7
* reference string. It is typically used to collapse runs of whitespace or
8
* other repeated characters.
9
*
10
* @copyright
11
* - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
12
* - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
13
*
14
* @license
15
* This file is distributed under the terms of the Software License Agreement
16
* found in the file LICENSE included with this distribution.
17
*
18
* @author C. Saunders, R. Soliday
19
*/
20
21
#include "mdb.h"
22
#include <ctype.h>
23
24
/**
25
* @brief Eliminates repeated occurrences of characters in string t from string s.
26
*
27
* This function removes consecutive duplicate characters in string `s` that are present in string `t`.
28
*
29
* @param s Pointer to the string to be compressed. The string is modified in place.
30
* @param t Pointer to the string containing characters to remove from `s`.
31
* @return Pointer to the compressed string `s`.
32
*/
33
char
*
compressString
(
char
*s,
char
*t) {
34
register
char
*ptr, *ptr0, *tptr;
35
36
ptr = ptr0 = s;
37
while
(*ptr0) {
38
tptr = t;
39
while
(*tptr) {
40
if
(*tptr != *ptr0) {
41
tptr++;
42
continue
;
43
}
44
while
(*++ptr0 == *tptr)
45
;
46
tptr++;
47
ptr0--;
48
}
49
*ptr++ = *ptr0++;
50
}
51
*ptr = 0;
52
return
(s);
53
}
compressString
char * compressString(char *s, char *t)
Eliminates repeated occurrences of characters in string t from string s.
Definition
compress.c:33
Generated by
1.12.0