gfx/skia/trunk/include/xml/SkXMLParser.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/xml/SkXMLParser.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,155 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2006 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkXMLParser_DEFINED
    1.14 +#define SkXMLParser_DEFINED
    1.15 +
    1.16 +#include "SkString.h"
    1.17 +
    1.18 +class SkStream;
    1.19 +
    1.20 +class SkDOM;
    1.21 +struct SkDOMNode;
    1.22 +
    1.23 +class SkXMLParserError {
    1.24 +public:
    1.25 +    enum ErrorCode {
    1.26 +        kNoError,
    1.27 +        kEmptyFile,
    1.28 +        kUnknownElement,
    1.29 +        kUnknownAttributeName,
    1.30 +        kErrorInAttributeValue,
    1.31 +        kDuplicateIDs,
    1.32 +        kUnknownError
    1.33 +    };
    1.34 +
    1.35 +    SkXMLParserError();
    1.36 +    virtual ~SkXMLParserError();
    1.37 +    ErrorCode getErrorCode() const { return fCode; }
    1.38 +    virtual void getErrorString(SkString* str) const;
    1.39 +    int getLineNumber() const { return fLineNumber; }
    1.40 +    int getNativeCode() const { return fNativeCode; }
    1.41 +    bool hasError() const { return fCode != kNoError || fNativeCode != -1; }
    1.42 +    bool hasNoun() const { return fNoun.size() > 0; }
    1.43 +    void reset();
    1.44 +    void setCode(ErrorCode code) { fCode = code; }
    1.45 +    void setNoun(const SkString& str) { fNoun.set(str); }
    1.46 +    void setNoun(const char* ch)  { fNoun.set(ch); }
    1.47 +    void setNoun(const char* ch, size_t len) { fNoun.set(ch, len); }
    1.48 +protected:
    1.49 +    ErrorCode fCode;
    1.50 +private:
    1.51 +    int fLineNumber;
    1.52 +    int fNativeCode;
    1.53 +    SkString fNoun;
    1.54 +    friend class SkXMLParser;
    1.55 +};
    1.56 +
    1.57 +class SkXMLParser {
    1.58 +public:
    1.59 +            SkXMLParser(SkXMLParserError* parserError = NULL);
    1.60 +    virtual ~SkXMLParser();
    1.61 +
    1.62 +    /** Returns true for success
    1.63 +    */
    1.64 +    bool parse(const char doc[], size_t len);
    1.65 +    bool parse(SkStream& docStream);
    1.66 +    bool parse(const SkDOM&, const SkDOMNode*);
    1.67 +
    1.68 +    static void GetNativeErrorString(int nativeErrorCode, SkString* str);
    1.69 +
    1.70 +protected:
    1.71 +    // override in subclasses; return true to stop parsing
    1.72 +    virtual bool onStartElement(const char elem[]);
    1.73 +    virtual bool onAddAttribute(const char name[], const char value[]);
    1.74 +    virtual bool onEndElement(const char elem[]);
    1.75 +    virtual bool onText(const char text[], int len);
    1.76 +
    1.77 +public:
    1.78 +    // public for ported implementation, not meant for clients to call
    1.79 +    virtual bool startElement(const char elem[]);
    1.80 +    virtual bool addAttribute(const char name[], const char value[]);
    1.81 +    virtual bool endElement(const char elem[]);
    1.82 +    virtual bool text(const char text[], int len);
    1.83 +    void* fParser;
    1.84 +protected:
    1.85 +    SkXMLParserError* fError;
    1.86 +private:
    1.87 +    void reportError(void* parser);
    1.88 +};
    1.89 +
    1.90 +#if 0
    1.91 +class SkXMLPullParser {
    1.92 +public:
    1.93 +            SkXMLPullParser();
    1.94 +    explicit SkXMLPullParser(SkStream*);
    1.95 +    virtual ~SkXMLPullParser();
    1.96 +
    1.97 +    SkStream*   getStream() const { return fStream; }
    1.98 +    SkStream*   setStream(SkStream* stream);
    1.99 +
   1.100 +    enum EventType {
   1.101 +        ERROR = -1,
   1.102 +        START_DOCUMENT,
   1.103 +        END_DOCUMENT,
   1.104 +        START_TAG,
   1.105 +        END_TAG,
   1.106 +        TEXT,
   1.107 +        CDSECT,
   1.108 +        ENTITY_REF,
   1.109 +        IGNORABLE_WHITESPACE,
   1.110 +        PROCESSING_INSTRUCTION,
   1.111 +        COMMENT,
   1.112 +        DOCDECL
   1.113 +    };
   1.114 +
   1.115 +    EventType   nextToken();
   1.116 +    EventType   getEventType() const { return fCurr.fEventType; }
   1.117 +
   1.118 +    struct AttrInfo {
   1.119 +        const char* fName;
   1.120 +        const char* fValue;
   1.121 +    };
   1.122 +
   1.123 +    int         getDepth() const { return fDepth; }
   1.124 +    const char* getName();
   1.125 +    int         getAttributeCount();
   1.126 +    void        getAttributeInfo(int, AttrInfo*);
   1.127 +    const char* getText();
   1.128 +    bool        isWhitespace();
   1.129 +
   1.130 +protected:
   1.131 +    virtual bool onEntityReplacement(const char name[],
   1.132 +                                     SkString* replacement);
   1.133 +
   1.134 +public:
   1.135 +    struct Curr {
   1.136 +        EventType   fEventType;
   1.137 +        const char* fName;
   1.138 +        AttrInfo*   fAttrInfos;
   1.139 +        int         fAttrInfoCount;
   1.140 +        bool        fIsWhitespace;
   1.141 +    };
   1.142 +
   1.143 +private:
   1.144 +    // implemented in the porting layer
   1.145 +    bool        onInit();   // return false on failure
   1.146 +    EventType   onNextToken();
   1.147 +    void        onExit();
   1.148 +
   1.149 +    SkStream*   fStream;
   1.150 +    Curr        fCurr;
   1.151 +    int         fDepth;
   1.152 +
   1.153 +    struct Impl;
   1.154 +    Impl*   fImpl;
   1.155 +};
   1.156 +#endif
   1.157 +
   1.158 +#endif

mercurial