comparison test/testiconv.c @ 1528:ff3322d66771

The check for UTF-* isn't needed anymore since UTF-8 has the same code range.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 14 Mar 2006 07:45:15 +0000
parents 4d241ea8a1cd
children 782fd950bd46 c121d94672cb 6a4f3a32c2e6
comparison
equal deleted inserted replaced
1527:ce84e28c2c07 1528:ff3322d66771
1 1
2 #include <stdio.h> 2 #include <stdio.h>
3 3
4 #include "SDL.h" 4 #include "SDL.h"
5
6 static SDL_bool testutf1632(char *data)
7 {
8 Uint32 *p = (Uint32 *)data;
9 while(*p) {
10 if ( *p > 0x10FFFF ) {
11 return SDL_FALSE;
12 }
13 ++p;
14 }
15 return SDL_TRUE;
16 }
17 5
18 static size_t widelen(char *data) 6 static size_t widelen(char *data)
19 { 7 {
20 size_t len = 0; 8 size_t len = 0;
21 Uint32 *p = (Uint32 *)data; 9 Uint32 *p = (Uint32 *)data;
61 /* Convert to UCS-4 */ 49 /* Convert to UCS-4 */
62 size_t len; 50 size_t len;
63 ucs4 = SDL_iconv_string("UCS-4", "UTF-8", buffer, SDL_strlen(buffer)+1); 51 ucs4 = SDL_iconv_string("UCS-4", "UTF-8", buffer, SDL_strlen(buffer)+1);
64 len = (widelen(ucs4)+1)*4; 52 len = (widelen(ucs4)+1)*4;
65 for ( i = 0; i < SDL_arraysize(formats); ++i ) { 53 for ( i = 0; i < SDL_arraysize(formats); ++i ) {
66 if ( (SDL_strncasecmp(formats[i], "UTF16", 5) == 0 ||
67 SDL_strncasecmp(formats[i], "UTF-16", 6) == 0 ||
68 SDL_strncasecmp(formats[i], "UTF32", 5) == 0 ||
69 SDL_strncasecmp(formats[i], "UTF-32", 6) == 0) &&
70 !testutf1632(ucs4) ) {
71 continue;
72 }
73 test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len); 54 test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len);
74 test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len); 55 test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len);
75 if ( SDL_memcmp(test[1], ucs4, len) != 0 ) { 56 if ( SDL_memcmp(test[1], ucs4, len) != 0 ) {
76 fprintf(stderr, "FAIL: %s\n", formats[i]); 57 fprintf(stderr, "FAIL: %s\n", formats[i]);
77 ++errors; 58 ++errors;