OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Markup Class Reference

#include <C4Markup.h>

Public Member Functions

 C4Markup (bool fDoClr)
 
 ~C4Markup ()
 
bool Read (const char **ppText, bool fSkip=false)
 
bool SkipTags (const char **ppText)
 
void Apply (C4BltTransform &rBltTrf, DWORD &dwClr)
 
bool Clean ()
 

Static Public Member Functions

static bool StripMarkup (char *szText)
 
static bool StripMarkup (StdStrBuf *sText)
 

Detailed Description

Definition at line 57 of file C4Markup.h.

Constructor & Destructor Documentation

C4Markup::C4Markup ( bool  fDoClr)
inline

Definition at line 68 of file C4Markup.h.

68 { pTags=pLast=nullptr; this->fDoClr=fDoClr; }; // ctor
C4Markup::~C4Markup ( )
inline

Definition at line 69 of file C4Markup.h.

References C4MarkupTag::pNext.

70  { C4MarkupTag *pTag=pTags,*pNext; while (pTag) { pNext=pTag->pNext; delete pTag; pTag=pNext; } }
C4MarkupTag * pNext
Definition: C4Markup.h:25

Member Function Documentation

void C4Markup::Apply ( C4BltTransform rBltTrf,
DWORD dwClr 
)
inline

Definition at line 74 of file C4Markup.h.

References C4MarkupTag::Apply(), and C4MarkupTag::pNext.

Referenced by CStdFont::DrawText().

75  { for (C4MarkupTag *pTag=pTags; pTag; pTag=pTag->pNext) pTag->Apply(rBltTrf, fDoClr, dwClr); }
C4MarkupTag * pNext
Definition: C4Markup.h:25

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Markup::Clean ( )
inline

Definition at line 76 of file C4Markup.h.

Referenced by CStdFont::DrawText().

76 { return !pTags; } // empty?

Here is the caller graph for this function:

bool C4Markup::Read ( const char **  ppText,
bool  fSkip = false 
)

Definition at line 34 of file C4Markup.cpp.

References b, SCharPos(), SCopyEnclosed(), SEqual(), SLen(), and C4MarkupTag::TagName().

Referenced by CStdFont::DrawText(), and SkipTags().

35 {
36  char Tag[50]; C4MarkupTag *pNewTag=nullptr; int iTagLen,iParLen;
37  // get tag
38  if (!SCopyEnclosed(*ppText, '<', '>', Tag, 49)) return false;
39  iTagLen=SLen(Tag);
40  // split tag to name and pars
41  char *szPars=nullptr; int iSPos;
42  if ((iSPos=SCharPos(' ', Tag))>-1)
43  {
44  Tag[iSPos]=0;
45  szPars=Tag+iSPos+1;
46  }
47  // closing tag?
48  if (Tag[0]=='/')
49  {
50  // no parameters
51  if (szPars) return false;
52  if (!fSkip)
53  {
54  // is this the tag to be closed?
55  if (!pLast) return false;
56  if (!SEqual(pLast->TagName(), Tag+1)) return false;
57  // close it
58  delete Pop();
59  }
60  }
61  // italic
62  else if (SEqual(Tag, "i"))
63  {
64  // no parameters
65  if (szPars) return false;
66  // create italic tag
67  if (!fSkip) pNewTag=new C4MarkupTagItalic();
68  }
69  // colored
70  else if (SEqual(Tag, "c"))
71  {
72  // no parameters?
73  if (!szPars) return false;
74  if ((iParLen=SLen(szPars))>8) return false;
75  if (!fSkip)
76  {
77  // get color value by parameter
78  DWORD dwClr=0;
79  for (int i=0; i<iParLen; ++i)
80  {
81  BYTE b;
82  if (szPars[i]>='0' && szPars[i]<='9') b=szPars[i]-'0';
83  else if (szPars[i]>='a' && szPars[i]<='f') b=szPars[i]-'a'+10;
84  else return false;
85  dwClr|=(b<<((iParLen-i-1)*4));
86  }
87  // adjust alpha if not given
88  if (iParLen<=6) dwClr|=0xff000000;
89  // create color tag
90  pNewTag=new C4MarkupTagColor(dwClr);
91  }
92  }
93  // unknown tag
94  else return false;
95  // add created tag
96  if (pNewTag) Push(pNewTag);
97  // advance past tag
98  *ppText+=iTagLen+2;
99  // success
100  return true;
101 }
#define b
bool SCopyEnclosed(const char *szSource, char cOpen, char cClose, char *sTarget, int iSize)
Definition: Standard.cpp:523
uint8_t BYTE
virtual const char * TagName()=0
size_t SLen(const char *sptr)
Definition: Standard.h:74
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:233
uint32_t DWORD

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Markup::SkipTags ( const char **  ppText)

Definition at line 105 of file C4Markup.cpp.

References Read().

Referenced by CStdFont::BreakMessage(), C4MenuItem::DoTextProgress(), CStdFont::GetTextExtent(), LogSilent(), and StripMarkup().

106 {
107  // read tags as long as found
108  while (**ppText=='<') if (!Read(ppText, true)) break;
109  // return whether end is reached
110  return !**ppText;
111 }
bool Read(const char **ppText, bool fSkip=false)
Definition: C4Markup.cpp:34

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Markup::StripMarkup ( char *  szText)
static

Definition at line 113 of file C4Markup.cpp.

References SkipTags(), and SSearch().

Referenced by C4PlayerInfoCore::Load(), StripMarkup(), and C4InVal::ValidateString().

114 {
115  // skip any tags and inline-images
116  C4Markup mkup(false);
117  const char *szRead = szText, *szPos2;
118  do
119  {
120  mkup.SkipTags(&szRead);
121  if (szRead[0] == '{' && szRead[1] == '{' && szRead[2] != '{') // skip at {{{, because {{{id}} should be parsed as { {{id}} }.
122  {
123  if ((szPos2 = SSearch(szRead+2, "}}")))
124  // valid {{blub}}-tag
125  szRead = szPos2;
126  else
127  // invalid {{-tag
128  szRead += 2;
129  }
130  else if (szRead[0] == '}' && szRead[1] == '}')
131  // invalid }}-tag
132  szRead += 2;
133  }
134  while ((*szText++ = *szRead++));
135  return szText != szRead;
136 }
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:363

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Markup::StripMarkup ( StdStrBuf sText)
static

Definition at line 138 of file C4Markup.cpp.

References StdStrBuf::GrabPointer(), StripMarkup(), and StdStrBuf::Take().

139 {
140  // strip any markup codes from given text buffer
141  char *buf = sText->GrabPointer();
142  if (!buf) return false;
143  bool fSuccess = StripMarkup(buf);
144  sText->Take(buf);
145  return fSuccess;
146 }
char * GrabPointer()
Definition: StdBuf.h:459
void Take(char *pnData)
Definition: StdBuf.h:457
static bool StripMarkup(char *szText)
Definition: C4Markup.cpp:113

Here is the call graph for this function:


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