Examples Delphi

> Not sure about the exact syntax of html. Here's a
> state-driven parser.
With at least one bug :=)
I forgot to handle one state completely.. 2
lines have been inserted below.
regards,
Robert
> regards,
> Robert Friberg
>
>
>
> type TParseState =
> (tpsNormal,tpsInTag,tpsInQuote,tpsInEscape,tpsInComment);
> function StripTags(inStr:string):string;
> var state:TParseState;
> idx : integer;
> LenInStr : integer;
> QuoteChar:char;
> begin
> state := tpsNormal;
> Result := '';
> idx := 1;
> LenInStr := Length(inStr); {avoid repeated caclulation}
> while idx <= LenInStr do begin
> case state of
> tpsNormal : begin
> if inStr[idx] = '<' then state := tpsInTag
> else Result := Result + inStr[idx];
> end;
> tpsInTag: begin
> if inStr[idx] = '>' then state := tpsNormal
> else if Copy(inStr, idx-1, 3) = '' then begin
> state := tpsNormal;
> idx := idx + 2;
> end;
> end;
> end;
> idx := idx + 1;
> end;
> end;