1/* Conversions between Unicode and legacy encodings. 2 Copyright (C) 2002, 2005, 2007, 2009, 2010 Free Software Foundation, Inc. 3 4 This program is free software: you can redistribute it and/or modify it 5 under the terms of the GNU Lesser General Public License as published 6 by the Free Software Foundation; either version 3 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17#ifndef _UNICONV_H 18#define _UNICONV_H 19 20/* Get size_t. */ 21#include <stddef.h> 22 23#include "unitypes.h" 24 25/* Get enum iconv_ilseq_handler. */ 26#include <unistring/iconveh.h> 27 28/* Get locale_charset() declaration. */ 29#include <unistring/localcharset.h> 30 31 32#ifdef __cplusplus 33extern "C" { 34#endif 35 36 37/* Converts an entire string, possibly including NUL bytes, from one encoding 38 to a Unicode encoding. 39 Converts a memory region given in encoding FROMCODE. FROMCODE is as for 40 iconv_open(3). 41 The input is in the memory region between SRC (inclusive) and SRC + SRCLEN 42 (exclusive). 43 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this 44 array is filled with offsets into the result, i.e. the character starting 45 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]], 46 and other offsets are set to (size_t)(-1). 47 RESULTBUF and *LENGTHP should initially be a scratch buffer and its size, 48 or *RESULTBUF can be NULL. 49 May erase the contents of the memory at RESULTBUF. 50 If successful: The resulting Unicode string (non-NULL) is returned and its 51 length stored in *LENGTHP. The resulting string is RESULTBUF if no dynamic 52 memory allocation was necessary, or a freshly allocated memory block 53 otherwise. 54 In case of error: NULL is returned and errno is set. Particular errno 55 values: EINVAL, EILSEQ, ENOMEM. */ 56extern uint8_t * 57 u8_conv_from_encoding (const char *fromcode, 58 enum iconv_ilseq_handler handler, 59 const char *src, size_t srclen, 60 size_t *offsets, 61 uint8_t *resultbuf, size_t *lengthp); 62extern uint16_t * 63 u16_conv_from_encoding (const char *fromcode, 64 enum iconv_ilseq_handler handler, 65 const char *src, size_t srclen, 66 size_t *offsets, 67 uint16_t *resultbuf, size_t *lengthp); 68extern uint32_t * 69 u32_conv_from_encoding (const char *fromcode, 70 enum iconv_ilseq_handler handler, 71 const char *src, size_t srclen, 72 size_t *offsets, 73 uint32_t *resultbuf, size_t *lengthp); 74 75/* Converts an entire Unicode string, possibly including NUL units, from a 76 Unicode encoding to a given encoding. 77 Converts a memory region to encoding TOCODE. TOCODE is as for 78 iconv_open(3). 79 The input is in the memory region between SRC (inclusive) and SRC + SRCLEN 80 (exclusive). 81 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this 82 array is filled with offsets into the result, i.e. the character starting 83 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]], 84 and other offsets are set to (size_t)(-1). 85 RESULTBUF and *LENGTHP should initially be a scratch buffer and its size, 86 or RESULTBUF can be NULL. 87 May erase the contents of the memory at RESULTBUF. 88 If successful: The resulting string (non-NULL) is returned and its length 89 stored in *LENGTHP. The resulting string is RESULTBUF if no dynamic memory 90 allocation was necessary, or a freshly allocated memory block otherwise. 91 In case of error: NULL is returned and errno is set. Particular errno 92 values: EINVAL, EILSEQ, ENOMEM. */ 93extern char * 94 u8_conv_to_encoding (const char *tocode, 95 enum iconv_ilseq_handler handler, 96 const uint8_t *src, size_t srclen, 97 size_t *offsets, 98 char *resultbuf, size_t *lengthp); 99extern char * 100 u16_conv_to_encoding (const char *tocode, 101 enum iconv_ilseq_handler handler, 102 const uint16_t *src, size_t srclen, 103 size_t *offsets, 104 char *resultbuf, size_t *lengthp); 105extern char * 106 u32_conv_to_encoding (const char *tocode, 107 enum iconv_ilseq_handler handler, 108 const uint32_t *src, size_t srclen, 109 size_t *offsets, 110 char *resultbuf, size_t *lengthp); 111 112/* Converts a NUL terminated string from a given encoding. 113 The result is malloc allocated, or NULL (with errno set) in case of error. 114 Particular errno values: EILSEQ, ENOMEM. */ 115extern uint8_t * 116 u8_strconv_from_encoding (const char *string, 117 const char *fromcode, 118 enum iconv_ilseq_handler handler); 119extern uint16_t * 120 u16_strconv_from_encoding (const char *string, 121 const char *fromcode, 122 enum iconv_ilseq_handler handler); 123extern uint32_t * 124 u32_strconv_from_encoding (const char *string, 125 const char *fromcode, 126 enum iconv_ilseq_handler handler); 127 128/* Converts a NUL terminated string to a given encoding. 129 The result is malloc allocated, or NULL (with errno set) in case of error. 130 Particular errno values: EILSEQ, ENOMEM. */ 131extern char * 132 u8_strconv_to_encoding (const uint8_t *string, 133 const char *tocode, 134 enum iconv_ilseq_handler handler); 135extern char * 136 u16_strconv_to_encoding (const uint16_t *string, 137 const char *tocode, 138 enum iconv_ilseq_handler handler); 139extern char * 140 u32_strconv_to_encoding (const uint32_t *string, 141 const char *tocode, 142 enum iconv_ilseq_handler handler); 143 144/* Converts a NUL terminated string from the locale encoding. 145 The result is malloc allocated, or NULL (with errno set) in case of error. 146 Particular errno values: ENOMEM. */ 147extern uint8_t * 148 u8_strconv_from_locale (const char *string); 149extern uint16_t * 150 u16_strconv_from_locale (const char *string); 151extern uint32_t * 152 u32_strconv_from_locale (const char *string); 153 154/* Converts a NUL terminated string to the locale encoding. 155 The result is malloc allocated, or NULL (with errno set) in case of error. 156 Particular errno values: ENOMEM. */ 157extern char * 158 u8_strconv_to_locale (const uint8_t *string); 159extern char * 160 u16_strconv_to_locale (const uint16_t *string); 161extern char * 162 u32_strconv_to_locale (const uint32_t *string); 163 164 165#ifdef __cplusplus 166} 167#endif 168 169#endif /* _UNICONV_H */ 170