OutputWrapper
in package
Simple output wrapper for "tagged outputs" instead of wordwrap(). This solution is based on a StackOverflow answer: https://stackoverflow.com/a/20434776/1476819 from user557597 (alias SLN).
(?: # -- Words/Characters ( # (1 start) (?> # Atomic Group - Match words with valid breaks .{1,16} # 1-N characters # Followed by one of 4 prioritized, non-linebreak whitespace (?: # break types: (?<= [^\S\r\n] ) # 1. - Behind a non-linebreak whitespace [^\S\r\n]? # ( optionally accept an extra non-linebreak whitespace ) | (?= \r? \n ) # 2. - Ahead a linebreak | $ # 3. - EOS | [^\S\r\n] # 4. - Accept an extra non-linebreak whitespace ) ) # End atomic group | .{1,16} # No valid word breaks, just break on the N'th character ) # (1 end) (?: \r? \n )? # Optional linebreak after Words/Characters | # -- Or, Linebreak (?: \r? \n | $ ) # Stand alone linebreak or at EOS )
Tags
Table of Contents
Constants
- TAG_CLOSE_REGEX_SEGMENT = '[a-z][^<>]*+'
- TAG_OPEN_REGEX_SEGMENT = '[a-z](?:[^\\\\<>]*+ | \\\\.)*'
- URL_PATTERN = 'https?://\S+'
Properties
- $allowCutUrls : bool
Methods
- __construct() : mixed
- wrap() : string
Constants
TAG_CLOSE_REGEX_SEGMENT
private
mixed
TAG_CLOSE_REGEX_SEGMENT
= '[a-z][^<>]*+'
TAG_OPEN_REGEX_SEGMENT
private
mixed
TAG_OPEN_REGEX_SEGMENT
= '[a-z](?:[^\\\\<>]*+ | \\\\.)*'
URL_PATTERN
private
mixed
URL_PATTERN
= 'https?://\S+'
Properties
$allowCutUrls
private
bool
$allowCutUrls
= false
Methods
__construct()
public
__construct([bool $allowCutUrls = false ]) : mixed
Parameters
- $allowCutUrls : bool = false
wrap()
public
wrap(string $text, int $width[, string $break = "
" ]) : string
Parameters
- $text : string
- $width : int
- $break : string = " "