[fpc-devel] Some new

J. Gareth Moreton gareth at moreton-family.com
Tue Mar 5 07:54:49 CET 2019


 Ah, okay.  In my case, it doesn't work if the set you specify is a
constant or variable defined elsewhere.

 e.g.

 const Delimiters: array[0..5] of Char = [#9, #10, #12, #13, #26, #32];

 if C in Delimiters then...
 If you do that, you get a compiler error about 'in' not being overloaded
or some such.

 Gareth aka. Kit

 On Tue 05/03/19 06:36 , Michael Van Canneyt michael at freepascal.org sent:

 On Tue, 5 Mar 2019, J. Gareth Moreton wrote: 

 > 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. 

 _______________________________________________
 fpc-devel maillist - fpc-devel at lists.freepascal.org [1]
 http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
[2]">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

 

Links:
------
[1] mailto:fpc-devel at lists.freepascal.org
[2] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190305/004b1913/attachment.html>


More information about the fpc-devel mailing list