]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/ubidi_props.c
2 *******************************************************************************
4 * Copyright (C) 2004-2012, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: ubidi_props.c
10 * tab size: 8 (not used)
13 * created on: 2004dec30
14 * created by: Markus W. Scherer
16 * Low-level Unicode bidi/shaping properties access.
19 #include "unicode/utypes.h"
20 #include "unicode/uset.h"
21 #include "unicode/udata.h" /* UDataInfo */
22 #include "ucmndata.h" /* DataHeader */
27 #include "ubidi_props.h"
32 const int32_t *indexes
;
33 const uint32_t *mirrors
;
34 const uint8_t *jgArray
;
37 uint8_t formatVersion
[4];
40 /* ubidi_props_data.h is machine-generated by genbidi --csource */
41 #define INCLUDED_FROM_UBIDI_PROPS_C
42 #include "ubidi_props_data.h"
44 /* UBiDiProps singleton ----------------------------------------------------- */
46 U_CFUNC
const UBiDiProps
*
47 ubidi_getSingleton() {
48 return &ubidi_props_singleton
;
51 /* set of property starts for UnicodeSet ------------------------------------ */
53 static UBool U_CALLCONV
54 _enumPropertyStartsRange(const void *context
, UChar32 start
, UChar32 end
, uint32_t value
) {
55 /* add the start code point to the USet */
56 const USetAdder
*sa
=(const USetAdder
*)context
;
57 sa
->add(sa
->set
, start
);
62 ubidi_addPropertyStarts(const UBiDiProps
*bdp
, const USetAdder
*sa
, UErrorCode
*pErrorCode
) {
64 UChar32 c
, start
, limit
;
66 const uint8_t *jgArray
;
69 if(U_FAILURE(*pErrorCode
)) {
73 /* add the start code point of each same-value range of the trie */
74 utrie2_enum(&bdp
->trie
, NULL
, _enumPropertyStartsRange
, sa
);
76 /* add the code points from the bidi mirroring table */
77 length
=bdp
->indexes
[UBIDI_IX_MIRROR_LENGTH
];
78 for(i
=0; i
<length
; ++i
) {
79 c
=UBIDI_GET_MIRROR_CODE_POINT(bdp
->mirrors
[i
]);
80 sa
->addRange(sa
->set
, c
, c
+1);
83 /* add the code points from the Joining_Group array where the value changes */
84 start
=bdp
->indexes
[UBIDI_IX_JG_START
];
85 limit
=bdp
->indexes
[UBIDI_IX_JG_LIMIT
];
91 sa
->add(sa
->set
, start
);
97 /* add the limit code point if the last value was not 0 (it is now start==limit) */
98 sa
->add(sa
->set
, limit
);
101 /* add code points with hardcoded properties, plus the ones following them */
103 /* (none right now) */
106 /* property access functions ------------------------------------------------ */
109 ubidi_getMaxValue(const UBiDiProps
*bdp
, UProperty which
) {
116 max
=bdp
->indexes
[UBIDI_MAX_VALUES_INDEX
];
118 case UCHAR_BIDI_CLASS
:
119 return (max
&UBIDI_CLASS_MASK
);
120 case UCHAR_JOINING_GROUP
:
121 return (max
&UBIDI_MAX_JG_MASK
)>>UBIDI_MAX_JG_SHIFT
;
122 case UCHAR_JOINING_TYPE
:
123 return (max
&UBIDI_JT_MASK
)>>UBIDI_JT_SHIFT
;
125 return -1; /* undefined */
129 U_CAPI UCharDirection
130 ubidi_getClass(const UBiDiProps
*bdp
, UChar32 c
) {
131 uint16_t props
=UTRIE2_GET16(&bdp
->trie
, c
);
132 return (UCharDirection
)UBIDI_GET_CLASS(props
);
136 ubidi_isMirrored(const UBiDiProps
*bdp
, UChar32 c
) {
137 uint16_t props
=UTRIE2_GET16(&bdp
->trie
, c
);
138 return (UBool
)UBIDI_GET_FLAG(props
, UBIDI_IS_MIRRORED_SHIFT
);
142 ubidi_getMirror(const UBiDiProps
*bdp
, UChar32 c
) {
143 uint16_t props
=UTRIE2_GET16(&bdp
->trie
, c
);
144 int32_t delta
=((int16_t)props
)>>UBIDI_MIRROR_DELTA_SHIFT
;
145 if(delta
!=UBIDI_ESC_MIRROR_DELTA
) {
148 /* look for mirror code point in the mirrors[] table */
149 const uint32_t *mirrors
;
154 mirrors
=bdp
->mirrors
;
155 length
=bdp
->indexes
[UBIDI_IX_MIRROR_LENGTH
];
158 for(i
=0; i
<length
; ++i
) {
160 c2
=UBIDI_GET_MIRROR_CODE_POINT(m
);
162 /* found c, return its mirror code point using the index in m */
163 return UBIDI_GET_MIRROR_CODE_POINT(mirrors
[UBIDI_GET_MIRROR_INDEX(m
)]);
169 /* c not found, return it itself */
175 ubidi_isBidiControl(const UBiDiProps
*bdp
, UChar32 c
) {
176 uint16_t props
=UTRIE2_GET16(&bdp
->trie
, c
);
177 return (UBool
)UBIDI_GET_FLAG(props
, UBIDI_BIDI_CONTROL_SHIFT
);
181 ubidi_isJoinControl(const UBiDiProps
*bdp
, UChar32 c
) {
182 uint16_t props
=UTRIE2_GET16(&bdp
->trie
, c
);
183 return (UBool
)UBIDI_GET_FLAG(props
, UBIDI_JOIN_CONTROL_SHIFT
);
187 ubidi_getJoiningType(const UBiDiProps
*bdp
, UChar32 c
) {
188 uint16_t props
=UTRIE2_GET16(&bdp
->trie
, c
);
189 return (UJoiningType
)((props
&UBIDI_JT_MASK
)>>UBIDI_JT_SHIFT
);
192 U_CFUNC UJoiningGroup
193 ubidi_getJoiningGroup(const UBiDiProps
*bdp
, UChar32 c
) {
194 UChar32 start
, limit
;
196 start
=bdp
->indexes
[UBIDI_IX_JG_START
];
197 limit
=bdp
->indexes
[UBIDI_IX_JG_LIMIT
];
198 if(start
<=c
&& c
<limit
) {
199 return (UJoiningGroup
)bdp
->jgArray
[c
-start
];
201 return U_JG_NO_JOINING_GROUP
;
205 /* public API (see uchar.h) ------------------------------------------------- */
207 U_CFUNC UCharDirection
208 u_charDirection(UChar32 c
) {
209 return ubidi_getClass(&ubidi_props_singleton
, c
);
213 u_isMirrored(UChar32 c
) {
214 return ubidi_isMirrored(&ubidi_props_singleton
, c
);
218 u_charMirror(UChar32 c
) {
219 return ubidi_getMirror(&ubidi_props_singleton
, c
);