jstewmc/rtf-token

Rich Text Format (RTF) tokens

v0.1.0 2016-12-10 21:13 UTC

This package is auto-updated.

Last update: 2024-04-29 03:44:13 UTC


README

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}

Tokens

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.

Group

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 "}"

Controls

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.

Control words

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)

Control symbol

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)

Text

The text token has a single property, text:

namespace Jstewmc\RtfToken;

$text = new Text('foo');

$text->getText();  // returns "foo"

(string) $text;  // returns "foo"

Other

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!

Author

Jack Clayton

Version

0.1.0, December 10, 2016

  • Initial release