libnjb: /usr/obj/ports/libnjb-2.2.7/libnjb-2.2.7/src/unicode.c File Reference

libnjb 2.2.7

- Main Page
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

Macros | Functions | Variables
unicode.c File Reference
`#include <stdlib.h>`
`#include <string.h>`
`#include <errno.h>`
`#include "libnjb.h"`
`#include "protocol.h"`
`#include "protocol3.h"`
`#include "unicode.h"`
`#include "njb_error.h"`
`#include "usb_io.h"`
`#include "ioutil.h"`
`#include "defs.h"`
`#include "base.h"`

## Macros
#define | MAX_STRING_LENGTH 512

## Functions
void | njb_set_unicode (int flag)
int | ucs2strlen (const unsigned char *unicstr)
char * | strtoutf8 (const unsigned char *str)
char * | utf8tostr (const unsigned char *str)
char * | ucs2tostr (const unsigned char *unicstr)
unsigned char * | strtoucs2 (const unsigned char *str)

## Variables
int | __sub_depth
int | njb_unicode_flag = NJB_UC_8859

## Detailed Description

This file contains general Unicode string manipulation functions. It mainly consist of functions for converting between UCS-2 (used on the devices), UTF-8 (used by several applications) and ISO 8859-1 / Codepage 1252 (fallback).

## Function Documentation

void njb_set_unicode | ( | int | flag | ) |

This flag determines whether to use ISO 8859-1 / codepage 1252 (default) or unicode UTF-8 for ALL strings sent into and out of libnjb, for ALL sessions and devices.

Parameters

  flag | 0 for ISO 8859-1 / codepage 1252 or 1 for Unicode UTF-8.

Referenced by NJB_Set_Unicode().

unsigned char* strtoucs2 | ( | const unsigned char * | str | ) |

Convert a simple ISO 8859-1 or a Unicode UTF8 string (depending on library Unicode flag) to a unicode UCS-2 string.

Parameters

  str | the ISO 8859-1 or UTF-8 string to conver

Returns
  a pointer to a newly allocated UCS-2 string

References NJB_UC_UTF8.

Referenced by datafile_pack3(), new_folder_pack3(), NJB_Update_Playlist(), songid_pack(), songid_pack3(), and utf8tostr().

char* strtoutf8 | ( | const unsigned char * | str | ) |

This function converts an ordinary ISO 8859-1 string to a unicode UTF-8 string

Parameters

  str | the ISO 8859-1 string to convert

Returns
  a newly allocated UTF-8 encoded string with the same content. Should be freed after use.

Referenced by datafile_unpack(), NJB_Get_Owner_String(), playlist_unpack(), and songid_unpack().

int ucs2strlen | ( | const unsigned char * | 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).

Referenced by njb3_create_playlist(), njb3_update_string_frame(), songid_pack(), songid_pack3(), and ucs2tostr().

char* ucs2tostr | ( | const unsigned char * | unicstr | ) |

Converts a Unicode UCS-2 2-byte string to a common ISO 8859-1 string quick and dirty (japanese unicodes etc, that use all 16 bits will fail miserably)

Parameters

  unicstr | the UCS-2 unicode string to convert

Returns
  a newly allocated ISO 8859-1 string that tries to resemble the UCS-2 string

References NJB_UC_UTF8, and ucs2strlen().

Referenced by songid_unpack().

char* utf8tostr | ( | const unsigned char * | str | ) |

This function approximates an ISO 8859-1 string from a UTF-8 string, leaving out untranslatable characters

Parameters

  str | the UTF-8 string to use as indata

Returns
  a newly allocated ISO 8859-1 string which is as close a possible to the UTF-8 string.

References strtoucs2().

Referenced by datafile_pack(), NJB_Set_Owner_String(), NJB_Update_Playlist(), and songid_pack().

## Variable Documentation

int __sub_depth

The current subroutine depth for all of libnjb (global)

int njb_unicode_flag = NJB_UC_8859

A flag for if unicode is used or not (global)