home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
- # include "strings.h"
-
- function matchS{(s, pat: String):Nat0};
- {
- * Returns position of pat in s or 0 if not present.
- * Empty strings are not considered present!
- }
- var diff, lens, lenp, start, next: Nat0; nomatch: Boolean;
- begin
- lens := lengthS(s); lenp := lengthS(pat);
- if (lens = 0) or (lenp = 0) or (lenp > lens) then
- matchS := 0
- else begin
- start := 0;
- diff := lens - lenp;
- repeat
- start := start+1;
- next := 0;
- repeat
- next := next+1;
- nomatch := indexS(pat, next) <> indexS(s, start+next-1)
- until nomatch or (next = lenp);
- until not nomatch or (start > diff);
- if nomatch then matchS := 0 else matchS := start
- end;
- { -- possible that function called with constant string for pat }
- if pat <> nil then if pat^.REFS = 0 then disposeS(pat)
- end{ -- matchS};
-