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