unicode.c File Reference

#include <stdlib.h>
#include <string.h>
#include <iconv.h>
#include "libmtp.h"
#include "unicode.h"
#include "util.h"
#include "ptp.h"

Defines

#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)

Detailed Description

This file contains general Unicode string manipulation functions. It mainly consist of functions for converting between UCS-2 (used on the devices) and UTF-8 (used by several applications).

For a deeper understanding of Unicode encoding formats see the Wikipedia entries for UTF-16/UCS-2 and UTF-8.


Define Documentation

#define STRING_BUFFER_LENGTH   1024

The size of the buffer (in characters) used for creating string copies.


Function Documentation

int ucs2_strlen ( uint16_t const *const   unicstr  ) 

Gets the length (in characters, not bytes) of a unicode UCS-2 string, eg 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).

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.


Generated on Tue Sep 12 03:22:55 2006 for libmtp by  doxygen 1.4.7