XMLCodingSystem.cxx revision 7c478bd95313f5f23a4c958a745db2134aa03244
// Copyright (c) 1994, 1997 James Clark
// See the file COPYING for copying permission.
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __GNUG__
#pragma implementation
#endif
#include "splib.h"
#ifdef SP_MULTI_BYTE
#include "XMLCodingSystem.h"
#include "UTF8CodingSystem.h"
#include "CodingSystemKit.h"
#include "Boolean.h"
#include "Owner.h"
#include "macros.h"
#include <stddef.h>
#include <string.h>
#ifdef SP_DECLARE_MEMMOVE
extern "C" {
}
#endif
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
class XMLDecoder : public Decoder {
public:
XMLDecoder(const InputCodingSystemKit *);
const char **rest);
private:
public:
const char **rest);
private:
};
// Don't keep parsing a PI longer than this.
// We want to avoid reading some enormous file into memory just because
// some quote was left off.
void initDecoderDefault();
void initDecoderPI();
enum DetectPhase {
};
int guessBytesPerChar_;
// Contains all the characters passed to caller that were
// not produced by subDecoder_.
const InputCodingSystemKit *kit_;
};
{
}
{
return new XMLDecoder(kit_);
}
{
return utf8.makeEncoder();
}
: Decoder(1),
byteOrderMark_(0),
lsbFirst_(0),
piLiteral_(0)
{
}
const char **rest)
{
if (phase_ == phaseFinish)
if (fromLen == 0) {
return 0;
}
switch ((unsigned char)*from) {
case 0x00:
case 0x3C:
case 0xFF:
case 0xFE:
if (fromLen < 2) {
return 0;
}
case 0xFEFF:
byteOrderMark_ = 1;
guessBytesPerChar_ = 2;
from += 2;
fromLen -= 2;
break;
case 0xFFFE:
lsbFirst_ = 1;
byteOrderMark_ = 1;
guessBytesPerChar_ = 2;
from += 2;
fromLen -= 2;
break;
case 0x3C3F:
break;
case 0x3C00:
lsbFirst_ = 1;
guessBytesPerChar_ = 2;
break;
case 0x003C:
guessBytesPerChar_ = 2;
break;
default:
break;
}
break;
// fall through
default:
guessBytesPerChar_ = 1;
}
}
for (; fromLen > guessBytesPerChar_;
}
if (guessBytesPerChar_ > 1) {
if (lsbFirst_)
else {
c <<= 8;
c |= (unsigned char)from[1];
}
}
static const Char startBytes[] = {
};
// Stop accumulating the PI if we get characters that are illegal in the PI.
if (c == 0
|| c >= 0x7F
break;
}
*p++ = c;
pi_ += c;
if (piLiteral_) {
if (c == piLiteral_)
piLiteral_ = 0;
}
else if (c == ISO646_QUOT || c == ISO646_APOS)
piLiteral_ = c;
}
return n;
}
{
n *= guessBytesPerChar_;
else {
if (!subDecoder_)
return 0;
return 0;
}
if (byteOrderMark_)
n += 2;
return 1;
}
void XMLDecoder::initDecoderDefault()
{
if (guessBytesPerChar_ == 1) {
}
else {
unsigned short n = 0x1;
minBytesPerChar_ = 2;
}
}
void XMLDecoder::initDecoderPI()
{
if (!extractEncoding(name))
const char *dummy;
const InputCodingSystem *ics
0,
dummy);
if (ics) {
}
if (!subDecoder_)
}
{
switch (c) {
case ISO646_CR:
case ISO646_LF:
case ISO646_SPACE:
case ISO646_TAB:
return 1;
}
return 0;
}
{
if (!lit) {
else if (pi_[i] == ISO646_EQUAL) {
size_t j = i;
for (; j > 0; j--) {
break;
}
for (; j > 0; j--) {
break;
}
static const Char encodingName[] = {
0
};
const Char *s = encodingName;
for (; *s && j < nameEnd; j++, s++)
if (pi_[j] != *s)
break;
if (j == nameEnd && *s == 0) {
size_t j = i + 1;
break;
}
if (j > nameStart) {
return 1;
}
break;
}
}
}
return 0;
}
}
}
lit = 0;
}
return 0;
}
{
}
const char **rest)
{
union U {
unsigned short word;
char bytes[2];
};
fromLen &= ~1;
if (sizeof(Char) == 2) {
if (!swapBytes_) {
return fromLen/2;
}
}
if (swapBytes_) {
U u;
}
}
else {
U u;
}
}
return fromLen/2;
}
{
n *= 2;
return 1;
}
#ifdef SP_NAMESPACE
}
#endif
#else /* not SP_MULTI_BYTE */
#ifndef __GNUG__
static char non_empty_translation_unit; // sigh
#endif
#endif /* not SP_MULTI_BYTE */