Mercurial > trustbridge
diff common/strhelp.h @ 251:c596568fa45b
Add utf16 conversion functions for Windows.
This also includes a null pointer checking free.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 01 Apr 2014 10:48:35 +0000 |
parents | 6b4ad6ccc48e |
children | 4077eff1dd39 |
line wrap: on
line diff
--- a/common/strhelp.h Mon Mar 31 11:41:43 2014 +0200 +++ b/common/strhelp.h Tue Apr 01 10:48:35 2014 +0000 @@ -6,6 +6,7 @@ #endif #include <stdbool.h> +#include <stddef.h> /** * @file strhelp.h @@ -19,6 +20,7 @@ void *xrealloc( void *a, size_t n ); void *xcalloc( size_t n, size_t m ); char *xstrndup( const char *string, const size_t len ); +void xfree ( void *p ); /** * @brief Returns the length of the given %NULL-terminated @@ -101,6 +103,30 @@ */ int str_base64_decode(char **dst, size_t *dst_size, char *src, size_t src_size); + +#ifdef WIN32 + +/** @brief convert a utf8 string to utf16 wchar + * + * @param[in] string utf8 string. Must be at least len characters long. + * @param[in] len number of characters to be converted. + * + * @returns pointer to a newly allocated wchar array. NULL on error. + * + **/ +wchar_t *utf8_to_wchar (const char *string, size_t len); + +/** @brief convert a utf16 string to utf8 + * + * @param[in] string utf16 string. Must be at least len characters long. + * @param[in] len number of characters to be converted. + * + * @returns pointer to a newly allocated char array. NULL on error. + * + **/ +char *wchar_to_utf8 (const wchar_t *string, size_t len); +#endif + #ifdef __cplusplus } #endif