Rules to write Unicode compatible code

This document is intended to help writing Unicode compatible source code in Amaya. It concerns the handling of strings in terms of memory allocation, comparison, copying etc. This document will be updated if necessary.

Declaration of characters and strings

Use the following typedefined types to declare characters:

In the near future, will use only CHAR_T, PCHAR_T and STRING.

Handling character and strings

There is some macros #defined functions to use while manipulating characters and strings:

int ustrcasecmp (STRING, const STRING); /* Eq. to strcasecmp */

STRING ustrcat (STRING, const STRING); /* Eq. strcat */

STRING ustrchr (const STRING, CHAR_T); /* Eq. strchr */

int ustrcmp (const STRING, const STRING); /* Eq. strcmp */

int ustrcoll (const STRING, const STRING); /* Eq. strcoll */

STRING ustrcpy (STRING, const STRING); /* Eq. strcpy */

STRING ustrdup (const STRING); /* Eq. strdup */

int ustrlen (const STRING); /* Eq. strlen */

int ustrncasecmp (STRING, const STRING, unsigned int); /* Eq. strncasecmp */

STRING ustrncat (STRING, const STRING, unsigned int); /* Eq. strncat */

STRING ustrncmp (const STRING, const STRING, unsigned int); /* Eq. strncmp */

STRING ustrncpy (STRING, const STRING, unsigned int); /* Eq. strncpy */

STRING ustrrchr (const STRING, CHAR_T); /* Eq. strrchr */

STRING ustrstr (const STRING, const STRING); /* Eq. strstr */

STRING ustrtok (STRING, const STRING); /* Eq. strtok */

int uctoi (const STRING); /* Eq. atoi */

CHAR_T utolower (CHAR_T); /* Eq. tolower */

ufprintf /* Eq. fprintf *

usprintf /* Eq. sprintf */

usscanf /* Eq. sscanf */

uaccess /* Eq. access */

ufgets /* Eq. fgets */

ufopen /* Eq. fopen */

uunlink /* Eq. unlink */

umkdir /* Eq. mkdir */

urmdir /* Eq. rmdir */

ugetenv /* Eq. getenv */

ugetcwd /* Eq. getcwd */

urename /* Eq. rename */

Using hardcoded characters and string

When hardcoded strings or characters are needed use the following conventions:

#if defined(_I18N_) || defined(__JIS__)

/* _I18N_ allows to use 16bits characters and strings encoding */

/* __JIS__ for 32 bits characters and strings encoding */

#define MACRO_MY_HARCODED_STRING L"this is an UCS2 coded string"

#define EOS L'\0'

STRING var_hardcoded_string = L"this is a UCS2 coded variable string;

#else /* defined(_I18N_) || defined(__JIS__) */

#define MACRO_MY_HARCODED_STRING "this is not an UCS2 coded string"

STRING var_hardcoded_string = "this is not an UCS2 coded variable string;

#define EOS '\0'

#endif

Memory management for strings

Please use the function dedicated to memory allocation for strings: TtaAllocString. See Amaya/thotlib/base/memory.c

STRING TtaAllocString (unsigned int size)

int len = ustrlen (oldString);

STRING newString = TtaAllocString (len + 1);

Ramzi Guetari

Copyright  ©  1997 W3C (MIT, INRIA, Keio ), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply. Your interactions with this site are in accordance with our public and Member privacy statements.