blob: 2b185d311dfa02de2db5e8f6e5b9cc09ecf71ad7 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
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//
18
19#ifndef ANDROID_UNICODE_H
20#define ANDROID_UNICODE_H
21
22#include <stdint.h>
23#include <sys/types.h>
24
25#define REPLACEMENT_CHAR (0xFFFD)
26
27// this part of code is copied from umachine.h under ICU
28/**
29 * Define UChar32 as a type for single Unicode code points.
30 * UChar32 is a signed 32-bit integer (same as int32_t).
31 *
32 * The Unicode code point range is 0..0x10ffff.
33 * All other values (negative or >=0x110000) are illegal as Unicode code points.
34 * They may be used as sentinel values to indicate "done", "error"
35 * or similar non-code point conditions.
36 *
37 * @stable ICU 2.4
38 */
39typedef int32_t UChar32;
40
41namespace android {
42
43 class Encoding;
44 /**
45 * \class Unicode
46 *
47 * Helper class for getting properties of Unicode characters. Characters
48 * can have one of the types listed in CharType and each character can have the
49 * directionality of Direction.
50 */
51 class Unicode
52 {
53 public:
54 /**
55 * Directions specified in the Unicode standard. These directions map directly
56 * to java.lang.Character.
57 */
58 enum Direction {
59 DIRECTIONALITY_UNDEFINED = -1,
60 DIRECTIONALITY_LEFT_TO_RIGHT,
61 DIRECTIONALITY_RIGHT_TO_LEFT,
62 DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC,
63 DIRECTIONALITY_EUROPEAN_NUMBER,
64 DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR,
65 DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR,
66 DIRECTIONALITY_ARABIC_NUMBER,
67 DIRECTIONALITY_COMMON_NUMBER_SEPARATOR,
68 DIRECTIONALITY_NONSPACING_MARK,
69 DIRECTIONALITY_BOUNDARY_NEUTRAL,
70 DIRECTIONALITY_PARAGRAPH_SEPARATOR,
71 DIRECTIONALITY_SEGMENT_SEPARATOR,
72 DIRECTIONALITY_WHITESPACE,
73 DIRECTIONALITY_OTHER_NEUTRALS,
74 DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING,
75 DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE,
76 DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING,
77 DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE,
78 DIRECTIONALITY_POP_DIRECTIONAL_FORMAT
79 };
80
81 /**
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082 * Returns the packed data for java calls
83 * @param c The unicode character.
84 * @return The packed data for the character.
85 *
86 * Copied from java.lang.Character implementation:
87 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
88 * F E D C B A 9 8 7 6 5 4 3 2 1 0 F E D C B A 9 8 7 6 5 4 3 2 1 0
89 *
90 * 31 types ---------
91 * 18 directionalities ---------
92 * 2 mirroreds -
93 * ----------- 56 toupper diffs
94 * ----------- 48 tolower diffs
95 * --- 4 totitlecase diffs
96 * ------------- 84 numeric values
97 * --------- 24 mirror char diffs
98 */
99 static uint32_t getPackedData(UChar32 c);
100
101 /**
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 * Get the directionality of the character.
103 * @param c The unicode character.
104 * @return The direction of the character or DIRECTIONALITY_UNDEFINED.
105 */
106 static Direction getDirectionality(UChar32 c);
107
108 /**
109 * Check if the character is a mirrored character. This means that the character
110 * has an equivalent character that is the mirror image of itself.
111 * @param c The unicode character.
112 * @return True iff c has a mirror equivalent.
113 */
114 static bool isMirrored(UChar32 c);
115
116 /**
117 * Return the mirror of the given character.
118 * @param c The unicode character.
119 * @return The mirror equivalent of c. If c does not have a mirror equivalent,
120 * the original character is returned.
121 * @see isMirrored
122 */
123 static UChar32 toMirror(UChar32 c);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124 };
125
126}
127
128#endif