OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * | 3 * |
4 * Copyright (C) 2003-2007, International Business Machines | 4 * Copyright (C) 2003-2014, International Business Machines |
5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
6 * | 6 * |
7 ******************************************************************************* | 7 ******************************************************************************* |
8 * file name: uciter8.c | 8 * file name: uciter8.c |
9 * encoding: US-ASCII | 9 * encoding: US-ASCII |
10 * tab size: 8 (not used) | 10 * tab size: 8 (not used) |
11 * indentation:4 | 11 * indentation:4 |
12 * | 12 * |
13 * created on: 2003jan10 | 13 * created on: 2003jan10 |
14 * created by: Markus W. Scherer | 14 * created by: Markus W. Scherer |
15 * | 15 * |
16 * This file contains sample code that illustrates reading | 16 * This file contains sample code that illustrates reading |
17 * 8-bit Unicode text leniently, accepting a mix of UTF-8 and CESU-8 | 17 * 8-bit Unicode text leniently, accepting a mix of UTF-8 and CESU-8 |
18 * and also accepting single surrogates. | 18 * and also accepting single surrogates. |
19 */ | 19 */ |
20 | 20 |
21 #include <stdio.h> | 21 #include <stdio.h> |
22 #include <string.h> | 22 #include <string.h> |
23 #include "unicode/utypes.h" | 23 #include "unicode/utypes.h" |
24 #include "unicode/uiter.h" | 24 #include "unicode/uiter.h" |
25 #include "uit_len8.h" | 25 #include "uit_len8.h" |
26 | 26 |
27 #define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) | |
28 | |
29 #define log_err printf | 27 #define log_err printf |
30 | 28 |
31 /* UCharIterator test ------------------------------------------------------- */ | 29 /* UCharIterator test ------------------------------------------------------- */ |
32 | 30 |
33 /* | 31 /* |
34 * The following code is a copy of the UCharIterator test code in | 32 * The following code is a copy of the UCharIterator test code in |
35 * source/test/cintltst/custrtst.c, | 33 * source/test/cintltst/custrtst.c, |
36 * testing the lenient-8 iterator instead of the UTF-8 one. | 34 * testing the lenient-8 iterator instead of the UTF-8 one. |
37 */ | 35 */ |
38 | 36 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 /* compare the same string between UTF-16 and lenient-8 UCharIterators */ | 311 /* compare the same string between UTF-16 and lenient-8 UCharIterators */ |
314 uiter_setString(&iter1, text, -1); | 312 uiter_setString(&iter1, text, -1); |
315 uiter_setLenient8(&iter2, (const char *)bytes, sizeof(bytes)-1); | 313 uiter_setLenient8(&iter2, (const char *)bytes, sizeof(bytes)-1); |
316 compareIterators(&iter1, "UTF16Iterator", &iter2, "Lenient8Iterator"); | 314 compareIterators(&iter1, "UTF16Iterator", &iter2, "Lenient8Iterator"); |
317 | 315 |
318 /* try again with length=-1 */ | 316 /* try again with length=-1 */ |
319 uiter_setLenient8(&iter2, (const char *)bytes, -1); | 317 uiter_setLenient8(&iter2, (const char *)bytes, -1); |
320 compareIterators(&iter1, "UTF16Iterator", &iter2, "Lenient8Iterator_1"); | 318 compareIterators(&iter1, "UTF16Iterator", &iter2, "Lenient8Iterator_1"); |
321 | 319 |
322 /* test get/set state */ | 320 /* test get/set state */ |
323 length=LENGTHOF(text)-1; | 321 length=UPRV_LENGTHOF(text)-1; |
324 uiter_setLenient8(&iter1, (const char*)bytes, -1); | 322 uiter_setLenient8(&iter1, (const char*)bytes, -1); |
325 testIteratorState(&iter1, &iter2, "Lenient8IteratorState", length/2); | 323 testIteratorState(&iter1, &iter2, "Lenient8IteratorState", length/2); |
326 testIteratorState(&iter1, &iter2, "Lenient8IteratorStatePlus1", length/2+1); | 324 testIteratorState(&iter1, &iter2, "Lenient8IteratorStatePlus1", length/2+1); |
327 | 325 |
328 /* ---------------------------------------------------------------------- */ | 326 /* ---------------------------------------------------------------------- */ |
329 | 327 |
330 puts("no output so far means that the lenient-8 iterator works fine"); | 328 puts("no output so far means that the lenient-8 iterator works fine"); |
331 | 329 |
332 puts("iterate forward:\nUTF-16\tlenient-8"); | 330 puts("iterate forward:\nUTF-16\tlenient-8"); |
333 uiter_setString(&iter1, text, -1); | 331 uiter_setString(&iter1, text, -1); |
(...skipping 13 matching lines...) Expand all Loading... |
347 printf("%04x\t%04x\n", c1, c2); | 345 printf("%04x\t%04x\n", c1, c2); |
348 } | 346 } |
349 } | 347 } |
350 } | 348 } |
351 | 349 |
352 extern int | 350 extern int |
353 main(int argc, const char *argv[]) { | 351 main(int argc, const char *argv[]) { |
354 TestLenient8Iterator(); | 352 TestLenient8Iterator(); |
355 return 0; | 353 return 0; |
356 } | 354 } |
OLD | NEW |