inline Bytes encode(const Unicode& object) const { int state; size_t offset = 0; size_t enclen = 0; bytechar* encptr = NULL; size_t declen = object.length(); const unicode* decptr = static_cast<const unicode*>(object); state = u8_encode(decptr, declen, encptr, enclen, offset); if (state != UNICODE_STATE_SUCCESS) throw EncodeError(state, offset, "UTF-8"); return Bytes(encptr, enclen); }
inline Bytes encode(const Unicode& object) const { unicode code = 0; size_t offset = 0; bytechar* encptr = NULL; size_t len = object.length(); const unicode* decptr = object; encptr = new bytechar[len]; for (size_t i = 0; i < len; ++i) { code = this->uctobyte(decptr[i]); if (code == 0x110000) { delete[] decptr; throw EncodeError(UNICODE_STATE_ILLEGAL, offset, *this); } encptr[i] = static_cast<bytechar>(code); ++offset; } return Bytes(encptr, len); }