Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2019-03

Some new "in" operator functions

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

J. Gareth Moreton

Hi everyone,

I've developed a couple of "in" operator overrides so you can use " in " (useful in parsing tools, say, to see if a character belongs to a set of delimiters) and " in ". e.g.

 operator in(_Char: Char; _Set: array of Char): Boolean;
 var
   C: Char;
 begin
   Result := False;
   for C in _Set do
     if C = _Char then
     begin
       Result := True;
       Exit;
     end;
 end;

Would these be welcome in one of the core units? And if so, which unit would you recommend?

Gareth aka. Kit

Reply by email

Michael Van Canneyt
to J. Gareth Moreton
J. Gareth Moreton wrote 21 lines
Hi everyone, I've developed a couple of "in" operator overrides so you can use " in " (useful in parsing tools, say, to see if a character belongs to a set of delimiters) and " in ". e.g. operator in(_Char: Char; _Set: array of Char): Boolean; var   C: Char; begin   Result := False;   for C in _Set do     if C = _Char then     begin       Result := True;       Exit;     end; end; Would these be welcome in one of the core units? And if so, which unit would you recommend?

At the risk of sounding stupid, but why would you want to add this if the compiler supports this out of the box ?

var
  C : char;
begin
   if ParamCount>0 then
     c:=paramstr(1)[1]
   else
     c:=#0;
   if c in ['a','b','c'] then
     writeln('ok')
   else
     writeln('not ok')
end.

Michael.

Reply by email