unicode.h(3)

πŸ’– unicode.h β€” libmtp's unicode bestie πŸ’–

okay so this is unicode.h(3), a page from the Library Functions Manual, and it's literally the Unicode string-wrangling part of libmtp. come get your letters converted, bestie ✨


🌸 NAME 🌸

libmtp β€”

(yes that's it. the NAME line is serving minimalism today. iconic behavior honestly πŸ’…)


✨ SYNOPSIS ✨

πŸŽ€ Functions πŸŽ€

int ucs2_strlen (uint16_t const *const)
char * utf16_to_utf8 (LIBMTP_mtpdevice_t *, const uint16_t *)
uint16_t * utf8_to_utf16 (LIBMTP_mtpdevice_t *, const char *)
void strip_7bit_from_utf8 (char *str)

πŸ¦‹ Detailed Description πŸ¦‹

so this file is the home of all the general Unicode string manipulation functions, no cap. the main character energy here is converting back and forth between UCS-2 (which is what your devices speak) and UTF-8 (which is what several applications speak). it's giving translator bestie 🫢

if you want a deeper understanding of Unicode encoding formats β€” like genuinely deep, not just vibes β€” go check the Wikipedia entries for UTF-16/UCS-2 and UTF-8. iykyk πŸ“š


Copyright (C) 2005-2007 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.

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.


πŸ”₯ Function Documentation πŸ”₯

🌈 void strip_7bit_from_utf8 (char * str)

this helper function simply removes any consecutive chars

0x7F

and replaces them with an underscore. here's the tea though: in UTF-8, consecutive chars > 0x7F represent one single character, so it has to be done like this (and it's elegant, fr fr). it will only shrink the string in size β€” no copying is needed, we love a low-effort glow-up πŸ’…

Referenced by LIBMTP_Create_Folder().


πŸ“ int ucs2_strlen (uint16_t const *const unicstr)

gets the length (in characters, not bytes, bestie β€” do not confuse them 😭) of a unicode UCS-2 string. like, a string which physically is 0x00 0x41 0x00 0x00 will return a value of 1. yes really. one whole character. slay ✨

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 the zero terminator). math girlies rise πŸ‘‘

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. honestly it's actually just a UCS-2 internal conversion routine that strips off the BOM if there is one. no BOM no problem πŸ™ˆ

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, keeping it simple, periodt πŸ’–

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. (not a human author, just a lil robot doing its thing, and honestly? ate. πŸ€–βœ¨)


okay babes that's the whole page πŸ’€ this little slice of the library lives in libmtp Version 1.1.23 β€” that's the version stamped at the bottom of the original unicode.h(3) page, along with the libmtp source tag. go convert some strings, bestie, you got this πŸ«ΆπŸ’–πŸŽ€

πŸ“¦ where this page comes from