Rich Text Format (RTF) tokens.
namespace Jstewmc\RtfToken;
$open = new Group\Open();
$control = new Control\Word('foo');
$text = new Text('bar');
$close = new Group\Close();
echo $open . $control . $text . $close;
The example above would output the following:
{\foo bar}
This library includes tokens for the Rich Text Format (RTF) language including:
- open-group (i.e.,
{
), - close-group (i.e.,
}
), - control word (e.g.,
\b
), - control symbol (e.g.,
\*
), - text (e.g.,
foo
), and - other (e.g.,
\0
).
The properties of each token differ, but all tokens implement the _toString()
magic method.
This library supports two group tokens: Group\Open
and Group\Close
. They have no properties:
namespace Jstewmc\RtfToken\Group;
(string) (new Open()); // returns "{"
(string) (new Close()); // returns "}"
This library supports control word and control symbol tokens.
By default, control tokens are space-delimited. However, this can be turned off using the setIsSpaceDelimited()
method.
The control word token has a word and (optional) integer parameter property:
namespace Jstewmc\RtfToken\Control;
$word = new Word('b', 0);
$word->getWord(); // returns "b"
$word->getParameter(); // returns 0
(string) $word; // returns "\b0 "
$word->setIsSpaceDelimited(false);
(string) $word; // returns "\b0" (note, no space)
The control symbol token has a symbol and mixed parameter property:
namespace Jstewmc\RtfToken\Control;
$symbol = new Symbol('\'', 99);
$symbol->getSymbol(); // returns "'"
$symbol->getParameter(); // returns 99
(string) $symbol; // returns "\'99 "
$symbol->setIsSpaceDelimited(false);
(string) $symbol; // returns "\'99" (note, no space)
The text token has a single property, text:
namespace Jstewmc\RtfToken;
$text = new Text('foo');
$text->getText(); // returns "foo"
(string) $text; // returns "foo"
The "other" token exists for any character that isn't an open-group, close-group, control word, control symbol, or text token. Usually, this includes special characters like line-feeds ("\n"), carriage-returns ("\r"), etc.
The "other" token has a single property, character:
namespace Jstewmc\RtfToken;
$other = new Other("\n");
$other->getCharacter(); // returns "\n"
(string) $other; // returns "\n"
That's about it!
- Initial release