unicode.c(3)
unicode.c(3) π
okay bestie, welcome to the Library Functions Manual page for unicode.c. This is the libmtp Unicode-string corner of the group chat, and it's giving βconvert me between encodings, but make it cute.β π¦
πΈ NAME πΈ
unicode.c
β¨ SYNOPSIS β¨
#include 'config.h'
#include <stdlib.h>
#include <string.h>
#include 'libmtp.h'
#include 'unicode.h'
#include 'util.h'
#include 'ptp.h'
Macros
#define STRING_BUFFER_LENGTH 1024
Functions
int ucs2_strlen (uint16_t const *const unicstr)char * utf16_to_utf8 (LIBMTP_mtpdevice_t *device, const uint16_t *unicstr)uint16_t * utf8_to_utf16 (LIBMTP_mtpdevice_t *device, const char *localstr)void strip_7bit_from_utf8 (char *str)
π Detailed Description π
This file is literally where general Unicode string manipulation functions live β mostly the converters between UCS-2 (what the devices use) and UTF-8 (what several applications use). β¨
For a deeper understanding of Unicode encoding formats, see the Wikipedia entries for UTF-16/UCS-2 and UTF-8.
Copyright (C) 2005-2009 Linus Walleij triad@df.lth.se
The legal bestie section, preserved with care:
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
π Macro Definition Documentation π
π #define STRING_BUFFER_LENGTH 1024
The size of the buffer (in characters) used for creating string copies.
Referenced by utf16_to_utf8(), and utf8_to_utf16().
π¦ Function Documentation π¦
π§ void strip_7bit_from_utf8 (char * str)
This helper function simply removes any consecutive chars 0x7F and replaces them with an underscore. In UTF-8, consecutive chars > 0x7F represent one single character, so it has to be done like this (and it's elegant). It will only shrink the string in size, so no copying is needed.
Referenced by LIBMTP_Create_Folder().
π§ int ucs2_strlen (uint16_t const *const unicstr)
Gets the length (in characters, not bytes) of a unicode UCS-2 string. Example: a string which physically is 0x00 0x41 0x00 0x00 will return a value of 1.
Parameters
unicstrβ a UCS-2 Unicode string
Returns
the length of the string, in number of characters. If you want to know the length in bytes, multiply this by two and add two (for zero terminator).
Referenced by utf16_to_utf8(), and utf8_to_utf16().
π§ char * utf16_to_utf8 (LIBMTP_mtpdevice_t * device, const uint16_t * unicstr)
Converts a big-endian UTF-16 2-byte string to a UTF-8 string. Actually just a UCS-2 internal conversion routine that strips off the BOM if there is one.
Parameters
deviceβ a pointer to the current device.unicstrβ the UTF-16 unicode string to convert
Returns
a UTF-8 string.
References LIBMTP_mtpdevice_struct::params, STRING_BUFFER_LENGTH, and ucs2_strlen().
π§ uint16_t * utf8_to_utf16 (LIBMTP_mtpdevice_t * device, const char * localstr)
Converts a UTF-8 string to a big-endian UTF-16 2-byte string. Actually just a UCS-2 internal conversion.
Parameters
deviceβ a pointer to the current device.localstrβ the UTF-8 unicode string to convert
Returns
a UTF-16 string.
References LIBMTP_mtpdevice_struct::params, STRING_BUFFER_LENGTH, and ucs2_strlen().
π Author π
Generated automatically by Doxygen for libmtp from the source code.
Mwah π that's the whole page. It's from libmtp, Version 1.1.23 β the footer's source/version line. No separate calendar date is printed in that footer, so don't come for me π. unicode.c(3) forever. π
π¦ where this page comes from
- arch rolling: libmtp 1.1.23-1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms