[fpc-pascal] Generic constants with generic type
Hi all! With the existing syntax of constants, it is good to pass array boundaries, but bad to initial parameter values. What do you think about such constructs: GTValue=... ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Mustache templates implementation
On Tue, 20 Apr 2021, leledumbo via fpc-pascal wrote: Since dmustache (part of mORMot) fails the official mustache tests and did not work on the platform I needed it for, I wrote my own implementation. I do remember it didn't pass all the tests, but still works for my needs so I let it be. My biggest beef is that it does not work on all platforms, because it pulls in some of mORMot. My implementation just needs the classes and sysutils units.. The result has been committed to packages/fcl-mustache, in case someone else has a need for it. Now thank you for this, I'll be sure to check it out to replace dmustache. I'm currently porting it to Delphi (where I'll eventually need it) and will publish those sources too on gitlab or so. Delphi's JSON handling is not compatible to FPC's so some minor changes are needed. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How does TFPGMap key compare work?
Am 21.04.2021 um 00:09 schrieb Ryan Joseph via fpc-pascal: On Apr 20, 2021, at 3:10 PM, Sven Barth wrote: If you look at TFPSMap' code you'll see that BinaryCompareKey and BinaryCompareData are only used in the way of method pointers OnKeyPtrCompare and OnDataPtrCompare. In TFPGMap<,> these are then set to compare methods specific to the specialization, most importantly TFPGMap<,>.KeyCompare if no custom compare function is set. There's no many levels of indirection here I got confused. I see this method below and so maybe the <> operators are overloaded for short strings? function TFPGMap.KeyCompare(Key1, Key2: Pointer): Integer; begin if PKey(Key1)^ < PKey(Key2)^ then Result := -1 else if PKey(Key1)^ > PKey(Key2)^ then Result := 1 else Result := 0; end; All four string types provide built in > and < operators: === code begin === program tstrcmp; {$mode objfpc}{$H+} var ss1, ss2: ShortString; as1, as2: AnsiString; us1, us2: UnicodeString; ws1, ws2: WideString; begin ss1 := 'Hello'; ss2 := 'World'; as1 := 'Hello'; as2 := 'World'; us1 := 'Hello'; us2 := 'World'; ws1 := 'Hello'; ws2 := 'World'; Writeln('ShortString: ', ss1 < ss2, ' ', ss1 > ss2); Writeln('AnsiString: ', as1 < as2, ' ', as1 > as2); Writeln('UnicodeString: ', us1 < us2, ' ', us1 > us2); Writeln('WideString: ', ws1 < ws2, ' ', ws1 > ws2); end. === code end === Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Mustache templates implementation
> Since dmustache (part of mORMot) fails the official mustache tests and did not work > on the platform I needed it for, I wrote my own implementation. I do remember it didn't pass all the tests, but still works for my needs so I let it be. > The result has been committed to packages/fcl-mustache, in case someone > else > has a need for it. Now thank you for this, I'll be sure to check it out to replace dmustache. -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How does TFPGMap key compare work?
> On Apr 20, 2021, at 3:10 PM, Sven Barth wrote: > > If you look at TFPSMap' code you'll see that BinaryCompareKey and > BinaryCompareData are only used in the way of method pointers OnKeyPtrCompare > and OnDataPtrCompare. In TFPGMap<,> these are then set to compare methods > specific to the specialization, most importantly TFPGMap<,>.KeyCompare if no > custom compare function is set. There's no many levels of indirection here I got confused. I see this method below and so maybe the <> operators are overloaded for short strings? function TFPGMap.KeyCompare(Key1, Key2: Pointer): Integer; begin if PKey(Key1)^ < PKey(Key2)^ then Result := -1 else if PKey(Key1)^ > PKey(Key2)^ then Result := 1 else Result := 0; end; Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How does TFPGMap key compare work?
Am 19.04.2021 um 19:05 schrieb Ryan Joseph via fpc-pascal: I have a question I was just curious about. From what I can tell TFPGMap uses CompareByte to compare keys of arbitrary type, which is clever but how does this work for ShortStrings? I have tried to use this method myself and I find it always fails because short strings have garbage at the end and so even if you zero out the memory (which is allocated) a short string passed as a parameter to a function will have garbage and thus fail to compare. Any ideas how this works for TFPGMap then? function TFPSMap.BinaryCompareKey(Key1, Key2: Pointer): Integer; begin Result := CompareByte(Key1^, Key2^, FKeySize); end; If you look at TFPSMap' code you'll see that BinaryCompareKey and BinaryCompareData are only used in the way of method pointers OnKeyPtrCompare and OnDataPtrCompare. In TFPGMap<,> these are then set to compare methods specific to the specialization, most importantly TFPGMap<,>.KeyCompare if no custom compare function is set. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Mustache templates implementation
Hello , For my job I needed a Mustache templates library in pascal. Since dmustache (part of mORMot) fails the official mustache tests and did not work on the platform I needed it for, I wrote my own implementation. The result has been committed to packages/fcl-mustache, in case someone else has a need for it. Basic Features: - TMustache Component, can be dropped on a form. - Compiles the template, so repeated output should be fast. - Passes all official testcases (including weird whitespace rules). - JSON data input by default. - Output easily configurable. Extra: - Integration with FPExprPars engine for expressions: {{[age + 2]}} will work. - You can use datasets as source of data. - Written to be easily extendable with other features. - Unit tested. Demos available, there is a complete usable command-line program that has all features enabled. Enjoy, Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal