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.

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

mercurial