void
XalanOutputStream::setOutputEncoding(const XalanDOMString&  theEncoding)
{
    // Flush, just in case.  This should probably be an error...
    flushBuffer();

    XalanTranscodingServices::destroyTranscoder(m_transcoder);

    XalanTranscodingServices::eCode     theCode = XalanTranscodingServices::OK;

    // This turns on an optimization that we can only do if
    // XalanDOMChar == sizeof(ushort).  See doWrite().
#if !defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH)
    if (XalanTranscodingServices::encodingIsUTF16(theEncoding) == true)
    {
        m_writeAsUTF16 = true;
    }
    else
#endif
    {
        m_transcoder = XalanTranscodingServices::makeNewTranscoder(
                    getMemoryManager(),
                    theEncoding,
                    theCode,
                    m_transcoderBlockSize);

        if (theCode == XalanTranscodingServices::UnsupportedEncoding)
        {
            XalanDOMString theBuffer(getMemoryManager());

            throw UnsupportedEncodingException(theEncoding, theBuffer);
        }
        else if (theCode != XalanTranscodingServices::OK)
        {
            XalanDOMString theBuffer(getMemoryManager());

            throw TranscoderInternalFailureException(theEncoding, theBuffer);
        }

        assert(m_transcoder != 0);
    }

    m_encoding = theEncoding;

    const XalanTranscodingServices::XalanXMLByte*   theProlog =
        XalanTranscodingServices::getStreamProlog(theEncoding);
    assert(theProlog != 0);

    const size_type     theLength = XalanTranscodingServices::length(theProlog);

    if (theLength > 0)
    {
#if defined(XALAN_OLD_STYLE_CASTS)
        write((const char*)theProlog, theLength);
#else
        write(reinterpret_cast<const char*>(theProlog), theLength);
#endif
    }
}
예제 #2
0
int Encodings::toBytes(int encoding, wchar wc, byte *dest){
  if (encoding < -6 || encoding == -1 || encoding >= encNamesNum)
    throw UnsupportedEncodingException(SString(encoding));
  if (encoding >= 0){
    dest[0] = TO_CHAR(encoding, wc);
    return 1;
  };
  if (encoding == ENC_UTF8){
    int dpos = 0;
    if (wc <= 0x7F){
      dest[dpos] = wc & 0x7F;
    };
    if (wc > 0x7F && wc <= 0x7FF){
      dest[dpos] = 0xC0 + (wc>>6);
      dpos++;
      dest[dpos] = 0x80 + (wc&0x3F);
    };
예제 #3
0
int Encodings::getEncodingBOMSize(int encoding){
  if (encoding >= -1 || encoding < -6) throw UnsupportedEncodingException(DString("getEncodingBOM was called for bad encoding"));
  return bomArraySize[-encoding-2];
}