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