MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cupsUTF8ToCharset

Function cupsUTF8ToCharset

cups/transcode.c:190–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188 */
189
190int /* O - Count or -1 on error */
191cupsUTF8ToCharset(
192 char *dest, /* O - Target string */
193 const cups_utf8_t *src, /* I - Source string */
194 const int maxout, /* I - Max output */
195 const cups_encoding_t encoding) /* I - Encoding */
196{
197 char *destptr; /* Pointer into destination */
198#ifdef HAVE_ICONV_H
199 size_t srclen, /* Length of source string */
200 outBytesLeft; /* Bytes remaining in output buffer */
201#endif /* HAVE_ICONV_H */
202
203
204 /*
205 * Check for valid arguments...
206 */
207
208 if (!dest || !src || maxout < 1)
209 {
210 if (dest)
211 *dest = '\0';
212
213 return (-1);
214 }
215
216 /*
217 * Handle identity conversions...
218 */
219
220 if (encoding == CUPS_UTF8 ||
221 encoding >= CUPS_ENCODING_VBCS_END)
222 {
223 strlcpy(dest, (char *)src, (size_t)maxout);
224 return ((int)strlen(dest));
225 }
226
227 /*
228 * Handle UTF-8 to ISO-8859-1 directly...
229 */
230
231 destptr = dest;
232
233 if (encoding == CUPS_ISO8859_1 || encoding <= CUPS_US_ASCII)
234 {
235 int ch, /* Character from string */
236 maxch; /* Maximum character for charset */
237 char *destend; /* End of ISO-8859-1 buffer */
238
239 maxch = encoding == CUPS_ISO8859_1 ? 256 : 128;
240 destend = dest + maxout - 1;
241
242 while (*src && destptr < destend)
243 {
244 ch = *src++;
245
246 if ((ch & 0xe0) == 0xc0 && (*src & 0xc0) == 0x80)
247 {

Callers 6

show_promptFunction · 0.85
_cupsLangPrintErrorFunction · 0.85
_cupsLangPrintFilterFunction · 0.85
_cupsLangPrintfFunction · 0.85
_cupsLangPutsFunction · 0.85
mainFunction · 0.85

Calls 4

_cupsMutexLockFunction · 0.85
_cupsCharmapFlushFunction · 0.85
_cupsEncodingNameFunction · 0.85
_cupsMutexUnlockFunction · 0.85

Tested by 1

mainFunction · 0.68