You.i Engine
CYIYouIMarkupParser Class Reference

Detailed Description

This class implements a text markup parser for the You.I text markup.

Markup Details

The You.I markups is composed of tags in the format \{tagKey:tagValue}. For example:

The \{font-style:Oblique}quick\{end} brown fox \{font-size:40}jumps \{sub}over\{} the lazy dog.\{}

Tags take effect from where they are encountered until the end of the text, unless an end tag ( \{end} ) is encountered. Thus, closing tags is optional. Each end tag 'ends' a single previously-occuring tag (excluding 'end' tags themselves).

For some tags, the 'value' is optional (such as the \{sub} tag). For other, a value must be specified after a semi-colon.

Spaces before tag keys, after tag keys, before tag values and after tag values are ignored. For example, each of the following tags are equivalent: \{key:value} \{ key:value} \{key: value} \{key: value } \{ key : value }. Tag keys will never have spaces, but tag values might.

Tag values can optionally be surrounded by double quotes to ensure that spaces do not get trimmed. Using double quotes is also required if the tag value contains the ';' or '}' characters, which otherwise would demark the end of a tag or the end of a tag value. Single quotes may not be used to quote strings. Within a quoted value, double quotes must be escaped using \" and backslashes must be escaped using \\ . For example:

\{key:"value \"with\" \\quotes"}

Multiple tag keys can be placed within the same tag by separating them with a semi-colon. Spaces around the semi-colon are ignored. For example:

\{key1:value1; key2:value2}

The character combination '\{' should be escaped using the \{\} or \{escape} tags. For example:

This is a \{\}tag}. 

External Tags

External styles can be provided through a CYICustomTagsProvider pointer. External styles are specified using the 'style' tag like so: \{style:myCustomStyle} . This tells the markup parser to query the CYICustomTagsProvider for the style name 'myCustomStyle'. The tags provider is expected to return a semi-colon separated list of key-value pairs, which will then be parsed. The format of that key-value pairs list is the same as the tags content.

Supported Tags

The following tags are supported:

\{} or \{end}: ends the last non-ended and non-ending tag
\{\} or \{escape}: inserts the text '\{'
\{font-family:tagValue}: set the current font family to tagValue
\{font-style:tagValue}: set the current font style to tagValue
\{font-size:tagValue}: set the current font size to tagValue
\{color:tagValue}: changes the text color to tagValue. See the \a ParseColor function for allowed values.
\{leading:tagValue}: sets the leading to tagValue
\{tracking:tagValue}: sets the tracking to tagValue
\{kerning:tagValue}: sets the kerning to tagValue
\{baseline-shift:tagValue}: sets the baseline shift to tagValue
\{all-caps}: changes the text mode to 'all caps'
\{sub} or \{subscript}: changes the text mode to 'subscript'
\{sup} or \{superscript}: changes the text mode to 'superscript'
\{u} or \{underline}: changes the text mode to 'underlined'
\{style:styleName}: inserts external tags identified by styleName

#include <utility/YiYouIMarkupParser.h>

Inheritance diagram for CYIYouIMarkupParser:

Public Member Functions

virtual bool ParseMarkup (const CYIString &rMarkupText, const CYITextSceneNode::YI_TEXT_STYLE_DEF &rDefaultStyle, const CYICustomMarkupTagsProvider *pExternalTagsProvider, bool logErrors, CYIString *pParsedText, std::vector< CYITextSceneNode::YI_TEXT_STYLE_DEF > *pStyles) const override
- Public Member Functions inherited from CYITextMarkupParser
virtual ~CYITextMarkupParser ()

Static Public Member Functions

static bool HasMarkup (const CYIString &rText)
static bool GetNextTagContent (const CYIString &input, const CYIString::ConstIterator &startPosition, CYIString *pTagContent, CYIString::ConstIterator *pTagStartPosition, CYIString::ConstIterator *pNextPosition, bool logErrors, bool *pErrorEncountered)

Member Function Documentation

◆ GetNextTagContent()

static bool CYIYouIMarkupParser::GetNextTagContent ( const CYIString input,
const CYIString::ConstIterator startPosition,
CYIString pTagContent,
CYIString::ConstIterator pTagStartPosition,
CYIString::ConstIterator pNextPosition,
bool  logErrors,
bool *  pErrorEncountered 

Locates and parses the next tag in the provided input string input, starting at position startPosition. The tag content will be placed in pTagContent, with the iterator to the first character of the tag (e.g. the \ character) being placed in the pTagStartPosition parameter and the iterator to the first character following the tag being placed in the nextPosition parameter.

If logErrors is true and errors are encountered, a message will be logged to the console and the pErrorEncountered parameter will be set to true .

Starting a tag search within a tag will result in undefined behaviour.
true if a tag was found.

◆ HasMarkup()

static bool CYIYouIMarkupParser::HasMarkup ( const CYIString rText)

Checks if the provided text rText contains markup that would need to be parsed. This can be used as a 'fast' check to see if a string needs to be parsed for markup.

true if rText contains markup.

◆ ParseMarkup()

virtual bool CYIYouIMarkupParser::ParseMarkup ( const CYIString rMarkupText,
const CYITextSceneNode::YI_TEXT_STYLE_DEF rDefaultStyle,
const CYICustomMarkupTagsProvider pExternalTagsProvider,
bool  logErrors,
CYIString pParsedText,
std::vector< CYITextSceneNode::YI_TEXT_STYLE_DEF > *  pStyles 
) const

Parses the marked-up text rMarkupText, generating a list of styles and storing them in pStyles.

See also

Implements CYITextMarkupParser.

The documentation for this class was generated from the following file: