]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ******************************************************************************* | |
3 | * | |
f3c0d7a5 A |
4 | * © 2016 and later: Unicode, Inc. and others. |
5 | * License & terms of use: http://www.unicode.org/copyright.html#License | |
6 | * | |
7 | ******************************************************************************* | |
8 | ******************************************************************************* | |
9 | * | |
374ca955 | 10 | * Copyright (C) 2003-2004, International Business Machines |
b75a7d8f A |
11 | * Corporation and others. All Rights Reserved. |
12 | * | |
13 | ******************************************************************************* | |
14 | */ | |
15 | ||
16 | #include <unicode/unistr.h> | |
17 | #include <unicode/ustdio.h> | |
b75a7d8f A |
18 | #include <unicode/brkiter.h> |
19 | #include <stdlib.h> | |
20 | ||
0f5d89e8 A |
21 | using namespace icu; |
22 | ||
b75a7d8f A |
23 | U_CFUNC int c_main(UFILE *out); |
24 | ||
25 | void printUnicodeString(UFILE *out, const UnicodeString &s) { | |
374ca955 A |
26 | UnicodeString other = s; |
27 | u_fprintf(out, "\"%S\"", other.getTerminatedBuffer()); | |
b75a7d8f A |
28 | } |
29 | ||
30 | ||
31 | int main( void ) | |
32 | { | |
374ca955 A |
33 | UFILE *out; |
34 | UErrorCode status = U_ZERO_ERROR; | |
35 | out = u_finit(stdout, NULL, NULL); | |
36 | if(!out) { | |
37 | fprintf(stderr, "Could not initialize (finit()) over stdout! \n"); | |
38 | return 1; | |
39 | } | |
40 | ucnv_setFromUCallBack(u_fgetConverter(out), UCNV_FROM_U_CALLBACK_ESCAPE, | |
41 | NULL, NULL, NULL, &status); | |
42 | if(U_FAILURE(status)) { | |
43 | u_fprintf(out, "Warning- couldn't set the substitute callback - err %s\n", u_errorName(status)); | |
44 | } | |
45 | ||
46 | /* End Demo boilerplate */ | |
47 | ||
48 | u_fprintf(out,"ICU Case Mapping Sample Program\n\n"); | |
49 | u_fprintf(out, "C++ Case Mapping\n\n"); | |
50 | ||
51 | UnicodeString string("This is a test"); | |
52 | /* lowercase = "istanbul" */ | |
53 | UChar lowercase[] = {0x69, 0x73, 0x74, 0x61, 0x6e, 0x62, 0x75, 0x6c, 0}; | |
54 | /* uppercase = "LATIN CAPITAL I WITH DOT ABOVE STANBUL" */ | |
55 | UChar uppercase[] = {0x0130, 0x53, 0x54, 0x41, 0x4e, 0x42, 0x55, 0x4C, 0}; | |
56 | ||
57 | UnicodeString upper(uppercase); | |
58 | UnicodeString lower(lowercase); | |
59 | ||
60 | u_fprintf(out, "\nstring: "); | |
61 | printUnicodeString(out, string); | |
62 | string.toUpper(); /* string = "THIS IS A TEST" */ | |
63 | u_fprintf(out, "\ntoUpper(): "); | |
64 | printUnicodeString(out, string); | |
65 | string.toLower(); /* string = "this is a test" */ | |
66 | u_fprintf(out, "\ntoLower(): "); | |
67 | printUnicodeString(out, string); | |
68 | ||
69 | u_fprintf(out, "\n\nlowercase=%S, uppercase=%S\n", lowercase, uppercase); | |
70 | ||
71 | ||
72 | string = upper; | |
73 | string.toLower(Locale("tr", "TR")); /* Turkish lower case map string = | |
74 | lowercase */ | |
75 | u_fprintf(out, "\nupper.toLower: "); | |
76 | printUnicodeString(out, string); | |
77 | ||
78 | string = lower; | |
79 | string.toUpper(Locale("tr", "TR")); /* Turkish upper case map string = | |
80 | uppercase */ | |
81 | u_fprintf(out, "\nlower.toUpper: "); | |
82 | printUnicodeString(out, string); | |
83 | ||
84 | ||
85 | u_fprintf(out, "\nEnd C++ sample\n\n"); | |
86 | ||
87 | // Call the C version | |
88 | int rc = c_main(out); | |
89 | u_fclose(out); | |
90 | return rc; | |
b75a7d8f | 91 | } |
374ca955 | 92 |