Go to the source code of this file.
|
They are used to maintain dual UNICODE/ASCII processing. This is needed because there are different names for mutibyte and widechar functions.
|
#define | NO_MORE WEOF |
|
#define | PUTCHAR(x, y) putwc(x,y) |
|
#define | GETCHAR(x) getwc(x) |
|
#define | STRLEN(x) wcslen(x) |
|
#define | STRNCPY(x, y, z) wcsncpy(x,y,z) |
|
#define | STRCMP(x, y) wcscmp(x,y) |
|
#define | STRTOD(x, y) wcstod(x,y) |
|
#define | STRTOL(x, y) wcstoll(x,y,0) |
|
#define | TOUPPER(x) towupper(x) |
|
#define | TOLOWER(x) towlower(x) |
|
#define | ISDIGIT(x) iswdigit(x) |
|
#define | STRCHR(x, y) wcschr(x,y) |
|
#define | PRINT(x,...) printf(x,__VA_ARGS__) |
|
#define | STRFTIME(x, y, z, t) wcsftime(x,y,z,t) |
|
#define | SPRINTF(x, n, y, z) swprintf(x,n,y,z) |
|
#define | SPRINT(x, n, y,...) swprintf(x,n,y,__VA_ARGS__) |
|
#define NULL_CHAR TEXT('\0') |
#define PUTCHAR |
( |
|
x, |
|
|
|
y |
|
) |
| putwc(x,y) |
#define GETCHAR |
( |
|
x) | |
getwc(x) |
#define STRLEN |
( |
|
x) | |
wcslen(x) |
#define STRNCPY |
( |
|
x, |
|
|
|
y, |
|
|
|
z |
|
) |
| wcsncpy(x,y,z) |
#define STRCMP |
( |
|
x, |
|
|
|
y |
|
) |
| wcscmp(x,y) |
#define STRTOD |
( |
|
x, |
|
|
|
y |
|
) |
| wcstod(x,y) |
#define STRTOL |
( |
|
x, |
|
|
|
y |
|
) |
| wcstoll(x,y,0) |
#define TOUPPER |
( |
|
x) | |
towupper(x) |
#define TOLOWER |
( |
|
x) | |
towlower(x) |
#define ISDIGIT |
( |
|
x) | |
iswdigit(x) |
#define STRCHR |
( |
|
x, |
|
|
|
y |
|
) |
| wcschr(x,y) |
#define PRINT |
( |
|
x, |
|
|
|
... |
|
) |
| printf(x,__VA_ARGS__) |
#define STRFTIME |
( |
|
x, |
|
|
|
y, |
|
|
|
z, |
|
|
|
t |
|
) |
| wcsftime(x,y,z,t) |
#define SPRINTF |
( |
|
x, |
|
|
|
n, |
|
|
|
y, |
|
|
|
z |
|
) |
| swprintf(x,n,y,z) |
#define SPRINT |
( |
|
x, |
|
|
|
n, |
|
|
|
y, |
|
|
|
... |
|
) |
| swprintf(x,n,y,__VA_ARGS__) |
- Parameters
-
source | characters to convert |
- Returns
- converted string
- Note
- defined only if UNICODE_CHARS symbol is defined
Converts string of multibyte UTF-8 encoding to widechar UTF-16LE encoding.
Definition at line 230 of file unicode.c.
232 int len = strlen ((
char*)source);
233 wchar_t *buffer = alloca(
CHAR_SIZE*(len+1) );
234 wchar_t *buf = buffer;
239 if( (*source & 0x80)==0x00 )
244 else if( (*source & 0xE0)==0xC0 )
248 wc = (wc<<6) + (*source & 0x3F);
252 else if( ((
byte_t)*source & 0xF0)==0xE0 )
256 wc = (wc<<6) + (*source & 0x3F);
258 wc = (wc<<6) + (*source & 0x3F);
266 wc = (wc<<6) + (*source & 0x3F);
268 wc = (wc<<6) + (*source & 0x3F);
270 wc = (wc<<6) + (*source & 0x3F);
274 *buf = (
unsigned short)wc;
282 memcpy( buf, buffer, len );
Definition at line 186 of file unicode.c.
188 int len =
STRLEN( source );
189 byte_t *buffer = alloca( len+1 );
202 else if( wc < 0x0800 )
206 *buf++ = 0xC0 | (
byte_t)(wc >> 6);
207 *buf++ = 0x80 | (
byte_t)(wc & 0x3F);
213 *buf++ = 0xE0 | (
byte_t)(wc >> 12);
214 *buf++ = 0x80 | (
byte_t)((wc >> 6) & 0x3F);
215 *buf++ = 0x80 | (
byte_t)(wc & 0x3F);
225 memcpy( buf, buffer, len );
Converts string of widechar UTF-16LE encoding to ASCII encoding. The input string is not freed.
- Parameters
-
- Returns
- converted string
- Note
- function defined only if
Definition at line 76 of file unicode.c.
78 size_t len = wcslen( ws );
79 char* buffer = alloca( 4*(len+1) );
84 memset (&state,
'\0',
sizeof (state));
87 nbytes = wcrtomb (buf, *ws, &state);
96 memcpy( buf, buffer, len );
chars_t ASCII_to_UTF16 |
( |
const char * |
s) | |
|
Converts string of ASCII encoding to widechar UTF-16LE encoding.
- Parameters
-
- Returns
- converted string
- Note
- defined only if UNICODE_CHARS
Definition at line 116 of file unicode.c.
120 size_t len = strlen(s);
122 wchar_t *buf = buffer;
125 memset (&state,
'\0',
sizeof (state));
128 nbytes = mbrtowc (buf, s, len, &state);
137 memcpy( buf, buffer, len );
chars_t ASCII_to_ASCII |
( |
const char * |
s) | |
|
- Parameters
-
- Returns
- converted string
- Note
- defined only if UNICODE_CHARS symbol is not defined
Converts string of ASCII encoding to ASCII. Actually does not covert anything. This function is used because it uses the ALLOC() macro which helps tracing memory allocation.
Definition at line 159 of file unicode.c.
161 #ifndef UNICODE_CHARS
163 char* buf =
ALLOC( len );
164 memcpy( buf, s, len );
168 #endif //UNICODE_CHARS
- Parameters
-
wfilename | file name |
filesize | file size |
- Returns
- word atom
Loads a text file which can be ASCII, multibyte UTF-8 or widechar UTF-16LE encoding. The size of the file is returned in filesize
so that the caller can append null character if needed.
Definition at line 303 of file unicode.c.
310 char* filename =
FILENAME(wfilename);
315 file = fopen( filename,
"rb" );
320 char buf[PATH_MAX+1];
322 char* path = dirname(buf);
323 int pathlen = strlen(path);
324 strncpy(buf,path,pathlen);
326 int filelen = strlen(filename);
327 if( pathlen+filelen+6 > PATH_MAX ) filelen=0;
329 strncpy(buf+pathlen,
"\\lib\\",5);
331 strncpy(buf+pathlen,
"/lib/",5);
333 strncpy(buf+5+pathlen,filename,filelen);
334 buf[pathlen+5+filelen] =
'\0';
338 file = fopen( buf,
"rb" );
347 fstat( fileno(file), &st_info );
348 *filesize = st_info.st_size;
356 buffer =
ALLOC(*filesize+1);
367 if( *filesize && !fread(buffer,1,*filesize,file ) )