Merge "master" branch into "db".
[sliver-openvswitch.git] / lib / unicode.h
1 /*
2  * Copyright (c) 2009 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef UNICODE_H
18 #define UNICODE_H 1
19
20 #include <stdbool.h>
21
22 /* Returns true if 'c' is a Unicode code point, otherwise false. */
23 static inline bool
24 uc_is_code_point(int c)
25 {
26     return c >= 0 && c <= 0x10ffff;
27 }
28
29 /* Returns true if 'c' is a Unicode code point for a leading surrogate. */
30 static inline bool
31 uc_is_leading_surrogate(int c)
32 {
33     return c >= 0xd800 && c <= 0xdbff;
34 }
35
36 /* Returns true if 'c' is a Unicode code point for a trailing surrogate. */
37 static inline bool
38 uc_is_trailing_surrogate(int c)
39 {
40     return c >= 0xdc00 && c <= 0xdfff;
41 }
42
43 /* Returns true if 'c' is a Unicode code point for a leading or trailing
44  * surrogate. */
45 static inline bool
46 uc_is_surrogate(int c)
47 {
48     return c >= 0xd800 && c <= 0xdfff;
49 }
50
51 int utf16_decode_surrogate_pair(int leading, int trailing);
52
53 #endif /* unicode.h */