Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
SkDOMParser Class Reference
Inheritance diagram for SkDOMParser:
SkXMLParser

Public Member Functions

 SkDOMParser (SkArenaAllocWithReset *chunk)
 
SkDOM::NodegetRoot () const
 
- Public Member Functions inherited from SkXMLParser
 SkXMLParser (SkXMLParserError *parserError=nullptr)
 
virtual ~SkXMLParser ()
 
bool parse (const char doc[], size_t len)
 
bool parse (SkStream &docStream)
 
bool parse (const SkDOM &, const SkDOMNode *)
 
bool startElement (const char elem[])
 
bool addAttribute (const char name[], const char value[])
 
bool endElement (const char elem[])
 
bool text (const char text[], int len)
 

Public Attributes

SkXMLParserError fParserError
 
- Public Attributes inherited from SkXMLParser
void * fParser
 

Protected Member Functions

void flushAttributes ()
 
bool onStartElement (const char elem[]) override
 
bool onAddAttribute (const char name[], const char value[]) override
 
bool onEndElement (const char elem[]) override
 
bool onText (const char text[], int len) override
 
virtual bool onStartElement (const char elem[])
 
virtual bool onAddAttribute (const char name[], const char value[])
 
virtual bool onEndElement (const char elem[])
 
virtual bool onText (const char text[], int len)
 

Additional Inherited Members

- Static Public Member Functions inherited from SkXMLParser
static void GetNativeErrorString (int nativeErrorCode, SkString *str)
 
- Protected Attributes inherited from SkXMLParser
SkXMLParserErrorfError
 

Detailed Description

Definition at line 190 of file SkDOM.cpp.

Constructor & Destructor Documentation

◆ SkDOMParser()

SkDOMParser::SkDOMParser ( SkArenaAllocWithReset chunk)
inline

Definition at line 192 of file SkDOM.cpp.

192 : SkXMLParser(&fParserError), fAlloc(chunk) {
193 fAlloc->reset();
194 fRoot = nullptr;
195 fLevel = 0;
196 fNeedToFlush = true;
197 }
SkXMLParserError fParserError
Definition: SkDOM.cpp:199
SkXMLParser(SkXMLParserError *parserError=nullptr)

Member Function Documentation

◆ flushAttributes()

void SkDOMParser::flushAttributes ( )
inlineprotected

Definition at line 202 of file SkDOM.cpp.

202 {
203 SkASSERT(fLevel > 0);
204
205 int attrCount = fAttrs.size();
206
207 SkDOMAttr* attrs = fAlloc->makeArrayDefault<SkDOMAttr>(attrCount);
208 SkDOM::Node* node = fAlloc->make<SkDOM::Node>();
209
210 node->fName = fElemName;
211 node->fFirstChild = nullptr;
212 node->fAttrCount = SkToU16(attrCount);
213 node->fAttrs = attrs;
214 node->fType = fElemType;
215
216 if (fRoot == nullptr) {
217 node->fNextSibling = nullptr;
218 fRoot = node;
219 } else { // this adds siblings in reverse order. gets corrected in onEndElement()
220 SkDOM::Node* parent = fParentStack.back();
221 SkASSERT(fRoot && parent);
222 node->fNextSibling = parent->fFirstChild;
223 parent->fFirstChild = node;
224 }
225 *fParentStack.append() = node;
226
227 sk_careful_memcpy(node->attrs(), fAttrs.begin(), attrCount * sizeof(SkDOM::Attr));
228 fAttrs.reset();
229 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
Definition: SkMalloc.h:125
constexpr uint16_t SkToU16(S x)
Definition: SkTo.h:24
T * makeArrayDefault(size_t count)
Definition: SkArenaAlloc.h:171
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
SkDOMNode * fFirstChild
Definition: SkDOM.cpp:52
const char * fName
Definition: SkDOM.cpp:51

◆ getRoot()

SkDOM::Node * SkDOMParser::getRoot ( ) const
inline

Definition at line 198 of file SkDOM.cpp.

198{ return fRoot; }

◆ onAddAttribute()

bool SkDOMParser::onAddAttribute ( const char  name[],
const char  value[] 
)
inlineoverrideprotectedvirtual

Reimplemented from SkXMLParser.

Definition at line 236 of file SkDOM.cpp.

236 {
237 SkDOM::Attr* attr = fAttrs.append();
238 attr->fName = dupstr(fAlloc, name, strlen(name));
239 attr->fValue = dupstr(fAlloc, value, strlen(value));
240 return false;
241 }
static char * dupstr(SkArenaAlloc *chunk, const char src[], size_t srcLen)
Definition: SkDOM.cpp:182
uint8_t value
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
const char * fValue
Definition: SkDOM.cpp:47
const char * fName
Definition: SkDOM.cpp:46

◆ onEndElement()

bool SkDOMParser::onEndElement ( const char  elem[])
inlineoverrideprotectedvirtual

Reimplemented from SkXMLParser.

Definition at line 243 of file SkDOM.cpp.

243 {
244 if (fNeedToFlush)
245 this->flushAttributes();
246 fNeedToFlush = false;
247 --fLevel;
248
249 SkDOM::Node* parent = fParentStack.back();
250 fParentStack.pop_back();
251
252 SkDOM::Node* child = parent->fFirstChild;
253 SkDOM::Node* prev = nullptr;
254 while (child) {
255 SkDOM::Node* next = child->fNextSibling;
256 child->fNextSibling = prev;
257 prev = child;
258 child = next;
259 }
260 parent->fFirstChild = prev;
261 return false;
262 }
static float next(float f)
static float prev(float f)
void flushAttributes()
Definition: SkDOM.cpp:202
SkDOMNode * fNextSibling
Definition: SkDOM.cpp:53

◆ onStartElement()

bool SkDOMParser::onStartElement ( const char  elem[])
inlineoverrideprotectedvirtual

Reimplemented from SkXMLParser.

Definition at line 231 of file SkDOM.cpp.

231 {
232 this->startCommon(elem, strlen(elem), SkDOM::kElement_Type);
233 return false;
234 }
@ kElement_Type
Definition: SkDOM.h:43

◆ onText()

bool SkDOMParser::onText ( const char  text[],
int  len 
)
inlineoverrideprotectedvirtual

Reimplemented from SkXMLParser.

Definition at line 264 of file SkDOM.cpp.

264 {
265 this->startCommon(text, len, SkDOM::kText_Type);
266 this->SkDOMParser::onEndElement(fElemName);
267
268 return false;
269 }
bool onEndElement(const char elem[]) override
Definition: SkDOM.cpp:243
@ kText_Type
Definition: SkDOM.h:44
bool text(const char text[], int len)

Member Data Documentation

◆ fParserError

SkXMLParserError SkDOMParser::fParserError

Definition at line 199 of file SkDOM.cpp.


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