1 /* 2 ******************************************************************************* 3 * 4 * Copyright (C) 2001 - 2005, International Business Machines 5 * Corporation and others. All Rights Reserved. 6 * 7 ******************************************************************************* 8 * file name: main.cpp 9 * encoding: US-ASCII 10 * tab size: 8 (not used) 11 * indentation:4 12 * 13 * created on: 2001jul24 14 * created by: Vladimir Weinstein 15 */ 16 17 /****************************************************************************** 18 * main program demonstrating using two versions of ICU in the same project 19 ******************************************************************************/ 20 21 #include <stdio.h> 22 #include "unicode/utypes.h" 23 #include "unicode/ustring.h" 24 25 extern "C" void test_current(UChar data[][5], uint32_t size, uint32_t maxLen, uint8_t keys[][32]); 26 extern "C" void test_legacy(UChar data[][5], uint32_t size, uint32_t maxlen, uint8_t keys[][32]); 27 28 void printZTUChar(const UChar *str) { 29 while(*str != 0) { 30 if(*str > 0x1F && *str < 0x80) { 31 fprintf(stdout, "%c", (*str) & 0xFF); 32 } else { 33 fprintf(stdout, "\\u%04X", *str); 34 } 35 str++; 36 } 37 } 38 39 void printArray(const char* const comment, const UChar UArray[][5], int32_t arraySize) { 40 fprintf (stdout, "%s\n", comment); 41 int32_t i = 0; 42 for(i = 0; i<arraySize; i++) { 43 fprintf(stdout, "%d ", i); 44 printZTUChar(UArray[i]); 45 fprintf(stdout, "\n"); 46 } 47 } 48 49 void printKeys(const char *comment, uint8_t keys[][32], int32_t keySize) { 50 int32_t i = 0; 51 uint8_t *currentKey = NULL; 52 fprintf(stdout, "%s\n", comment); 53 for(i = 0; i<keySize; i++) { 54 currentKey = keys[i]; 55 while(*currentKey != 0) { 56 if(*currentKey == 1) { 57 fprintf(stdout, "01 "); 58 } else { 59 fprintf(stdout, "%02X", *currentKey); 60 } 61 currentKey++; 62 } 63 fprintf(stdout, " 00\n"); 64 } 65 } 66 67 68 //int main(int argc, const char * const argv[]) { 69 int main(int, const char * const *) { 70 static const char* test[4] = { 71 "\\u304D\\u3085\\u3046\\u0000", 72 "\\u30AD\\u30E6\\u30A6\\u0000", 73 "\\u304D\\u3086\\u3046\\u0000", 74 "\\u30AD\\u30E5\\u30A6\\u0000" 75 }; 76 77 #if 0 78 static const char* test2[4] = { 79 "dbc\\u0000", 80 "cbc\\u0000", 81 "bbc\\u0000", 82 "abc\\u0000" 83 }; 84 #endif 85 86 static UChar uTest[4][5]; 87 88 static uint8_t keys[4][32]; 89 90 uint32_t i = 0; 91 92 for(i = 0; i<4; i++) { 93 u_unescape(test[i], uTest[i], 5); 94 } 95 printArray("Before current", uTest, 4); 96 test_current(uTest, 4, 5, keys); 97 printArray("After current", uTest, 4); 98 printKeys("Current keys", keys, 4); 99 100 for(i = 0; i<4; i++) { 101 u_unescape(test[i], uTest[i], 5); 102 } 103 printArray("Before legacy", uTest, 4); 104 test_legacy(uTest, 4, 5, keys); 105 printArray("After legacy", uTest, 4); 106 printKeys("Legacy keys", keys, 4); 107 108 109 return 0; 110 } 111