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