Commit 0bb44c36 authored by darin's avatar darin

Reviewed by Maciej.

	- first cut at XML parsing with expat

        * khtml/khtml_part.cpp: (KHTMLPart::begin): Remove APPLE_CHANGES and use the XML
	code for text/xml documents.

        * WebCore.pbproj/project.pbxproj: Added the ForwardingHeaders to the project.
	Added new QXml files, removed old ones.

        * kwq/KWQXml.h: Removed.
        * kwq/KWQXml.mm: Removed.

        * kwq/KWQXmlAttributes.h: Added.
        * kwq/KWQXmlAttributes.mm: Added.
        * kwq/KWQXmlDefaultHandler.h: Added.
        * kwq/KWQXmlDefaultHandler.mm: Added.
        * kwq/KWQXmlSimpleReader.h: Added.
        * kwq/KWQXmlSimpleReader.mm: Added.

        * kwq/KWQString.h: Add fromUtf8 functions.
        * kwq/KWQString.mm: (QString::fromUtf8): Added. Simple implementation just
	calls fromStringWithEncoding. We may need something more efficient later,
	at least for all-ASCII text.

	- other changes

        * khtml/khtml_part.h: Fix spelling of occurrence.

        * khtml/misc/decoder.cpp: (Decoder::decode): Turn on Japanese auto-detect.
	It doesn't seem to work yet, but this does no harm.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3321 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2028aa44
