home *** CD-ROM | disk | FTP | other *** search
- TYPE
- match_type = (next_match, last_match, next_unmatch, last_unmatch);
-
- FUNCTION match_char(match_str: str255; ifirst:INTEGER; target_char: byte;
- match_spec: match_type): INTEGER;
-
- VAR
- n:INTEGER;
- next, match, more: BOOLEAN;
-
- BEGIN
-
- n := LENGTH(match_str);
-
- IF n > 0 THEN
- BEGIN
- next := (match_spec = next_match) OR (match_spec = next_unmatch);
- match := (match_spec = next_match) OR (match_spec = last_match);
-
- n := ifirst;
- IF next
- THEN
- BEGIN
- IF n < 1 THEN n := 1;
- IF n > LENGTH(match_str) THEN n := 0;
- END {next}
- ELSE {NOT next}
- BEGIN
- IF n < 1 THEN n := 0;
- IF n > LENGTH(match_str) THEN n := LENGTH(match_str);
- END; {NOT next} {For IF next}
- END; {IF n > 0}
-
- IF n > 0 THEN
- BEGIN {Avoid dangling ELSE}
- IF next
- THEN
- BEGIN
- {Use more rather than AND to avoid evaluating
- match_str[LENGTH(match_str) +1]}
- IF match
- THEN more := (ORD(match_str[n]) <> target_char)
- ELSE more := (ORD(match_str[n]) = target_char);
- WHILE more DO
- BEGIN
- n := n + 1;
- more := (n <= LENGTH(match_str));
- IF more THEN
- IF match
- THEN more := (ORD(match_str[n]) <> target_char)
- ELSE more := (ORD(match_str[n]) = target_char);
- END; {WHILE more}
- IF n > LENGTH(match_str) THEN n := 0;
- END {if next}
- ELSE {last}
- BEGIN
- IF match
- THEN WHILE (n > 0) AND (ORD(match_str[n]) <> target_char)
- DO n := n - 1
- ELSE WHILE (n > 0) AND (ORD(match_str[n]) = target_char)
- DO n := n - 1;
- IF n <= 0 THEN n := 0;
- END; {last} {For IF next}
- END; {IF n > 0}
- match_char := n;
- END; {match_char}
-