-
Notifications
You must be signed in to change notification settings - Fork 0
/
is2b_Ucp.c
30 lines (28 loc) · 1.09 KB
/
is2b_Ucp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdbool.h> // needed for bool, true, false
#include <stdlib.h> // needed for exit
/***************************************************************
bool is2b_Ucp(unsigned int)
Pre: This function takes an unsigned int representing
a Unicode code point.
Post: This function returns boolean true if this
unsigned int is a Unicode code point that
should be encoded as a 2-byte UTF-8
character; otherwise, the return value
is false.
Functions used: only standard library functions
Includes: stdio.h, stdbool.h, & stdlib.h (for exit())
Used in: */
bool is2b_Ucp(unsigned int u) {
// this program requires that the size of an int be 4 bytes
if( sizeof(int) != 4 ) {
fprintf(stderr, "%s: sizeof(int) is not 4!\n", __func__);
exit(EXIT_FAILURE);
}
// Unicode code point to be encoded with 2 bytes
if( (u >= 0x00000080) && (u <= 0x000007FF) ) {
return true;
} else {
return false;
}
}; /* end is2b_Ucp() */