Recommend this page to a friend! |
Classes of Caleb | PHP Common Class Library | _docs/ComplexStringHandler.md | Download |
|
DownloadDocumentation for the "ComplexStringHandler" class.The complex string handler class provides an easy way to iterate over the parts of a given string, identified by a given pattern, in order to execute a given closure to those parts of the given string, or to the glue that separates those parts. How to use:ComplexStringHandler constructor.
The first parameter, All parameters are optional. The constructor allows this information to be supplied to the object during instantiation, but it can also be supplied to the object after instantiation, too. An instance of ComplexStringHandler is effectively reusable, capable of performing multiple, unrelated operations to multiple, unrelated strings (though instantiation of a new object for subsequent operations may perhaps result in cleaner, more maintainable code in many cases). A simple example, to demonstrate two different ways to achieve the same results:
Output:
generateMarkers method.The generateMarkers method identifies potential delimiters (or glue) within the previously supplied string, using a pattern supplied as the method's sole parameter.
iterateClosure method.The iterateClosure method, depending on whether its second parameter is true or false, iterates over either the substrings, or the delimiters/glue, as per previously identified by generateMarkers, of the previously supplied string, and during iteration, uses the callable/closure supplied as the method's first parameter to process those substrings or delimiters/glue.
recompile method.The recompile method returns a string created using the substrings and delimiters/glue of the previously supplied string, generally intended to be called after any necessary processing has been completed. It accepts no parameters.
Last Updated: 22 May 2019 (2019.05.22). |