diff options
Diffstat (limited to 'src/libexif/exif-utils.c')
-rw-r--r-- | src/libexif/exif-utils.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/libexif/exif-utils.c b/src/libexif/exif-utils.c index 9386012..a6e7696 100644 --- a/src/libexif/exif-utils.c +++ b/src/libexif/exif-utils.c @@ -1,6 +1,6 @@ /* exif-utils.c * - * Copyright © 2001 Lutz Müller <lutz@users.sourceforge.net> + * Copyright (c) 2001 Lutz Mueller <lutz@users.sourceforge.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -212,3 +212,40 @@ exif_set_srational (unsigned char *buf, ExifByteOrder order, exif_set_slong (buf, order, value.numerator); exif_set_slong (buf + 4, order, value.denominator); } + +void +exif_convert_utf16_to_utf8 (char *out, const unsigned short *in, int maxlen) +{ + /* This function converts rather UCS2 than UTF16 to UTF8 */ + if (maxlen <= 0) { + return; + } + while (*in) { + if (*in < 0x80) { + if (maxlen > 1) { + *out++ = (char)*in++; + maxlen--; + } else { + break; + } + } else if (*in < 0x800) { + if (maxlen > 2) { + *out++ = ((*in >> 6) & 0x1F) | 0xC0; + *out++ = (*in++ & 0x3F) | 0x80; + maxlen -= 2; + } else { + break; + } + } else { + if (maxlen > 2) { + *out++ = ((*in >> 12) & 0x0F) | 0xE0; + *out++ = ((*in >> 6) & 0x3F) | 0x80; + *out++ = (*in++ & 0x3F) | 0x80; + maxlen -= 3; + } else { + break; + } + } + } + *out = 0; +} |