comparison include/SDL_stdinc.h @ 1501:73dc5d39bbf8

Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
author Sam Lantinga <slouken@libsdl.org>
date Mon, 13 Mar 2006 01:08:00 +0000
parents 84de7511f79f
children 720f8bb49d7d
comparison
equal deleted inserted replaced
1500:f58c88a4dff5 1501:73dc5d39bbf8
67 # include <stdint.h> 67 # include <stdint.h>
68 # endif 68 # endif
69 #endif 69 #endif
70 #if HAVE_CTYPE_H 70 #if HAVE_CTYPE_H
71 # include <ctype.h> 71 # include <ctype.h>
72 #endif
73 #if HAVE_ICONV_H
74 # include <iconv.h>
72 #endif 75 #endif
73 76
74 /* The number of elements in an array */ 77 /* The number of elements in an array */
75 #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0])) 78 #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
76 #define SDL_TABLESIZE(table) SDL_arraysize(table) 79 #define SDL_TABLESIZE(table) SDL_arraysize(table)
516 #define SDL_strcasecmp stricmp 519 #define SDL_strcasecmp stricmp
517 #else 520 #else
518 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); 521 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
519 #endif 522 #endif
520 523
524 #if HAVE_STRNCASECMP
525 #define SDL_strncasecmp strncasecmp
526 #else
527 extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
528 #endif
529
521 #if HAVE_SSCANF 530 #if HAVE_SSCANF
522 #define SDL_sscanf sscanf 531 #define SDL_sscanf sscanf
523 #else 532 #else
524 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...); 533 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
525 #endif 534 #endif
533 #if HAVE_VSNPRINTF 542 #if HAVE_VSNPRINTF
534 #define SDL_vsnprintf vsnprintf 543 #define SDL_vsnprintf vsnprintf
535 #else 544 #else
536 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap); 545 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
537 #endif 546 #endif
547
548 /* The SDL implementation of iconv() returns these error codes */
549 #define SDL_ICONV_ERROR (size_t)-1
550 #define SDL_ICONV_E2BIG (size_t)-2
551 #define SDL_ICONV_EILSEQ (size_t)-3
552 #define SDL_ICONV_EINVAL (size_t)-4
553
554 #if HAVE_ICONV
555 #define SDL_iconv_t iconv_t
556 #define SDL_iconv_open iconv_open
557 #define SDL_iconv_close iconv_close
558 extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
559 #else
560 typedef struct _SDL_iconv_t *SDL_iconv_t;
561 extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode);
562 extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
563 extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
564 #endif
565 /* This function converts a string between encodings in one pass, returning a
566 string that must be freed with SDL_free() or NULL on error.
567 */
568 extern DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, char *inbuf, size_t inbytesleft);
569 #define SDL_iconv_utf8_ascii(S) SDL_iconv_string("ASCII", "UTF-8", S, SDL_strlen(S)+1)
570 #define SDL_iconv_utf8_latin1(S) SDL_iconv_string("LATIN1", "UTF-8", S, SDL_strlen(S)+1)
571 #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
572 #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
538 573
539 /* Ends C function definitions when using C++ */ 574 /* Ends C function definitions when using C++ */
540 #ifdef __cplusplus 575 #ifdef __cplusplus
541 } 576 }
542 #endif 577 #endif