10910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project#include "SkXMLParser.h"
20910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project#include "SkStream.h"
30910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
40910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectstatic void reset(SkXMLPullParser::Curr* curr)
50910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
60910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    curr->fEventType = SkXMLPullParser::ERROR;
70910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    curr->fName = "";
80910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    curr->fAttrInfoCount = 0;
90910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    curr->fIsWhitespace = false;
100910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
110910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
120910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source ProjectSkXMLPullParser::SkXMLPullParser() : fStream(NULL)
130910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
140910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    fCurr.fEventType = ERROR;
150910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    fDepth = -1;
160910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
170910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
180910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source ProjectSkXMLPullParser::SkXMLPullParser(SkStream* stream) : fStream(NULL)
190910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
200910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    fCurr.fEventType = ERROR;
210910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    fDepth = 0;
220910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
230910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    this->setStream(stream);
240910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
250910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
260910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source ProjectSkXMLPullParser::~SkXMLPullParser()
270910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
280910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    this->setStream(NULL);
290910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
300910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
310910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source ProjectSkStream* SkXMLPullParser::setStream(SkStream* stream)
320910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
330910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    if (fStream && !stream)
340910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        this->onExit();
350910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
360910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    SkRefCnt_SafeAssign(fStream, stream);
370910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
380910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    if (fStream)
390910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    {
400910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        fCurr.fEventType = START_DOCUMENT;
410910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        this->onInit();
420910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    }
430910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    else
440910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    {
450910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        fCurr.fEventType = ERROR;
460910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    }
470910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    fDepth = 0;
480910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
490910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    return fStream;
500910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
510910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
520910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source ProjectSkXMLPullParser::EventType SkXMLPullParser::nextToken()
530910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
540910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    switch (fCurr.fEventType) {
550910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case ERROR:
560910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case END_DOCUMENT:
570910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        break;
580910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case END_TAG:
590910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        fDepth -= 1;
600910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        // fall through
610910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    default:
620910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        reset(&fCurr);
630910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        fCurr.fEventType = this->onNextToken();
640910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        break;
650910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    }
660910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
670910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    switch (fCurr.fEventType) {
680910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case START_TAG:
690910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        fDepth += 1;
700910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        break;
710910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    default:
720910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        break;
730910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    }
740910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
750910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    return fCurr.fEventType;
760910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
770910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
780910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectconst char* SkXMLPullParser::getName()
790910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
800910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    switch (fCurr.fEventType) {
810910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case START_TAG:
820910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case END_TAG:
830910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        return fCurr.fName;
840910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    default:
850910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        return NULL;
860910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    }
870910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
880910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
890910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectconst char* SkXMLPullParser::getText()
900910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
910910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    switch (fCurr.fEventType) {
920910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case TEXT:
930910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case IGNORABLE_WHITESPACE:
940910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        return fCurr.fName;
950910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    default:
960910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        return NULL;
970910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    }
980910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
990910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
1000910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectbool SkXMLPullParser::isWhitespace()
1010910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
1020910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    switch (fCurr.fEventType) {
1030910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case IGNORABLE_WHITESPACE:
1040910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        return true;
1050910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case TEXT:
1060910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    case CDSECT:
1070910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        return fCurr.fIsWhitespace;
1080910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    default:
1090910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        return false;   // unknown/illegal
1100910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    }
1110910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
1120910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
1130910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectint SkXMLPullParser::getAttributeCount()
1140910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
1150910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    return fCurr.fAttrInfoCount;
1160910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
1170910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
1180910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectvoid SkXMLPullParser::getAttributeInfo(int index, AttrInfo* info)
1190910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
1200910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    SkASSERT((unsigned)index < (unsigned)fCurr.fAttrInfoCount);
1210910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
1220910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    if (info)
1230910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project        *info = fCurr.fAttrInfos[index];
1240910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
1250910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
1260910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectbool SkXMLPullParser::onEntityReplacement(const char name[],
1270910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project                                          SkString* replacement)
1280910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project{
1290910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    // TODO: std 5 entities here
1300910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project    return false;
1310910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}
1320910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project
133