40 #ifndef _uimarkupparser_cpp
41 #define _uimarkupparser_cpp
43 #include "UI/markupparser.h"
44 #include "UI/character.h"
46 #include "UI/sprite.h"
47 #include "UI/texttoken.h"
75 const Integer TextSize = Text.size();
77 UInt32 SlashPos = Text.find_first_of(
'/');
81 String TagName = Text.substr(SlashPos + 1,Text.find_first_of(this->GetMarkupTagEnd()) - SlashPos - 1);
83 }
else if( SlashPos == String::npos ) {
87 String SeparatorChars(
" =");
91 Position = Text.find_first_of(SeparatorChars);
92 String TagName = Text.substr(1,Position - 1);
96 if( TagIt != this->
Tags.end() ) {
98 if( (*TagIt).second->IsRangeTag() ) {
111 if( Text[Position] ==
'=' ) {
112 TagParams[
"Value"] = Text.substr(Position + 1,TextSize - Position - 1);
113 }
else if( Text[Position] ==
' ' ) {
115 String ParamEndChars(
" ");
117 while( Position < TextSize - 1 )
119 String ParamName, ParamValue;
121 UInt32 SeparatorPos = Text.find_first_of(
'=');
122 if( SeparatorPos != String::npos ) ParamName = Text.substr(Position + 1,SeparatorPos - Position - 1);
125 UInt32 PairEndPos = Text.find_first_of(ParamEndChars);
126 if( SeparatorPos != String::npos ) ParamValue = Text.substr(SeparatorPos + 1,PairEndPos - SeparatorPos - 1);
129 TagParams[ParamName] = ParamValue;
130 Position = PairEndPos;
134 CastedTag->
Params.swap(TagParams);
148 Int32 BytesAdvance = 0;
149 const char* StrBuf = Token->
Text.data();
151 while( static_cast<UInt32>(Position) < Token->
Text.size() )
154 if( GlyphID == -1 ) {
159 if( TheGlyph == NULL ) {
161 ExceptionStream <<
"Attempting to parse unknown Glyph ID: " << GlyphID <<
". Provided font (" << Traits.
CharFont->
GetName() <<
") does not contain that Glyph.";
168 Characters.push_back(NewChar);
170 Position += BytesAdvance;
176 for(
ConstTagVecIterator TagIt = ActiveTags.begin() ; TagIt != ActiveTags.end() ; ++TagIt )
179 (*TagIt).second->Process( (*TagIt).first->Params, Traits, Layer );
198 return GeneratedCharacters;
214 switch( (*TokIt)->Type )
224 CurrToken->
RenderSize = CharacterSegment.size();
225 GeneratedCharacters.splice(GeneratedCharacters.end(),CharacterSegment);
233 if( TagIt !=
Tags.end() ) {
235 if( (*TagIt).second->IsRangeTag() ) {
243 CharacterSegment.push_back(Res.second);
246 ActiveTags.push_back(
TokenTagPair( CurrToken,(*TagIt).second ) );
261 if( !CharacterSegment.empty() ) {
262 CurrToken->
RenderSize = CharacterSegment.size();
263 GeneratedCharacters.splice(GeneratedCharacters.end(),CharacterSegment);
273 for( TagVector::reverse_iterator TagIt = ActiveTags.rbegin() ; TagIt != ActiveTags.rend() ; ++TagIt )
277 ActiveTags.erase( --(TagIt.base()) );
280 CurrentTraits = InitialTraits;
285 CurrToken->
RenderSize = CharacterSegment.size();
286 GeneratedCharacters.splice(GeneratedCharacters.end(),CharacterSegment);
295 if( TagIt !=
Tags.end() ) {
299 CharacterSegment.push_back(Res.second);
306 CurrToken->
RenderSize = CharacterSegment.size();
307 GeneratedCharacters.splice(GeneratedCharacters.end(),CharacterSegment);
312 return GeneratedCharacters;
322 while( Position < Source.size() )
325 size_t TagStartPos = Source.find_first_of( this->
GetMarkupTagStart(), Position );
328 if( TagStartPos == String::npos ) {
332 }
else if( TagStartPos - Position > 0 ) {
338 size_t TagEndPos = Source.find_first_of( this->
GetMarkupTagEnd(), TagStartPos );
341 if( TagEndPos == String::npos ) {
364 Position = TagEndPos + 1;
int32_t Int32
An 32-bit integer.
This contains simple tools for indexing with UTF8 characters swiftly.
This class represents a normal text segment from the source string.
NameValuePairMap Params
The parameters provided for this tag, if any.
virtual CharacterContainer ParseTextTokens(TokenString *Tokens, const CharacterTraits &InitialTraits, TextLayer *CallingLayer) const
Processes a collection of text tokens into a list of renderable characters.
std::list< Character * > CharacterContainer
Basic container type for the storage of Character instances used during processing by this class...
virtual ~MarkupParser()
Class destructor.
String TagName
Unconverted version of the tag name.
This struct represents a markup tag segment from the source string.
This is a helper class that facilitates operations with collections of tokens generated from Markup P...
Used to describe a single tag used to insert a special character (such as s sprite).
Class used to describe a single glyph or character available for text operations. ...
Used to describe any generic error with a token.
TagVector::const_iterator ConstTagVecIterator
Const Iterator type for TokenTagPair instances being processed by this class.
virtual Char8 GetMarkupTagStart() const =0
Gets the ID for the character that marks the start of a markup section.
Used to describe the end of a range tag.
UInt32 RenderSize
The number of rendered characters this token produced.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
int Integer
A datatype used to represent any integer close to.
ReverseTokenIterator ReverseBeginToken()
Gets a reverse iterator to the last TextToken.
const String & GetTagName() const
Gets the name of the tag this token represents.
virtual TokenString * Lex(const String &Source) const
Converts a string into a series of tokens that can be parsed more readily.
This class stores common data for determining the look of a Character.
This implements the exception hiearchy for Mezzanine.
FontData * CharFont
The font this Character belongs to.
virtual CharacterContainer Parse(const String &Source, const CharacterTraits &InitialTraits, TextLayer *CallingLayer) const
Processes a string encoded in UTF8 into a list of renderable characters.
std::stringstream StringStream
A Datatype used for streaming operations with strings.
MarkupParser()
Class constructor.
virtual void PushToken(TextToken *ToBePushed)
Appends a new token to the end of this string.
TagContainer::const_iterator ConstTagIterator
Const Iterator type for MarkupTag instances stored by this class.
TokenContainer::reverse_iterator ReverseTokenIterator
Reverse Iterator type for TextToken instances being stored by this class.
TagContainer Tags
Map of tags recognized by this parser.
This class creates and encapsultes a character that can be used in text renders.
uint32_t UInt32
An 32-bit unsigned integer.
const String & GetName() const
Gets the name of this font.
virtual void GenerateCharactersFromToken(const TextToken *Token, TextLayer *Layer, const CharacterTraits &Traits, CharacterContainer &Characters) const
Helper method for converting text tokens into characters.
virtual TextToken * CreateTextToken(const String &Text) const
Helper method for creating text tokens.
virtual void RegenerateTraits(CharacterTraits &Traits, const TagVector &ActiveTags, TextLayer *Layer) const
Helper method for regenerating current traits after a tag is disabled.
std::pair< Boole, Character * > ProcessResult
An std::pair used to report the result of a MarkupTag being processed any the character it may have g...
virtual TextToken::TokenType GetTokenType() const
Gets the type of token this is.
void SetCharacterColour(const ColourValue &Colour)
Sets the fill colour for this character.
Used to describe either a tag token inserting a character, or the start of a range tag...
Thrown when parameters are checked at runtime and found invalid.
TokenIterator EndToken()
Gets an iterator to one passed the last TextToken.
TokenIterator BeginToken()
Gets an iterator to the first TextToken.
ColourValue CharColour
The colour to render this Character as.
Int32 GetIntFromCharacter(Int32 &BytesUsed, const char *CurrentCharacter)
Get a number suitable for using in an index from a character string.
This struct represents a markup tag segment from the source string.
virtual Char8 GetMarkupTagEnd() const =0
Gets the ID for the character that marks the end of a markup section.
This struct represents a markup tag segment from the source string.
std::pair< TagToken *, MarkupTag * > TokenTagPair
An std::pair type used to map a TagToken to the MarkupTag implementation it is calling.
RangeTagToken * PartnerTag
Pointer to the opening/closing tag for this tag.
The bulk of the engine components go in this namspace.
TokenContainer::iterator TokenIterator
Iterator type for TextToken instances being stored by this class.
ReverseTokenIterator ReverseEndToken()
Gets a reverse iterator to one before the first TextToken.
std::vector< TokenTagPair > TagVector
Basic container type for the storage of TokenTagPair instances used during processing by this class...
Used to describe a normal text token with plain text.
TokenType Type
Type of token this is.
Used to describe a tag token that is syntactically correct, but has another error, such as a range tag missing a partner, or the tag name isn't found.
String Text
Container for the converted text.
std::map< String, String > NameValuePairMap
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
std::string String
A datatype used to a series of characters.
This is a base class for render layers that render text.
Glyph * GetGlyph(const UInt32 &GlyphID) const
Gets the glyph corresponding to the provided characters UTF-8 code.
virtual TextToken * CreateTagToken(const String &Text) const
Helper method for creating tag tokens.