jai-like CTFE string formating

Manu via Digitalmars-d digitalmars-d at puremagic.com
Sat Aug 12 17:42:08 PDT 2017


On 13 August 2017 at 00:15, Stefan Koch via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Saturday, 12 August 2017 at 13:19:12 UTC, ixid wrote:
>
>> On Saturday, 12 August 2017 at 11:47:10 UTC, Stefan Koch wrote:
>>
>>> Whereas the following alternative takes 20 ms :
>>> {
>>>     import ctfe_utils;
>>>     pragma(msg, format_jai("Hello % % % % % % % % %", " I ", " just", "
>>> have" , " to", " concat", " a lot", " of", " strings ...", 9));
>>> }
>>>
>>> see for yourself:
>>> https://www.youtube.com/watch?v=T0BJxdt61RY
>>>
>>
>> Could we not improve the syntax to something like:
>>
>>      pragma(msg, format_jai("Hello %9", " I ", "
>>  just", " have" , " to", " concat", " a lot", " of", " strings
>>  ..."));
>>  }
>>
>> Or whatever is closest that doesn't step on the current print syntax.
>>
>
> The point of format is that you want to replace the % my the argument and
> then write more static text.
>
> "The Parameter '%' was null and it should not be"
> "Rule '%' was not found in catalog '%' is possible the closest match"
>

If you're keen to introduce a new function, I'd strongly suggest changing
to {1} {2} {3}, or %1 %2 %3, format/printf functions where you don't supply
the place index are useless a lot of the time and need to be rewritten,
which is a tedious task.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20170813/85c9ebbc/attachment.html>


More information about the Digitalmars-d mailing list