2003-01-14 Darin Adler <darin@apple.com>
Reviewed by Maciej.
- first cut at XML parsing with expat
* khtml/khtml_part.cpp: (KHTMLPart::begin): Remove APPLE_CHANGES and use the XML
code for text/xml documents.
* WebCore.pbproj/project.pbxproj: Added the ForwardingHeaders to the project.
Added new QXml files, removed old ones.
* kwq/KWQXml.h: Removed.
* kwq/KWQXml.mm: Removed.
* kwq/KWQXmlAttributes.h: Added.
* kwq/KWQXmlAttributes.mm: Added.
* kwq/KWQXmlDefaultHandler.h: Added.
* kwq/KWQXmlDefaultHandler.mm: Added.
* kwq/KWQXmlSimpleReader.h: Added.
* kwq/KWQXmlSimpleReader.mm: Added.
* kwq/KWQString.h: Add fromUtf8 functions.
* kwq/KWQString.mm: (QString::fromUtf8): Added. Simple implementation just
calls fromStringWithEncoding. We may need something more efficient later,
at least for all-ASCII text.
- other changes
* khtml/khtml_part.h: Fix spelling of occurrence.
* khtml/misc/decoder.cpp: (Decoder::decode): Turn on Japanese auto-detect.
It doesn't seem to work yet, but this does no harm.
2003-01-13 Richard Williamson <rjw@apple.com> 2003-01-13 Richard Williamson <rjw@apple.com>
Fix for 3139120. This patch was contributed by Mitz Pettel. It correctly Fix for 3139120. This patch was contributed by Mitz Pettel. It correctly
......
2003-01-14 Darin Adler <darin@apple.com>
Reviewed by Maciej.
- first cut at XML parsing with expat
* khtml/khtml_part.cpp: (KHTMLPart::begin): Remove APPLE_CHANGES and use the XML
code for text/xml documents.
* WebCore.pbproj/project.pbxproj: Added the ForwardingHeaders to the project.
Added new QXml files, removed old ones.
* kwq/KWQXml.h: Removed.
* kwq/KWQXml.mm: Removed.
* kwq/KWQXmlAttributes.h: Added.
* kwq/KWQXmlAttributes.mm: Added.
* kwq/KWQXmlDefaultHandler.h: Added.
* kwq/KWQXmlDefaultHandler.mm: Added.
* kwq/KWQXmlSimpleReader.h: Added.
* kwq/KWQXmlSimpleReader.mm: Added.
* kwq/KWQString.h: Add fromUtf8 functions.
* kwq/KWQString.mm: (QString::fromUtf8): Added. Simple implementation just
calls fromStringWithEncoding. We may need something more efficient later,
at least for all-ASCII text.
- other changes
* khtml/khtml_part.h: Fix spelling of occurrence.
* khtml/misc/decoder.cpp: (Decoder::decode): Turn on Japanese auto-detect.
It doesn't seem to work yet, but this does no harm.
2003-01-13 Richard Williamson <rjw@apple.com> 2003-01-13 Richard Williamson <rjw@apple.com>
Fix for 3139120. This patch was contributed by Mitz Pettel. It correctly Fix for 3139120. This patch was contributed by Mitz Pettel. It correctly
......
#include "KWQXml.h" #include "KWQXmlAttributes.h"
#include "KWQXmlDefaultHandler.h"
This diff is collapsed.
...@@ -1366,12 +1366,9 @@ void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset ) ...@@ -1366,12 +1366,9 @@ void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset )
#endif #endif
// ### not sure if XHTML documents served as text/xml should use DocumentImpl or HTMLDocumentImpl // ### not sure if XHTML documents served as text/xml should use DocumentImpl or HTMLDocumentImpl
#if !APPLE_CHANGES
// We can't deal with XML yet, so just give it an HTML document for now. -dwh
if (args.serviceType == "text/xml") if (args.serviceType == "text/xml")
d->m_doc = DOMImplementationImpl::instance()->createDocument( d->m_view ); d->m_doc = DOMImplementationImpl::instance()->createDocument( d->m_view );
else else
#endif
d->m_doc = DOMImplementationImpl::instance()->createHTMLDocument( d->m_view ); d->m_doc = DOMImplementationImpl::instance()->createHTMLDocument( d->m_view );
d->m_doc->ref(); d->m_doc->ref();
......
...@@ -518,7 +518,7 @@ public: ...@@ -518,7 +518,7 @@ public:
void findTextBegin(); void findTextBegin();
/** /**
* Finds the next occurence of the string or expression. * Finds the next occurrence of the string or expression.
* If isRegExp is true then str is converted to a QRegExp, and caseSensitive is ignored. * If isRegExp is true then str is converted to a QRegExp, and caseSensitive is ignored.
*/ */
bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp ); bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
......
...@@ -480,8 +480,7 @@ QString Decoder::decode(const char *data, int len) ...@@ -480,8 +480,7 @@ QString Decoder::decode(const char *data, int len)
found: found:
#if APPLE_CHANGES #if APPLE_CHANGES
// FIXME: We'll need our own rule for when to use Japanese auto-detect. if (!haveEncoding)
if (0)
#else #else
if (!haveEncoding && KGlobal::locale()->languageList()[0] == "ja") if (!haveEncoding && KGlobal::locale()->languageList()[0] == "ja")
#endif #endif
......
...@@ -335,6 +335,8 @@ public: ...@@ -335,6 +335,8 @@ public:
static QString fromLatin1(const char *); static QString fromLatin1(const char *);
static QString fromLatin1(const char *, int len); static QString fromLatin1(const char *, int len);
static QString fromUtf8(const char *);
static QString fromUtf8(const char *, int len);
static QString fromStringWithEncoding(const char *, int, CFStringEncoding); static QString fromStringWithEncoding(const char *, int, CFStringEncoding);
static QString fromCFString(CFStringRef); static QString fromCFString(CFStringRef);
static QString fromNSString(NSString *); static QString fromNSString(NSString *);
......
...@@ -651,6 +651,16 @@ void QString::setBufferFromCFString(CFStringRef cfs) ...@@ -651,6 +651,16 @@ void QString::setBufferFromCFString(CFStringRef cfs)
} }
} }
QString QString::fromUtf8(const char *chs)
{
return fromStringWithEncoding(chs, strlen(chs), kCFStringEncodingUTF8);
}
QString QString::fromUtf8(const char *chs, int len)
{
return fromStringWithEncoding(chs, len, kCFStringEncodingUTF8);
}
// This function is used by the decoder. // This function is used by the decoder.
QString QString::fromStringWithEncoding(const char *chs, int len, CFStringEncoding encoding) QString QString::fromStringWithEncoding(const char *chs, int len, CFStringEncoding encoding)
{ {
...@@ -1693,7 +1703,7 @@ QString QString::left(uint len) const ...@@ -1693,7 +1703,7 @@ QString QString::left(uint len) const
if ( isEmpty() ) { if ( isEmpty() ) {
return QString(); return QString();
} else if ( len == 0 ) { // ## just for 1.x compat: } else if ( len == 0 ) { // ## just for 1.x compat:
return QString::fromLatin1(""); return fromLatin1("");
} else if ( len > dataHandle[0]->_length ) { } else if ( len > dataHandle[0]->_length ) {
return *this; return *this;
} else { } else {
...@@ -1707,7 +1717,7 @@ QString QString::right(uint len) const ...@@ -1707,7 +1717,7 @@ QString QString::right(uint len) const
if ( isEmpty() ) { if ( isEmpty() ) {
return QString(); return QString();
} else if ( len == 0 ) { // ## just for 1.x compat: } else if ( len == 0 ) { // ## just for 1.x compat:
return QString::fromLatin1(""); return fromLatin1("");
} else { } else {
uint l = dataHandle[0]->_length; uint l = dataHandle[0]->_length;
if ( len > l ) if ( len > l )
...@@ -1723,7 +1733,7 @@ QString QString::mid(uint index, uint len) const ...@@ -1723,7 +1733,7 @@ QString QString::mid(uint index, uint len) const
if ( isEmpty() || index >= slen ) { if ( isEmpty() || index >= slen ) {
return QString(); return QString();
} else if ( len == 0 ) { // ## just for 1.x compat: } else if ( len == 0 ) { // ## just for 1.x compat:
return QString::fromLatin1(""); return fromLatin1("");
} else { } else {
if (dataHandle[0]->_isAsciiValid){ if (dataHandle[0]->_isAsciiValid){
if ( len > slen-index ) if ( len > slen-index )
......
/*
* Copyright (C) 2001, 2002, 2003 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KWQXMLATTRIBUTES_H
#define KWQXMLATTRIBUTES_H
#include "KWQString.h"
class QXmlAttributes {
public:
QXmlAttributes() : _ref(0), _length(0), _names(0), _values(0) { }
QXmlAttributes(const char **expatStyleAttributes);
~QXmlAttributes();
QXmlAttributes(const QXmlAttributes &);
QXmlAttributes &operator=(const QXmlAttributes &);
int length() const { return _length; }
QString localName(int index) const { return _names[index]; }
QString uri(int index) const;
QString value(int index) const { return _values[index]; }
QString value(const QString &) const;
private:
mutable int *_ref;
int _length;
QString *_names;
QString *_values;
};
#endif
/*
* Copyright (C) 2001, 2002, 2003 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "KWQXmlAttributes.h"
#include "KWQAssertions.h"
QXmlAttributes::QXmlAttributes(const char **expatStyleAttributes)
: _ref(0)
{
int length = 0;
for (const char **p = expatStyleAttributes; *p; p += 2) {
ASSERT(p[1]);
++length;
}
_length = length;
if (!length) {
_names = 0;
_values = 0;
} else {
_names = new QString [length];
_values = new QString [length];
}
int i = 0;
for (const char **p = expatStyleAttributes; *p; p += 2) {
_names[i] = QString::fromUtf8(p[0]);
_values[i] = QString::fromUtf8(p[1]);
++i;
}
}
QXmlAttributes::~QXmlAttributes()
{
if (_ref && !--*_ref) {
delete _ref;
_ref = 0;
}
if (!_ref) {
delete [] _names;
delete [] _values;
}
}
QXmlAttributes::QXmlAttributes(const QXmlAttributes &other)
: _ref(other._ref)
, _length(other._length)
, _names(other._names)
, _values(other._values)
{
if (!_ref) {
_ref = new int (2);
other._ref = _ref;
} else {
++*_ref;
}
}
QXmlAttributes &QXmlAttributes::operator=(const QXmlAttributes &other)
{
if (_ref && !--*_ref) {
delete _ref;
_ref = 0;
}
if (!_ref) {
delete [] _names;
delete [] _values;
}
_ref = other._ref;
_length = other._length;
_names = other._names;
_values = other._values;
if (!_ref) {
_ref = new int (2);
other._ref = _ref;
} else {
++*_ref;
}
return *this;
}
QString QXmlAttributes::uri(int index) const
{
return QString::null;
}
QString QXmlAttributes::value(const QString &name) const
{
for (int i = 0; i != _length; ++i) {
if (name == _names[i]) {
return _values[i];
}
}
return QString::null;
}
/*
* Copyright (C) 2001, 2002, 2003 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KWQXMLDEFAULTHANDLER_H
#define KWQXMLDEFAULTHANDLER_H
#include "KWQXmlSimpleReader.h"
class QXmlDefaultHandler :
public QXmlContentHandler,
public QXmlLexicalHandler,
public QXmlErrorHandler,
public QXmlDeclHandler,
public QXmlDTDHandler
{
virtual bool startDocument();
virtual bool endDocument();
virtual bool startPrefixMapping(const QString &prefix, const QString &URI);
virtual bool endPrefixMapping(const QString &prefix);
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes);
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName);
virtual bool characters(const QString &characters);
virtual bool ignorableWhitespace(const QString &characters);
virtual bool processingInstruction(const QString &target, const QString &data);
virtual bool skippedEntity(const QString &name);
virtual bool startDTD(const QString &name, const QString &publicId, const QString &systemId);
virtual bool endDTD();
virtual bool startEntity(const QString &name);
virtual bool endEntity(const QString &name);
virtual bool startCDATA();
virtual bool endCDATA();
virtual bool comment(const QString &characters);
virtual bool warning(const QXmlParseException &exception);
virtual bool error(const QXmlParseException &exception);
virtual bool fatalError(const QXmlParseException &exception);
virtual bool attributeDecl(const QString &entityName, const QString &attributeName, const QString &type, const QString &valueDefault, const QString &value);
virtual bool externalEntityDecl(const QString &name, const QString &publicId, const QString &systemId);
virtual bool internalEntityDecl(const QString &name, const QString &value);
virtual bool notationDecl(const QString& name, const QString& publicId, const QString& systemId);
virtual bool unparsedEntityDecl(const QString& name, const QString& publicId, const QString& systemId, const QString& notationName);
virtual QString errorString();
};
#endif
...@@ -23,99 +23,7 @@ ...@@ -23,99 +23,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#import "KWQXml.h" #include "KWQXmlDefaultHandler.h"
#include "expat.h"
#import "KWQAssertions.h"
#import "KWQString.h"
QString QXmlAttributes::value(const QString &) const
{
ERROR("not yet implemented");
return QString();
}
int QXmlAttributes::length() const
{
ERROR("not yet implemented");
return 0;
}
QString QXmlAttributes::localName(int index) const
{
ERROR("not yet implemented");
return QString();
}
QString QXmlAttributes::value(int index) const
{
ERROR("not yet implemented");
return QString();
}
QString QXmlAttributes::uri(int) const
{
ERROR("not yet implemented");
return QString();
}
void QXmlInputSource::setData(const QString& data)
{
ERROR("not yet implemented");
}
void QXmlSimpleReader::setContentHandler(QXmlContentHandler *handler)
{
ERROR("not yet implemented");
}
bool QXmlSimpleReader::parse(const QXmlInputSource &input)
{
XML_Parser parser = XML_ParserCreate(""); // FIXME: need encoding
XML_Status parseError = XML_Parse(parser, "", 0, FALSE); // string, length, isFinal
XML_ParserFree(parser);
return parseError != XML_STATUS_ERROR;
}
void QXmlSimpleReader::setLexicalHandler(QXmlLexicalHandler *handler)
{
ERROR("not yet implemented");
}
void QXmlSimpleReader::setDTDHandler(QXmlDTDHandler *handler)
{
ERROR("not yet implemented");
}
void QXmlSimpleReader::setDeclHandler(QXmlDeclHandler *handler)
{
ERROR("not yet implemented");
}
void QXmlSimpleReader::setErrorHandler(QXmlErrorHandler *handler)
{
ERROR("not yet implemented");
}
QString QXmlParseException::message() const
{
ERROR("not yet implemented");
return QString();
}
int QXmlParseException::columnNumber() const
{
ERROR("not yet implemented");
return 0;
}
int QXmlParseException::lineNumber() const
{
ERROR("not yet implemented");
return 0;
}
bool QXmlDefaultHandler::startDocument() bool QXmlDefaultHandler::startDocument()
{ {
...@@ -244,5 +152,5 @@ bool QXmlDefaultHandler::unparsedEntityDecl(const QString& name, const QString& ...@@ -244,5 +152,5 @@ bool QXmlDefaultHandler::unparsedEntityDecl(const QString& name, const QString&
QString QXmlDefaultHandler::errorString() QString QXmlDefaultHandler::errorString()
{ {
return QString(); return QString::null;
} }
/* /*
* Copyright (C) 2001, 2002 Apple Computer, Inc. All rights reserved. * Copyright (C) 2001, 2002, 2003 Apple Computer, Inc. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -23,14 +23,19 @@ ...@@ -23,14 +23,19 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef QXML_H_ #ifndef KWQXMLSIMPLEREADER_H
#define QXML_H_ #define KWQXMLSIMPLEREADER_H
class QString; #include "KWQString.h"
class QXmlAttributes;
class QXmlInputSource { class QXmlInputSource {
public: public:
void setData(const QString &); void setData(const QString &data) { _data = data; }
QString data() const { return _data; }
private:
QString _data;
}; };
class QXmlParseException { class QXmlParseException {
...@@ -40,15 +45,6 @@ public: ...@@ -40,15 +45,6 @@ public:
int lineNumber() const; int lineNumber() const;
}; };
class QXmlAttributes {
public:
QString value(const QString &) const;
int length() const;
QString localName(int index) const;
QString value(int index) const;
QString uri(int index) const;
};
class QXmlContentHandler { class QXmlContentHandler {
public: public:
virtual bool startDocument() = 0; virtual bool startDocument() = 0;
...@@ -98,55 +94,27 @@ public: ...@@ -98,55 +94,27 @@ public:
virtual QString errorString() = 0; virtual QString errorString() = 0;