blob: 63929a94e2f2b4a3b5b2e572728e6d0fddc8939f [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2006 The Android Open Source Project
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
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
10#include "SkXMLParser.h"
11
12static char const* const gErrorStrings[] = {
13 "empty or missing file ",
14 "unknown element ",
15 "unknown attribute name ",
16 "error in attribute value ",
17 "duplicate ID ",
18 "unknown error "
19};
20
21SkXMLParserError::SkXMLParserError() : fCode(kNoError), fLineNumber(-1),
22 fNativeCode(-1)
23{
24 reset();
25}
26
27SkXMLParserError::~SkXMLParserError()
28{
29 // need a virtual destructor for our subclasses
30}
31
32void SkXMLParserError::getErrorString(SkString* str) const
33{
34 SkASSERT(str);
35 SkString temp;
36 if (fCode != kNoError) {
37 if ((unsigned)fCode < SK_ARRAY_COUNT(gErrorStrings))
38 temp.set(gErrorStrings[fCode - 1]);
39 temp.append(fNoun);
40 } else
41 SkXMLParser::GetNativeErrorString(fNativeCode, &temp);
42 str->append(temp);
43}
44
45void SkXMLParserError::reset() {
46 fCode = kNoError;
47 fLineNumber = -1;
48 fNativeCode = -1;
49}
50
51
52////////////////
53
54SkXMLParser::SkXMLParser(SkXMLParserError* parserError) : fParser(NULL), fError(parserError)
55{
56}
57
58SkXMLParser::~SkXMLParser()
59{
60}
61
62bool SkXMLParser::startElement(const char elem[])
63{
64 return this->onStartElement(elem);
65}
66
67bool SkXMLParser::addAttribute(const char name[], const char value[])
68{
69 return this->onAddAttribute(name, value);
70}
71
72bool SkXMLParser::endElement(const char elem[])
73{
74 return this->onEndElement(elem);
75}
76
rmistry@google.comd6176b02012-08-23 18:14:13 +000077bool SkXMLParser::text(const char text[], int len)
reed@android.com8a1c16f2008-12-17 15:59:43 +000078{
79 return this->onText(text, len);
80}
81
82////////////////////////////////////////////////////////////////////////////////
83
84bool SkXMLParser::onStartElement(const char elem[]) {return false; }
85bool SkXMLParser::onAddAttribute(const char name[], const char value[]) {return false; }
86bool SkXMLParser::onEndElement(const char elem[]) { return false; }
87bool SkXMLParser::onText(const char text[], int len) {return false; }