Press on the image to return to the main documentation page.
RichString
Written by Andrew Graham
This library contains RichString and RichStringBuilder objects. These objects are analogous to the normal String and StringBuilder. However RichStrings can contain formatting information that controls how they are drawn when used as the text in a View.
This library also contains a RichStringFormatter object. This object, once suitably initialised, will efficiently format RichStrings passed to it. For long strings that require many changes of format this is much more efficien than using the individual RichString formatting commands.
A RichString supports formatting of its contents at the individual character level. The formatting methods are available in two forms.
The first form accepts a start and index for the region of the RichString to format in the same way that regions of ordinary strings are specified.
The second form uses matched identifiers within the RichString contents to identify the regions to be formatted. The identifiers are arbitary strings used in pairs within the RichString content to bracket the regions to be formatted. Multiple regions within the RichString content can be specified in a single call.
RichStringBuilder is a mutable RichString unlike regular RichStrings which are immutable. RichStringBuilder is especially useful when you need to concatenate many RichStrings. Methods of a RichStringBuilder return itself so methods may be repeatedly invoked
A RichStringFormatter provides a very efficient way of applying multiple formats to a RichString using matched identifiers within the RichString contents to identify the regions to be formatted.
Each of the RichString format commands iterates along the entire RichString so applying several different formats to the same RichString invokes several iterations. This is fine for short strings like Labels but may take a significant time for longer text with more complicated formatting.
In constrast a RichStringFormatter will format a RichString in a single pass over the string. However in order to accomplish this some initialisation work is necessary to define the formatting tokens that will be accepted by the formatter. Once initialised a RichStringFormatter may be used repeatedly on RichStrings as long as they are using the same tokens for formatting as the RichStringFormatter was initialised to expect.
All formatting tokens must start and end with the characters specified in Initialize. Note that start and end characters need not be different, the same character can be used for both. Formatting tokens are case-sensitive and may be of arbitrary length.
Unlike XML or HTML formatting tokens do not need to be properly nested. They may overlap with no adverse effect and the resulting formatting will be as expected.