]> git.saurik.com Git - apple/icu.git/blame - icuSources/samples/case/case.cpp
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / samples / case / case.cpp
CommitLineData
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
21U_CFUNC int c_main(UFILE *out);
22
23void printUnicodeString(UFILE *out, const UnicodeString &s) {
374ca955
A
24 UnicodeString other = s;
25 u_fprintf(out, "\"%S\"", other.getTerminatedBuffer());
b75a7d8f
A
26}
27
28
29int main( void )
30{
374ca955
A
31 UFILE *out;
32 UErrorCode status = U_ZERO_ERROR;
33 out = u_finit(stdout, NULL, NULL);
34 if(!out) {
35 fprintf(stderr, "Could not initialize (finit()) over stdout! \n");
36 return 1;
37 }
38 ucnv_setFromUCallBack(u_fgetConverter(out), UCNV_FROM_U_CALLBACK_ESCAPE,
39 NULL, NULL, NULL, &status);
40 if(U_FAILURE(status)) {
41 u_fprintf(out, "Warning- couldn't set the substitute callback - err %s\n", u_errorName(status));
42 }
43
44 /* End Demo boilerplate */
45
46 u_fprintf(out,"ICU Case Mapping Sample Program\n\n");
47 u_fprintf(out, "C++ Case Mapping\n\n");
48
49 UnicodeString string("This is a test");
50 /* lowercase = "istanbul" */
51 UChar lowercase[] = {0x69, 0x73, 0x74, 0x61, 0x6e, 0x62, 0x75, 0x6c, 0};
52 /* uppercase = "LATIN CAPITAL I WITH DOT ABOVE STANBUL" */
53 UChar uppercase[] = {0x0130, 0x53, 0x54, 0x41, 0x4e, 0x42, 0x55, 0x4C, 0};
54
55 UnicodeString upper(uppercase);
56 UnicodeString lower(lowercase);
57
58 u_fprintf(out, "\nstring: ");
59 printUnicodeString(out, string);
60 string.toUpper(); /* string = "THIS IS A TEST" */
61 u_fprintf(out, "\ntoUpper(): ");
62 printUnicodeString(out, string);
63 string.toLower(); /* string = "this is a test" */
64 u_fprintf(out, "\ntoLower(): ");
65 printUnicodeString(out, string);
66
67 u_fprintf(out, "\n\nlowercase=%S, uppercase=%S\n", lowercase, uppercase);
68
69
70 string = upper;
71 string.toLower(Locale("tr", "TR")); /* Turkish lower case map string =
72 lowercase */
73 u_fprintf(out, "\nupper.toLower: ");
74 printUnicodeString(out, string);
75
76 string = lower;
77 string.toUpper(Locale("tr", "TR")); /* Turkish upper case map string =
78 uppercase */
79 u_fprintf(out, "\nlower.toUpper: ");
80 printUnicodeString(out, string);
81
82
83 u_fprintf(out, "\nEnd C++ sample\n\n");
84
85 // Call the C version
86 int rc = c_main(out);
87 u_fclose(out);
88 return rc;
b75a7d8f 89}
374ca955 90