comparison test/testiconv.c @ 1502:d403a39389da

UTF-32 by definition can't handle characters higher than 0x10FFFF
author Sam Lantinga <slouken@libsdl.org>
date Mon, 13 Mar 2006 01:16:16 +0000
parents 73dc5d39bbf8
children 4d241ea8a1cd
comparison
equal deleted inserted replaced
1501:73dc5d39bbf8 1502:d403a39389da
1 1
2 #include <stdio.h> 2 #include <stdio.h>
3 3
4 #include "SDL.h" 4 #include "SDL.h"
5 5
6 static SDL_bool testutf16(char *data) 6 static SDL_bool testutf1632(char *data)
7 { 7 {
8 Uint32 *p = (Uint32 *)data; 8 Uint32 *p = (Uint32 *)data;
9 while(*p) { 9 while(*p) {
10 if ( *p > 0x10FFFF ) { 10 if ( *p > 0x10FFFF ) {
11 return SDL_FALSE; 11 return SDL_FALSE;
61 /* Convert to UCS-4 */ 61 /* Convert to UCS-4 */
62 ucs4 = SDL_iconv_string("UCS-4", "UTF-8", buffer, SDL_strlen(buffer)+1); 62 ucs4 = SDL_iconv_string("UCS-4", "UTF-8", buffer, SDL_strlen(buffer)+1);
63 size_t len = (widelen(ucs4)+1)*4; 63 size_t len = (widelen(ucs4)+1)*4;
64 for ( i = 0; i < SDL_arraysize(formats); ++i ) { 64 for ( i = 0; i < SDL_arraysize(formats); ++i ) {
65 if ( (SDL_strncasecmp(formats[i], "UTF16", 5) == 0 || 65 if ( (SDL_strncasecmp(formats[i], "UTF16", 5) == 0 ||
66 SDL_strncasecmp(formats[i], "UTF-16", 6) == 0) && 66 SDL_strncasecmp(formats[i], "UTF-16", 6) == 0 ||
67 !testutf16(ucs4) ) { 67 SDL_strncasecmp(formats[i], "UTF32", 5) == 0 ||
68 SDL_strncasecmp(formats[i], "UTF-32", 6) == 0) &&
69 !testutf1632(ucs4) ) {
68 continue; 70 continue;
69 } 71 }
70 test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len); 72 test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len);
71 test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len); 73 test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len);
72 if ( SDL_memcmp(test[1], ucs4, len) != 0 ) { 74 if ( SDL_memcmp(test[1], ucs4, len) != 0 ) {