gfx/skia/trunk/src/xml/SkXMLPullParser.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8 #include "SkXMLParser.h"
michael@0 9 #include "SkStream.h"
michael@0 10
michael@0 11 static void reset(SkXMLPullParser::Curr* curr)
michael@0 12 {
michael@0 13 curr->fEventType = SkXMLPullParser::ERROR;
michael@0 14 curr->fName = "";
michael@0 15 curr->fAttrInfoCount = 0;
michael@0 16 curr->fIsWhitespace = false;
michael@0 17 }
michael@0 18
michael@0 19 SkXMLPullParser::SkXMLPullParser() : fStream(NULL)
michael@0 20 {
michael@0 21 fCurr.fEventType = ERROR;
michael@0 22 fDepth = -1;
michael@0 23 }
michael@0 24
michael@0 25 SkXMLPullParser::SkXMLPullParser(SkStream* stream) : fStream(NULL)
michael@0 26 {
michael@0 27 fCurr.fEventType = ERROR;
michael@0 28 fDepth = 0;
michael@0 29
michael@0 30 this->setStream(stream);
michael@0 31 }
michael@0 32
michael@0 33 SkXMLPullParser::~SkXMLPullParser()
michael@0 34 {
michael@0 35 this->setStream(NULL);
michael@0 36 }
michael@0 37
michael@0 38 SkStream* SkXMLPullParser::setStream(SkStream* stream)
michael@0 39 {
michael@0 40 if (fStream && !stream)
michael@0 41 this->onExit();
michael@0 42
michael@0 43 SkRefCnt_SafeAssign(fStream, stream);
michael@0 44
michael@0 45 if (fStream)
michael@0 46 {
michael@0 47 fCurr.fEventType = START_DOCUMENT;
michael@0 48 this->onInit();
michael@0 49 }
michael@0 50 else
michael@0 51 {
michael@0 52 fCurr.fEventType = ERROR;
michael@0 53 }
michael@0 54 fDepth = 0;
michael@0 55
michael@0 56 return fStream;
michael@0 57 }
michael@0 58
michael@0 59 SkXMLPullParser::EventType SkXMLPullParser::nextToken()
michael@0 60 {
michael@0 61 switch (fCurr.fEventType) {
michael@0 62 case ERROR:
michael@0 63 case END_DOCUMENT:
michael@0 64 break;
michael@0 65 case END_TAG:
michael@0 66 fDepth -= 1;
michael@0 67 // fall through
michael@0 68 default:
michael@0 69 reset(&fCurr);
michael@0 70 fCurr.fEventType = this->onNextToken();
michael@0 71 break;
michael@0 72 }
michael@0 73
michael@0 74 switch (fCurr.fEventType) {
michael@0 75 case START_TAG:
michael@0 76 fDepth += 1;
michael@0 77 break;
michael@0 78 default:
michael@0 79 break;
michael@0 80 }
michael@0 81
michael@0 82 return fCurr.fEventType;
michael@0 83 }
michael@0 84
michael@0 85 const char* SkXMLPullParser::getName()
michael@0 86 {
michael@0 87 switch (fCurr.fEventType) {
michael@0 88 case START_TAG:
michael@0 89 case END_TAG:
michael@0 90 return fCurr.fName;
michael@0 91 default:
michael@0 92 return NULL;
michael@0 93 }
michael@0 94 }
michael@0 95
michael@0 96 const char* SkXMLPullParser::getText()
michael@0 97 {
michael@0 98 switch (fCurr.fEventType) {
michael@0 99 case TEXT:
michael@0 100 case IGNORABLE_WHITESPACE:
michael@0 101 return fCurr.fName;
michael@0 102 default:
michael@0 103 return NULL;
michael@0 104 }
michael@0 105 }
michael@0 106
michael@0 107 bool SkXMLPullParser::isWhitespace()
michael@0 108 {
michael@0 109 switch (fCurr.fEventType) {
michael@0 110 case IGNORABLE_WHITESPACE:
michael@0 111 return true;
michael@0 112 case TEXT:
michael@0 113 case CDSECT:
michael@0 114 return fCurr.fIsWhitespace;
michael@0 115 default:
michael@0 116 return false; // unknown/illegal
michael@0 117 }
michael@0 118 }
michael@0 119
michael@0 120 int SkXMLPullParser::getAttributeCount()
michael@0 121 {
michael@0 122 return fCurr.fAttrInfoCount;
michael@0 123 }
michael@0 124
michael@0 125 void SkXMLPullParser::getAttributeInfo(int index, AttrInfo* info)
michael@0 126 {
michael@0 127 SkASSERT((unsigned)index < (unsigned)fCurr.fAttrInfoCount);
michael@0 128
michael@0 129 if (info)
michael@0 130 *info = fCurr.fAttrInfos[index];
michael@0 131 }
michael@0 132
michael@0 133 bool SkXMLPullParser::onEntityReplacement(const char name[],
michael@0 134 SkString* replacement)
michael@0 135 {
michael@0 136 // TODO: std 5 entities here
michael@0 137 return false;
michael@0 138 }

mercurial