aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/selector/trstrim.x
blob: dfcf9d55e9cc9d803756c2589ffa99e83d7fe715 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
define	BLANK		' '

#* HISTORY *
#* B.Simon	24-Jul-92	Original
#* B.Simon	17-Dec-97	Copied from old cdbs for use in row selector

# This procedure removes leading and trailing whitespace and compresses 
# interior whitepace to a single blank. Whitespace is defined to be any 
# character with an ascii value less than or equal to that of the blank.
# 

# TRSTRIM -- Remove non-significant whitespace from string

int procedure trstrim (str)

char	str[ARB]	# u: String to be modified
#--
bool	flag
int	ic, jc

begin
	# Initialize flag to true so that leading blanks are skipped

	jc = 1
	flag = true

	# Convert control characters to blanks, skip multiple blanks

	for (ic = 1; str[ic] != EOS; ic = ic + 1) {

	    if (str[ic] > BLANK) {
		flag = false
		if (jc < ic)
		    str[jc] = str[ic]
		jc = jc + 1

	    } else {
		if (! flag) {
		    flag = true
		    str[jc] = ' '
		    jc = jc + 1
		}
	    }
	}

	# Remove trailing blanks

	if (flag && jc > 1)
	    jc = jc - 1

	str[jc] = EOS
	return (jc - 1)

end