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