UnicodeCodingSystem.cxx revision 7c478bd95313f5f23a4c958a745db2134aa03244
// Copyright (c) 1994 James Clark
// See the file COPYING for copying permission.
#pragma ident "%Z%%M% %I% %E% SMI"
#include "splib.h"
#ifdef SP_MULTI_BYTE
#include "UnicodeCodingSystem.h"
#include "macros.h"
#include "Owner.h"
#include <stddef.h>
#include <string.h>
#ifdef DECLARE_MEMMOVE
extern "C" {
}
#endif
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
const unsigned short byteOrderMark = 0xfeff;
const unsigned short swappedByteOrderMark = 0xfffe;
class UnicodeDecoder : public Decoder {
public:
const char **rest);
private:
const InputCodingSystem *subCodingSystem_;
};
class UnicodeEncoder : public Encoder {
public:
~UnicodeEncoder();
void startFile(OutputByteStream *);
private:
unsigned short *buf_;
};
{
}
{
return new UnicodeDecoder(sub_);
}
{
return new UnicodeEncoder;
}
unsigned UnicodeCodingSystem::fixedBytesPerChar() const
{
return 2;
}
{
}
const char **rest)
{
union U {
unsigned short word;
char bytes[2];
};
if (subDecoder_)
if (!hadFirstChar_) {
if (fromLen < 2) {
return 0;
}
hadFirstChar_ = 1;
minBytesPerChar_ = 2;
U u;
if (u.word == byteOrderMark) {
hadByteOrderMark_ = 1;
from += 2;
fromLen -= 2;
}
else if (u.word == swappedByteOrderMark) {
hadByteOrderMark_ = 1;
from += 2;
fromLen -= 2;
swapBytes_ = 1;
}
else if (subCodingSystem_) {
}
}
fromLen &= ~1;
if (sizeof(Char) == 2) {
if (!swapBytes_) {
return fromLen/2;
}
}
if (swapBytes_) {
U u;
}
}
else {
U u;
}
}
return fromLen/2;
}
{
if (subDecoder_)
return subDecoder_->convertOffset(n);
if (hadByteOrderMark_)
n += 1;
n *= 2;
return true;
}
{
}
{
delete [] buf_;
}
{
if (bufSize_ < n) {
delete [] buf_;
}
}
{
const unsigned short n = byteOrderMark;
}
{
if (sizeof(Char) == 2) {
return;
}
unsigned short *p = (unsigned short *)s;
for (size_t i = 0; i < n; i++)
p[i] = s[i] & 0xffff;
}
{
if (sizeof(Char) == 2) {
return;
}
allocBuf(n);
for (size_t i = 0; i < n; i++)
buf_[i] = s[i] & 0xffff;
}
#ifdef SP_NAMESPACE
}
#endif
#else /* not SP_MULTI_BYTE */
#ifndef __GNUG__
static char non_empty_translation_unit; // sigh
#endif
#endif /* not SP_MULTI_BYTE */