You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2005/07/27 13:06:55 UTC
cvs commit: ws-axis/c/src/guththila FileInputStream.cpp Makefile.am Makefile.in XmlPullParser.cpp unicode.cpp
samisa 2005/07/27 04:06:55
Added: c/src/guththila FileInputStream.cpp Makefile.am Makefile.in
XmlPullParser.cpp unicode.cpp
Log:
Added the pull paser implementation by Dinesh
AXISCPP-245
Revision Changes Path
1.1 ws-axis/c/src/guththila/FileInputStream.cpp
Index: FileInputStream.cpp
===================================================================
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Dasarath Weerathunga (dasarath@opensource.lk)
*
*/
#include <FileInputStream.hpp>
FileInputStream::FileInputStream (FILE * s)
{
this->s = s;
if (!s)
throw new XmlPullParserException ();
}
FileInputStream::~FileInputStream ()
{
fclose (s);
}
int
FileInputStream::read (char *buffer, int offset, int length)
{
return fread (buffer + offset, 1, length, s);
}
1.1 ws-axis/c/src/guththila/Makefile.am
Index: Makefile.am
===================================================================
AUTOMAKE_OPTIONS = gnu
if TRUE
#bin_PROGRAMS = tspp
#tspp_SOURCES = main.cpp XmlPullParser.cpp FileInputStream.cpp unicode.cpp
if UNICODE_OUT
INCLUDES = -I../include -DUNICODE_OUT -ggdb3
else
INCLUDES = -I../include -ggdb3
endif
lib_LTLIBRARIES = libguththila.la
libguththila_la_SOURCES = XmlPullParser.cpp FileInputStream.cpp unicode.cpp
endif
1.1 ws-axis/c/src/guththila/Makefile.in
Index: Makefile.in
===================================================================
# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
host_alias = @host_alias@
host_triplet = @host@
AR = @AR@
AS = @AS@
CC = @CC@
CXX = @CXX@
CXXCPP = @CXXCPP@
DLLTOOL = @DLLTOOL@
ECHO = @ECHO@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
GCJ = @GCJ@
GCJFLAGS = @GCJFLAGS@
HAVE_LIB = @HAVE_LIB@
LIB = @LIB@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIB = @LTLIB@
MAKEINFO = @MAKEINFO@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
RC = @RC@
STRIP = @STRIP@
VERSION = @VERSION@
AUTOMAKE_OPTIONS = gnu
@TRUE_TRUE@bin_PROGRAMS = tspp
@TRUE_TRUE@tspp_SOURCES = main.cpp XmlPullParser.cpp FileInputStream.cpp unicode.cpp
@TRUE_TRUE@@UNICODE_OUT_TRUE@INCLUDES = -I../include -DUNICODE_OUT -ggdb3
@TRUE_TRUE@@UNICODE_OUT_FALSE@INCLUDES = -I../include -ggdb3
@TRUE_TRUE@lib_LTLIBRARIES = libguththila.la
@TRUE_TRUE@libguththila_la_SOURCES = XmlPullParser.cpp FileInputStream.cpp unicode.cpp
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(lib_LTLIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libguththila_la_LDFLAGS =
libguththila_la_LIBADD =
@TRUE_TRUE@libguththila_la_OBJECTS = XmlPullParser.lo \
@TRUE_TRUE@FileInputStream.lo unicode.lo
@TRUE_TRUE@bin_PROGRAMS = tspp$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)
@TRUE_TRUE@tspp_OBJECTS = main.$(OBJEXT) XmlPullParser.$(OBJEXT) \
@TRUE_TRUE@FileInputStream.$(OBJEXT) unicode.$(OBJEXT)
tspp_LDADD = $(LDADD)
tspp_DEPENDENCIES =
tspp_LDFLAGS =
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP_ENV = --best
SOURCES = $(libguththila_la_SOURCES) $(tspp_SOURCES)
OBJECTS = $(libguththila_la_OBJECTS) $(tspp_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .cpp .lo .o .obj .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.ac $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps src/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-libLTLIBRARIES:
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
distclean-libLTLIBRARIES:
maintainer-clean-libLTLIBRARIES:
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(libdir)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
echo "$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \
$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \
else :; fi; \
done
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
list='$(lib_LTLIBRARIES)'; for p in $$list; do \
$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \
done
.c.o:
$(COMPILE) -c $<
# FIXME: We should only use cygpath when building on Windows,
# and only if it is available.
.c.obj:
$(COMPILE) -c `cygpath -w $<`
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
-rm -f *.$(OBJEXT)
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
.c.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
.s.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
.S.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
maintainer-clean-libtool:
libguththila.la: $(libguththila_la_OBJECTS) $(libguththila_la_DEPENDENCIES)
$(CXXLINK) -rpath $(libdir) $(libguththila_la_LDFLAGS) $(libguththila_la_OBJECTS) $(libguththila_la_LIBADD) $(LIBS)
mostlyclean-binPROGRAMS:
clean-binPROGRAMS:
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
distclean-binPROGRAMS:
maintainer-clean-binPROGRAMS:
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(bindir)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
if test -f $$p; then \
echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
list='$(bin_PROGRAMS)'; for p in $$list; do \
rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
done
tspp$(EXEEXT): $(tspp_OBJECTS) $(tspp_DEPENDENCIES)
@rm -f tspp$(EXEEXT)
$(CXXLINK) $(tspp_LDFLAGS) $(tspp_OBJECTS) $(tspp_LDADD) $(LIBS)
.cpp.o:
$(CXXCOMPILE) -c $<
.cpp.obj:
$(CXXCOMPILE) -c `cygpath -w $<`
.cpp.lo:
$(LTCXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags -o $$here/TAGS $(ETAGS_ARGS) $$tags $$unique $(LISP))
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = src
distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
FileInputStream.lo FileInputStream.o : FileInputStream.cpp \
../include/FileInputStream.hpp ../include/InputStream.hpp \
../include/XmlPullParserException.hpp
main.o: main.cpp ../include/XmlPullParser.hpp \
../include/XmlPullParserException.hpp \
../include/FileInputStream.hpp ../include/InputStream.hpp \
../include/Array.hpp ../include/Buffer.hpp \
../include/unicode.hpp ../include/Token.hpp \
../include/Namespace.hpp ../include/Attribute.hpp \
../include/Depth.hpp
unicode.lo unicode.o : unicode.cpp ../include/unicode.hpp
XmlPullParser.lo XmlPullParser.o : XmlPullParser.cpp \
../include/XmlPullParser.hpp \
../include/XmlPullParserException.hpp \
../include/FileInputStream.hpp ../include/InputStream.hpp \
../include/Array.hpp ../include/Buffer.hpp \
../include/unicode.hpp ../include/Token.hpp \
../include/Namespace.hpp ../include/Attribute.hpp \
../include/Depth.hpp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am: install-libLTLIBRARIES install-binPROGRAMS
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am: uninstall-libLTLIBRARIES uninstall-binPROGRAMS
uninstall: uninstall-am
all-am: Makefile $(LTLIBRARIES) $(PROGRAMS)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
$(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(bindir)
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-libLTLIBRARIES mostlyclean-compile \
mostlyclean-libtool mostlyclean-binPROGRAMS \
mostlyclean-tags mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-libLTLIBRARIES clean-compile clean-libtool \
clean-binPROGRAMS clean-tags clean-generic \
mostlyclean-am
clean: clean-am
distclean-am: distclean-libLTLIBRARIES distclean-compile \
distclean-libtool distclean-binPROGRAMS distclean-tags \
distclean-generic clean-am
-rm -f libtool
distclean: distclean-am
maintainer-clean-am: maintainer-clean-libLTLIBRARIES \
maintainer-clean-compile maintainer-clean-libtool \
maintainer-clean-binPROGRAMS maintainer-clean-tags \
maintainer-clean-generic distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \
clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \
uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \
distclean-compile clean-compile maintainer-clean-compile \
mostlyclean-libtool distclean-libtool clean-libtool \
maintainer-clean-libtool mostlyclean-binPROGRAMS distclean-binPROGRAMS \
clean-binPROGRAMS maintainer-clean-binPROGRAMS uninstall-binPROGRAMS \
install-binPROGRAMS tags mostlyclean-tags distclean-tags clean-tags \
maintainer-clean-tags distdir info-am info dvi-am dvi check check-am \
installcheck-am installcheck install-exec-am install-exec \
install-data-am install-data install-am install uninstall-am uninstall \
all-redirect all-am all installdirs mostlyclean-generic \
distclean-generic clean-generic maintainer-clean-generic clean \
mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
1.1 ws-axis/c/src/guththila/XmlPullParser.cpp
Index: XmlPullParser.cpp
===================================================================
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Dasarath Weerathunga (dasarath@opensource.lk)
* @author Dinesh Premalal (xydinesh@gmail.com
premalal@opensource.lk)
*
*@author Susantha Kumara ( susantha@opensource.lk )
*/
#include <XmlPullParser.hpp>
void
XmlPullParser::relocateTokens (int offset)
{
int size = token->count ();
for (int i = 0; i < size; i++)
token->get (i)->relocate (offset);
}
void
XmlPullParser::shift ()
{
memmove (buffer->get (), buffer->get () + offset, _next - offset);
_next -= offset;
last -= offset;
offset = 0;
}
int
XmlPullParser::read ()
{
if (_next == buffer->getSize ())
{
if (offset > 0)
{
relocateTokens (offset);
shift ();
}
else
{
char *p = buffer->get ();
buffer->grow ();
relocateTokens (p - buffer->get ());
}
}
int c = s->read (buffer->get (), _next, buffer->getSize () - _next);
last += c;
return !c;
}
/*! check with BOM
*This may or may not be presant with utf8 documents
*But UTF-16 document must have BOM 0xff 0xfe in any order,
* for LE = 0xff 0xfe,
* for BE = 0xfe 0xff,
* for UTF-8 = 0xef 0xbb 0xbf ( not necessary) */
int
XmlPullParser::isUtf8 ()
{
UTF8_char utf[3] = { 0, 0, 0 };
for (int i = 0; i < 3; i++)
utf[i] = (UTF8_char) buffer->get ()[_next++];
if (0xef == utf[0] && 0xbb == utf[1] && 0xbf == utf[2])
{
unicodeState = None;
return _next;
}
else
return _next = 0;
}
/*! check for BOM */
int
XmlPullParser::isUtf16 ()
{
if (_next == 0)
{
UTF8_char utf[2];
int i;
for (i = 0; i < 2; i++)
utf[i] = (UTF8_char) buffer->get ()[_next++];
if (0xff == utf[0] && 0xfe == utf[1])
return LE;
else if (0xfe == utf[0] && 0xff == utf[1])
return BE;
else
{
_next = 0;
return None;
}
}
else
return None;
}
/*!since we are interested in special charactes such as "<",
* "/",">","?","!",""",... nextCh() method suppose to return those
* values. Those values are retrieved form UTF-16 characters
* ,Here we need not to do a convertion. Because those values are
* < 128 */
int
XmlPullParser::fromUtf16 (int eof)
{
int c = buffer->get ()[_next++];
if (_next > last && read ())
if (eof)
{
term = 1;
return -1;
}
else
throw new XmlPullParserException ();
/*UTF16_char d = *((UTF16_char *) & buffer->get ()[_next]);
if (!d)
{
term = 1;
return -1;
}*/
while (!c)
c = buffer->get ()[_next++];
return c;
}
int
XmlPullParser::nextCh (int eof)
{
if (_next > last && read ())
if (eof)
{
term = 1;
return -1;
}
else
throw new XmlPullParserException ();
if (_next == 0)
{
if (isUtf8 ());
else
(unicodeState = isUtf16 ());
}
if (unicodeState == None)
return buffer->get ()[_next++];
else
return fromUtf16 (eof);
}
char *
XmlPullParser::lastCh ()
{
int i = 1;
char c = buffer->get ()[_next - 1];
/*! If term has set to true then that is a buffer termination */
if (term)
return buffer->get () + _next - 1;
else
{
while (!c)
c = buffer->get ()[_next - (++i)];
return buffer->get () + _next - i;
}
}
void
XmlPullParser::reset (int del)
{
offset = _next;
name = NULL;
prefix = NULL;
namesp = NULL;
term = 0;
token->trunc (0);
attr->trunc (0);
if (!del)
{
if (ETag == event || EmptyElemTag == event)
closeElement ();
}
}
void
XmlPullParser::openToken ()
{
token_t *t = token->append ();
t->type = token_t::Unknown;
t->start = lastCh ();
}
void
XmlPullParser::closeToken (int type)
{
token_t *t = token->last ();
t->type = type;
t->end = lastCh () - 1;
}
XmlPullParser::XmlPullParser (InputStream * s)
{
this->s = s;
state = S_1;
offset = 0;
last = -1;
_next = 0;
buffer = new Buffer < char >(1024);
token = new Array < token_t > (64);
namespa = new Array < namespace_t > (64);
depth = new Array < depth_t > (16);
attr = new Array < attr_t > (64);
}
XmlPullParser::~XmlPullParser ()
{
reset (-1);
delete buffer;
delete token;
delete namespa;
delete depth;
delete attr;
}
int
XmlPullParser::isS (int c)
{
return 0x9 == c || 0xA == c || 0xD == c || 0x20 == c;
}
int
XmlPullParser::parseS (int c)
{
while (isS (c))
c = nextCh ();
return c;
}
int
XmlPullParser::parseEq (int c)
{
if ('=' == parseS (c))
return parseS (nextCh ());
else
throw new XmlPullParserException ();
}
int
XmlPullParser::parseNameToken (int c)
{
openToken ();
while (!(isS (c) || '/' == c || '?' == c || '=' == c || '>' == c))
{
if (':' == c)
{
closeToken (token_t::Prefix);
c = nextCh ();
openToken ();
}
else
c = nextCh ();
}
closeToken (token_t::Name);
return c;
}
int
XmlPullParser::parseAttValueToken (int quote)
{
if ('\'' == quote || '"' == quote)
{
int c = nextCh ();
openToken ();
while ('&' != c && '<' != c)
{
if (c == quote)
{
closeToken (token_t::AttValue);
return nextCh ();
}
c = nextCh ();
}
}
throw new XmlPullParserException ();
}
int
XmlPullParser::parseAttribute (int c)
{
c = parseEq (parseNameToken (c));
c = parseAttValueToken (c);
return parseS (c);
}
void
XmlPullParser::parseXMLDecl ()
{
if (nextCh () == 'x' && nextCh () == 'm' && nextCh () == 'l')
{
int c = parseAttribute (parseS (nextCh ()));
if (c == 'e')
c = parseAttribute (c);
if (c == 's')
c = parseAttribute (c);
if (c == '?' && nextCh () == '>')
{
event = XMLDecl;
return;
}
}
throw new XmlPullParserException ();
}
void
XmlPullParser::parseSTagOrEmptyElemTag (int c)
{
c = parseS (parseNameToken (c));
event = STag;
for (;;)
{
if (c == '/')
{
event = EmptyElemTag;
if (nextCh () == '>')
return;
else
throw new XmlPullParserException ();
}
else if (c == '>')
return;
else
c = parseAttribute (c);
}
}
void
XmlPullParser::parseETag ()
{
if (parseS (parseNameToken (nextCh ())) == '>')
event = ETag;
else
throw new XmlPullParserException ();
}
int
XmlPullParser::parseCharData ()
{
int c;
event = Content;
openToken ();
do
{
c = nextCh (-1);
if (-1 == c)
{
closeToken (token_t::CharData);
return 0;
}
}
while ('<' != c);
closeToken (token_t::CharData);
return c;
}
int
XmlPullParser::tokenize ()
{
do
{
int c = nextCh (-1);
if (-1 == c)
return -1;
switch (state)
{
case S_1:
if ('<' == c)
state = S_2;
else
state = S_0;
break;
case S_2:
if ('?' == c)
parseXMLDecl ();
else
parseSTagOrEmptyElemTag (c);
state = S_3;
break;
case S_3:
if ('<' == c)
state = S_4;
else
{
c = parseCharData ();
if ('<' == c)
{
state = S_4;
return event;
}
else if ('\0' == c)
state = S_3;
else
state = S_0;
}
break;
case S_4:
if ('/' == c)
{
parseETag ();
state = S_3;
}
else if ('!' == c)
state = S_0;
else if ('?' == c)
state = S_0;
else
{
parseSTagOrEmptyElemTag (c);
state = S_3;
}
}
if (state == S_0)
throw new XmlPullParserException ();
}
while (state != S_3);
return event;
}
int
XmlPullParser::addNamespace (token_t * uri)
{
namespace_t *r = namespa->append ();
r->prefix = NULL;
r->length = 0;
r->uri = uri->toString (unicodeState);
r->lengthUri = strlen(r->uri);
}
int
XmlPullParser::addNamespace (token_t * prefix, token_t * uri)
{
namespace_t *r = namespa->append ();
r->prefix = prefix->toString (unicodeState);
r->length = strlen (r->prefix);
r->uri = uri->toString (unicodeState);
r->lengthUri = strlen(r->uri);
}
int
XmlPullParser::addAttribute (token_t * prefix, token_t * name,
token_t * value)
{
attr_t *r = attr->append ();
r->prefix = prefix;
r->name = name;
r->value = value;
r->namesp = NULL;
}
void
XmlPullParser::openElement ()
{
if (depth->count ())
{
depth_t *l = depth->last ();
depth_t *m = depth->append ();
m->first = l->first + l->count;
m->total = namespa->count ();
m->count = m->total - l->total;
}
else
{
depth_t *m = depth->append ();
m->first = 0;
m->total = namespa->count ();
m->count = m->total;
}
}
void
XmlPullParser::closeElement ()
{
depth_t *d = depth->last ();
if (d->count)
{
namespace_t *p = namespa->get (d->first);
for (int i = 0; i < d->count; i++, p++)
{
if (p->prefix)
free (p->prefix);
if(p->uri)
free(p->uri);
}
namespa->trunc (d->first);
}
depth->chip ();
}
int
XmlPullParser::next ()
{
token_t *p;
reset ();
switch (tokenize ())
{
case -1:
return -1;
case XMLDecl:
case STag:
case EmptyElemTag:
p = token->last ();
while (p->isOfType (token_t::AttValue))
{
token_t *value = p--;
token_t *name = p--;
if (p->isOfType (token_t::Prefix))
{
if (!p->compare ("xmlns", 5))
addNamespace (name, value);
else
addAttribute (p, name, value);
p--;
}
else if (!name->compare ("xmlns", 5))
addNamespace (value);
else
addAttribute (NULL, name, value);
}
openElement ();
case ETag:
p = token->get ();
if (p->isOfType (token_t::Prefix))
prefix = p++;
name = p;
case Content:
defualt:
return event;
}
}
namespace_t *
XmlPullParser::getNamespace (token_t * prefix)
{
namespace_t *p = namespa->last (), *q = namespa->get ();
while (1)
{
if (prefix == NULL)
{
if (p->prefix == NULL)
return p;
}
else
{
if (p->prefix && !prefix->compare (p->prefix, p->length))
return p;
}
if (p == q)
throw new XmlPullParserException ();
p--;
}
}
char *
XmlPullParser::getName ()
{
if (name)
return name->toString (unicodeState);
throw new XmlPullParserException ();
}
char *
XmlPullParser::getPrefix ()
{
if (prefix)
return prefix->toString (unicodeState);
return NULL;
}
char*
XmlPullParser::getNamespaceUri ()
{
if (!namesp)
namesp = getNamespace (prefix);
return strndup (namesp->uri, namesp->lengthUri);
}
char*
XmlPullParser::getValue ()
{
return token->get ()->toString (unicodeState);
}
int
XmlPullParser::getDepth ()
{
return depth->count ();
}
int
XmlPullParser::getAttributeCount ()
{
return attr->count ();
}
char*
XmlPullParser::getAttributeName (int i)
{
return attr->get (i)->name->toString (unicodeState);
}
char*
XmlPullParser::getAttributeValue (int i)
{
return attr->get (i)->value->toString (unicodeState);
}
char*
XmlPullParser::getAttributePrefix (int i)
{
attr_t *p = attr->get (i);
if (p->prefix)
return p->prefix->toString (unicodeState);
return NULL;
}
char*
XmlPullParser::getAttributeNamespaceUri (int i)
{
attr_t *p = attr->get (i);
if (!p->namesp)
p->namesp = getNamespace (p->prefix);
return strndup(p->namesp->uri, p->namesp->lengthUri);
}
int
XmlPullParser::getNamespaceCount (int i)
{
return depth->get (i - 1)->total;
}
char *
XmlPullParser::getNamespacePrefix (int i)
{
namespace_t *p = namespa->get (i);
if (p->prefix)
return strndup(p->prefix, p->length);
return NULL;
}
char *
XmlPullParser::getNamespaceUri (int i)
{
return strndup(namespa->get(i)->uri, namespa->get(i)->lengthUri);
}
char *
XmlPullParser::getNamespaceForPrefix (char *prefix)
{
namespace_t *p = namespa->last (), *q = namespa->get ();
while (1)
{
if (prefix == NULL)
{
if (p->prefix == NULL)
return strndup (p->uri, p->lengthUri);
}
else
{
if (p->prefix && !strncmp (p->prefix, prefix, p->length))
return strndup (p->uri, p->lengthUri);
}
if (p == q)
throw new XmlPullParserException ();
p--;
}
}
char *
XmlPullParser::getPrefixForNamespace (char *ns)
{
namespace_t *p = namespa->last (), *q = namespa->get ();
while (1)
{
if (ns == NULL)
throw new XmlPullParserException ();
/* No Namespace exsist with NULL URI*/
else
{
if (p->uri && !strncmp (p->uri, ns, p->lengthUri))
return strndup (p->prefix, p->length);
}
if (p == q)
throw new XmlPullParserException ();
p--;
}
}
1.1 ws-axis/c/src/guththila/unicode.cpp
Index: unicode.cpp
===================================================================
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Dinesh Premalal (xydinesh@gmail.com)
*
*/
#include <unicode.hpp>
#include <stdlib.h>
#include <string.h>
#ifdef UNICODE_OUT /* This variable for Obtain UTF-16 Output */
/*! In order to determine length of UTF-16 Buffer
* Basicall char *p should be a Utf-16 Buffer */
UTF8_char
strlenUnicode (char *p)
{
UTF8_char len = 0;
UTF8_char d;
UTF16_char c ;
char* s = p;
c = *((UTF16_char *)&s[len]);
if (c)
{
while (c)
{
c = *((UTF16_char *)&s[len]);
len +=2;
d = s[len];
if(!d)
{
return len;
break;
}
}
return (len-2);
}
else
return 0;
}
/*! To Duplicate UTF-16 string */
char *
strdupUnicode (char* p)
{
char *s;
UTF8_char length;
length = strlenUnicode (p);
unicodeLength = length + 1;
s = (char *)calloc (length, 1);
return (char *)memcpy (s, p, length);
}
/*!To Duplicate UTF-16 String */
char *
strdupUnicode (char* p, int length)
{
char *s;
unicodeLength = length + 1;
s = (char *)calloc (length+1, 1);
s[length] = 0;
return (char *)memcpy (s, p, length);
}
#endif /*end of UNICODE_OUT definition */