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.
Use the following typedefined types to declare characters:
CHAR_T
to declare a single character. This is
equivalent to the standard C type char
when
handling monobyte characters
UCHAR_T
to declare a single character.
UCHAR_T
and CHAR_T
are the same when using the unicode version of Amaya. It was introduced to
keep the compatibility with the monobyte version and it is equivalent to
unsigned char
type.
STRING
to declare a string and it is equivalent
to char*
type is used in monobyte characters
mode.
USTRING
to declare a string.
STRING
and USTRING
are the same when using unicode version. In monobyte mode,
USTRING
is equivalent to unsigned
char*
.
PCHAR_T
to declare a pointer to a single
character (equivalent to char*
). Do not use this
type to declare a string. It may be used as follows:
STRING str;
PCHAR_T pstr;
/*... */
pstr = str;
while (*pstr++)
do_something ();
PUCHAR_T
to declare a pointer to a single
character (equivalent to unsigned char*
).
In the near future, will use only CHAR_T
,
PCHAR_T
and
STRING
.
There is some macros #define
d 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 */
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
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);
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.