* Simple string template formatter (Dmitry A. Kazakov take note)
@ 2017-11-22 20:23 Victor Porton
2017-11-22 20:44 ` Victor Porton
2017-11-22 22:26 ` Dmitry A. Kazakov
0 siblings, 2 replies; 3+ messages in thread
From: Victor Porton @ 2017-11-22 20:23 UTC (permalink / raw)
I created a simple string template formatter (no if-then-else, no include,
just substitution of variables).
Example:
"First phrase: {1}. Second phrase: {2}."
This formatter is suitable for short strings, such as phrases for gettext.
https://github.com/vporton/xml-boiler/blob/master/src/boiler-auxiliary-string_formatter.ads
https://github.com/vporton/xml-boiler/blob/master/src/boiler-auxiliary-string_formatter.adb
My code was not tested!
Dmitry, I ask you to add something like this to your Simple Components.
My program anyway uses Simple Components, so after you implement it, I can
remove these files from my sources.
I released the files in question both GPLv3 and Apache License 2.0. So feel
free to use it as a coding example.
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Simple string template formatter (Dmitry A. Kazakov take note)
2017-11-22 20:23 Simple string template formatter (Dmitry A. Kazakov take note) Victor Porton
@ 2017-11-22 20:44 ` Victor Porton
2017-11-22 22:26 ` Dmitry A. Kazakov
1 sibling, 0 replies; 3+ messages in thread
From: Victor Porton @ 2017-11-22 20:44 UTC (permalink / raw)
Victor Porton wrote:
> I created a simple string template formatter (no if-then-else, no include,
> just substitution of variables).
>
> Example:
>
> "First phrase: {1}. Second phrase: {2}."
>
> This formatter is suitable for short strings, such as phrases for gettext.
>
> https://github.com/vporton/xml-boiler/blob/master/src/boiler-auxiliary-string_formatter.ads
> https://github.com/vporton/xml-boiler/blob/master/src/boiler-auxiliary-string_formatter.adb
>
> My code was not tested!
>
> Dmitry, I ask you to add something like this to your Simple Components.
>
> My program anyway uses Simple Components, so after you implement it, I can
> remove these files from my sources.
>
> I released the files in question both GPLv3 and Apache License 2.0. So
> feel free to use it as a coding example.
I did a small performance improvement in the sources at GitHub.
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Simple string template formatter (Dmitry A. Kazakov take note)
2017-11-22 20:23 Simple string template formatter (Dmitry A. Kazakov take note) Victor Porton
2017-11-22 20:44 ` Victor Porton
@ 2017-11-22 22:26 ` Dmitry A. Kazakov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry A. Kazakov @ 2017-11-22 22:26 UTC (permalink / raw)
On 2017-11-22 21:23, Victor Porton wrote:
> I created a simple string template formatter (no if-then-else, no include,
> just substitution of variables).
>
> Example:
>
> "First phrase: {1}. Second phrase: {2}."
>
> This formatter is suitable for short strings, such as phrases for gettext.
>
> https://github.com/vporton/xml-boiler/blob/master/src/boiler-auxiliary-string_formatter.ads
> https://github.com/vporton/xml-boiler/blob/master/src/boiler-auxiliary-string_formatter.adb
>
> My code was not tested!
>
> Dmitry, I ask you to add something like this to your Simple Components.
Thanks, but I specifically avoid this ugly paradigm. String editing in
Simple Components deploys a different schema of consequent reading input
/ writing output string:
Put
( Destination : in out String;
Pointer : in out Integer; -- Moving update position
Value : Something;
Field : Natural := 0;
Justify : Alignment := Left;
Fill : Character := ' '
);
Formatting is one of bad ideas FORTRAN gave us. It is necessarily
untyped, inefficient and unsafe. Microsoft has more than a dozen
incarnations of sprintf which is a perfect illustration that the idea is
just beyond any hope.
I also intentionally avoid so-called "global" operations on strings.
That is operations taking string as a whole as opposed to "local"
operations dealing with a string slice. Most "global" operations: find,
index, substitute, split, translate, tokenize, copy etc are bad. Format
is a "global" operation. For practical purpose of text processing
nothing of this is required or makes code clean.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-22 22:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-22 20:23 Simple string template formatter (Dmitry A. Kazakov take note) Victor Porton
2017-11-22 20:44 ` Victor Porton
2017-11-22 22:26 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox