-
Notifications
You must be signed in to change notification settings - Fork 14
Util_Texts_Builders
Stephane Carrez edited this page Feb 7, 2018
·
3 revisions
The Util.Texts.Builders generic package was designed to provide string builders. The interface was designed to reduce memory copies as much as possible.
- The Builder type holds a list of chunks into which texts are appended.
- The builder type holds an initial chunk whose capacity is defined when the builder instance is declared.
- There is only an Append procedure which allows to append text to the builder. This is the only time when a copy is made.
- The package defines the Iterate operation that allows to get the content collected by the builder. When using the Iterate operation, no copy is performed since chunks data are passed passed by reference.
- The type is limited to forbid copies of the builder instance.
First, instantiate the package for the element type (eg, String):
package String_Builder is new Util.Texts.Builders (Character, String);
Declare the string builder instance with its initial capacity:
Builder : String_Builder.Builder (256);
And append to it:
String_Builder.Append (Builder, "Hello");
To get the content collected in the builder instance, write a procedure that recieves the chunk data as parameter:
procedure Collect (Item : in String) is ...
And use the Iterate operation:
String_Builder.Iterate (Builder, Collect'Access);
Generated by Dynamo from util-texts-builders.ads