/************************************************************************** * * Copyright (C) 2000, International Business Machines * Corporation and others. All Rights Reserved. * *************************************************************************** * file name: compsamp.c * encoding: ASCII (7-bit) * * created on: 2000may30 * created by: Steven R. Loomis * * Sample code for the ICU compression routines. * * Note: Nothing special is needed to build this sample. Link with * the icu UC and icu I18N libraries. * * I use 'assert' for error checking, you probably will want * something more flexible. '***BEGIN SAMPLE***' and * '***END SAMPLE***' mark pieces suitable for stand alone * code snippets. * */ #include #include /* for isspace, etc. */ #include #include "unicode/utypes.h" /* Basic ICU data types */ #include "unicode/scsu.h" #include "unicode/uchar.h" #include "unicode/ustring.h" /* some more string fcns*/ #include "unicode/uloc.h" /* Some utility functions */ static const UChar kNone[] = { 0x0000 }; /* Print a UChar if possible, in seven characters. */ static void prettyPrintUChar(UChar c) { if( (c <= 0x007F) && (isgraph(c)) ) { printf(" '%c' ", (char)(0x00FF&c)); } else if ( c > 0x007F ) { char buf[100]; UErrorCode status = U_ZERO_ERROR; UTextOffset o; o = u_charName(c, U_UNICODE_CHAR_NAME, buf, 100, &status); if(U_SUCCESS(status)) { buf[6] = 0; printf("%- 7s", buf); } else { printf("??????? "); } } else { switch((char)(c & 0x007F)) { case ' ': printf(" ' ' "); break; case '\t': printf(" \t "); break; case '\n': printf(" \n "); break; default: printf(" "); break; } } } static void printUChars(const char *name = "?", const UChar *uch = kNone, int32_t len = -1 ) { int32_t i; if( (len == -1) && (uch) ) { len = u_strlen(uch); } printf("% 5s:", name); for( i = 0; i