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