unicode.c(3)
๐ฆ unicode.c(3) โ Library Functions Manual ๐ฆ
okay bestie, welcome to unicode.c(3) from the libmtp family of manual pages ๐ this one's short, it's cute, it's lowkey iconic โ it's all about shuffling strings between the encoding your device speaks and the encoding your app speaks. let's get into it โจ
๐ธ NAME ๐ธ
libmtp - _(yes that's literally it, the NAME line is just vibing with a dash, no cap)_
โจ 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 the general Unicode string manipulation zone, bestie ๐ง it mainly consists of functions for converting between UCS-2 (which is what the devices use) and UTF-8 (which is what several applications use). it's giving translator energy, fr fr ๐
if you want a deeper understanding of Unicode encoding formats, the original text points you at the Wikipedia entries for UTF-16/UCS-2 and UTF-8 ๐ go read them, iykyk.
Copyright (C) 2005-2009 Linus Walleij triad@df.lth.se
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 โ like, the whole disclaimer is doing main character energy, do not skip it.
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. simple, generous, 1024 characters of room to breathe ๐
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. (yes, really, it just goes in there and does the thing ๐ฉน)
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 โ obsessed with the efficiency tbh.
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. for example, a string which physically is 0x00 0x41 0x00 0x00 will return a value of 1. not me being shook at how tidy that is ๐ญ
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) ๐งฎ math is math, bestie.
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 ๐ (bye bye byte order mark, we hardly knew ye).
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. the round trip is complete, we love a symmetrical queen ๐
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 ๐ค (yes the robot wrote this part, and honestly? it ate).
okay that's the whole page bestie, you're officially unicode-literate ๐
this was unicode.c(3) from libmtp, Version 1.1.23 โ thanks for reading, mwah, take care of your strings ๐ธ๐ซถโจ
๐ฆ where this page comes from
- ubuntu stonking: libmtp-doc 1.1.23-1 ยท LGPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms