Home | History | Annotate | Download | only in props
      1 /*
      2 *******************************************************************************
      3 *
      4 *   Copyright (C) 2000, International Business Machines
      5 *   Corporation and others.  All Rights Reserved.
      6 *
      7 *******************************************************************************
      8 *   file name:  props.cpp
      9 *   encoding:   US-ASCII
     10 *   tab size:   8 (not used)
     11 *   indentation:4
     12 *
     13 *   created on: 2000sep22
     14 *   created by: Markus W. Scherer
     15 *
     16 *   This file contains sample code that illustrates the use of the ICU APIs
     17 *   for Unicode character properties.
     18 */
     19 
     20 #include <stdio.h>
     21 #include "unicode/utypes.h"
     22 #include "unicode/uchar.h"
     23 #include "unicode/uclean.h"
     24 
     25 static void
     26 printProps(UChar32 codePoint) {
     27     char buffer[100];
     28     UErrorCode errorCode;
     29 
     30     /* get the character name */
     31     errorCode=U_ZERO_ERROR;
     32     u_charName(codePoint, U_UNICODE_CHAR_NAME, buffer, sizeof(buffer), &errorCode);
     33 
     34     /* print the code point and the character name */
     35     printf("U+%04lx\t%s\n", codePoint, buffer);
     36 
     37     /* print some properties */
     38     printf("  general category (numeric enum value): %u\n", u_charType(codePoint));
     39 
     40     /* note: these APIs do not provide the data from SpecialCasing.txt */
     41     printf("  is lowercase: %d  uppercase: U+%04lx\n", u_islower(codePoint), u_toupper(codePoint));
     42 
     43     printf("  is digit: %d  decimal digit value: %d\n", u_isdigit(codePoint), u_charDigitValue(codePoint));
     44 
     45     printf("  BiDi directional category (numeric enum value): %u\n", u_charDirection(codePoint));
     46 }
     47 
     48 /* Note: In ICU 2.0, the Unicode class is deprecated - it is a pure wrapper around the C APIs above. */
     49 
     50 extern int
     51 main(int argc, const char *argv[]) {
     52     static const UChar32
     53     codePoints[]={
     54         0xd, 0x20, 0x2d, 0x35, 0x65, 0x284, 0x665, 0x5678, 0x23456, 0x10317, 0x1D01F, 0x10fffd
     55     };
     56     int i;
     57 
     58     for(i=0; i<sizeof(codePoints)/sizeof(codePoints[0]); ++i) {
     59         printProps(codePoints[i]);
     60         puts("");
     61     }
     62 
     63     u_cleanup();
     64     return 0;
     65 }
     66