httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adelle Hartley <>
Subject Re: Converting a 16-bit string to 8-bit?
Date Fri, 04 Mar 2011 01:24:31 GMT
On 4/03/2011 03:12, Sam Carleton wrote:
> I am looking at using a 3rd party library that only operates on 16-bit
> strings.  Is there a built in functions to convert the strings back to
> 8-bit?  I am currenly on Windows and Windows has built in functions I could
> use, I would prefer to use Apache functions if they exist.

This is a helper class I wrote for the module I'm working on.  It 
assumes the native wide encoding is UTF-32.  To make it cross platform, 
you'd have to check what the correct wide encoding is.

This is my first apache module, so any corrections welcome.

class our_response_t
	request_rec* m;
	apr_xlate_t* m_convset;
	our_response_t(request_rec* request) : m(request), m_convset(NULL), 
m_html(NULL), m_json(NULL)
		apr_pool_t* pool = m->pool;
		apr_status_t status = apr_xlate_open(&m_convset, "UTF-8", "UTF-32", pool);

		if (m_convset)
			ap_set_content_type(m, "text/html;charset=UTF-8");

		if (m_convset)

	void append_chars(const wchar_t* str, size_t num_chars)
		apr_size_t inbytes_left = num_chars*sizeof(wchar_t);
		apr_size_t outbytes_left = CHARSET_CONVERSION_BUFFER_SIZE-1;
		apr_status_t status = apr_xlate_conv_buffer(m_convset, (const 
char*)str, &inbytes_left, m_bufferBytes, &outbytes_left);
		m_bufferBytes[CHARSET_CONVERSION_BUFFER_SIZE-outbytes_left-1] = 0;
		ap_rputs(m_bufferBytes, m);


View raw message