1*647f063dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*647f063dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*647f063dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*647f063dSAndrew Rist * distributed with this work for additional information
6*647f063dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*647f063dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*647f063dSAndrew Rist * "License"); you may not use this file except in compliance
9*647f063dSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*647f063dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*647f063dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*647f063dSAndrew Rist * software distributed under the License is distributed on an
15*647f063dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647f063dSAndrew Rist * KIND, either express or implied. See the License for the
17*647f063dSAndrew Rist * specific language governing permissions and limitations
18*647f063dSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*647f063dSAndrew Rist *************************************************************/
21*647f063dSAndrew Rist
22*647f063dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "unichars.h"
25cdf0e10cSrcweir #include "osl/diagnose.h"
26cdf0e10cSrcweir #include "sal/types.h"
27cdf0e10cSrcweir
ImplIsNoncharacter(sal_uInt32 nUtf32)28cdf0e10cSrcweir int ImplIsNoncharacter(sal_uInt32 nUtf32)
29cdf0e10cSrcweir {
30cdf0e10cSrcweir /* All code points that are noncharacters, as of Unicode 3.1.1. */
31cdf0e10cSrcweir return (nUtf32 >= 0xFDD0 && nUtf32 <= 0xFDEF)
32cdf0e10cSrcweir || (nUtf32 & 0xFFFF) >= 0xFFFE
33cdf0e10cSrcweir || nUtf32 > 0x10FFFF;
34cdf0e10cSrcweir }
35cdf0e10cSrcweir
ImplIsControlOrFormat(sal_uInt32 nUtf32)36cdf0e10cSrcweir int ImplIsControlOrFormat(sal_uInt32 nUtf32)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir /* All code points of <http://www.unicode.org/Public/UNIDATA/
39cdf0e10cSrcweir UnicodeData.txt>, Version 3.1.1, that have a General Category of Cc
40cdf0e10cSrcweir (Other, Control) or Cf (Other, Format).
41cdf0e10cSrcweir */
42cdf0e10cSrcweir return nUtf32 <= 0x001F
43cdf0e10cSrcweir || (nUtf32 >= 0x007F && nUtf32 <= 0x009F)
44cdf0e10cSrcweir || nUtf32 == 0x070F /* SYRIAC ABBREVIATION MARK */
45cdf0e10cSrcweir || nUtf32 == 0x180B /* MONGOLIAN FREE VARIATION SELECTOR ONE */
46cdf0e10cSrcweir || nUtf32 == 0x180C /* MONGOLIAN FREE VARIATION SELECTOR TWO */
47cdf0e10cSrcweir || nUtf32 == 0x180D /* MONGOLIAN FREE VARIATION SELECTOR THREE */
48cdf0e10cSrcweir || nUtf32 == 0x180E /* MONGOLIAN VOWEL SEPARATOR */
49cdf0e10cSrcweir || nUtf32 == 0x200C /* ZERO WIDTH NON-JOINER */
50cdf0e10cSrcweir || nUtf32 == 0x200D /* ZERO WIDTH JOINER */
51cdf0e10cSrcweir || nUtf32 == 0x200E /* LEFT-TO-RIGHT MARK */
52cdf0e10cSrcweir || nUtf32 == 0x200F /* RIGHT-TO-LEFT MARK */
53cdf0e10cSrcweir || nUtf32 == 0x202A /* LEFT-TO-RIGHT EMBEDDING */
54cdf0e10cSrcweir || nUtf32 == 0x202B /* RIGHT-TO-LEFT EMBEDDING */
55cdf0e10cSrcweir || nUtf32 == 0x202C /* POP DIRECTIONAL FORMATTING */
56cdf0e10cSrcweir || nUtf32 == 0x202D /* LEFT-TO-RIGHT OVERRIDE */
57cdf0e10cSrcweir || nUtf32 == 0x202E /* RIGHT-TO-LEFT OVERRIDE */
58cdf0e10cSrcweir || nUtf32 == 0x206A /* INHIBIT SYMMETRIC SWAPPING */
59cdf0e10cSrcweir || nUtf32 == 0x206B /* ACTIVATE SYMMETRIC SWAPPING */
60cdf0e10cSrcweir || nUtf32 == 0x206C /* INHIBIT ARABIC FORM SHAPING */
61cdf0e10cSrcweir || nUtf32 == 0x206D /* ACTIVATE ARABIC FORM SHAPING */
62cdf0e10cSrcweir || nUtf32 == 0x206E /* NATIONAL DIGIT SHAPES */
63cdf0e10cSrcweir || nUtf32 == 0x206F /* NOMINAL DIGIT SHAPES */
64cdf0e10cSrcweir || nUtf32 == 0xFEFF /* ZERO WIDTH NO-BREAK SPACE */
65cdf0e10cSrcweir || nUtf32 == 0xFFF9 /* INTERLINEAR ANNOTATION ANCHOR */
66cdf0e10cSrcweir || nUtf32 == 0xFFFA /* INTERLINEAR ANNOTATION SEPARATOR */
67cdf0e10cSrcweir || nUtf32 == 0xFFFB /* INTERLINEAR ANNOTATION TERMINATOR */
68cdf0e10cSrcweir || nUtf32 == 0x1D173 /* MUSICAL SYMBOL BEGIN BEAM */
69cdf0e10cSrcweir || nUtf32 == 0x1D174 /* MUSICAL SYMBOL END BEAM */
70cdf0e10cSrcweir || nUtf32 == 0x1D175 /* MUSICAL SYMBOL BEGIN TIE */
71cdf0e10cSrcweir || nUtf32 == 0x1D176 /* MUSICAL SYMBOL END TIE */
72cdf0e10cSrcweir || nUtf32 == 0x1D177 /* MUSICAL SYMBOL BEGIN SLUR */
73cdf0e10cSrcweir || nUtf32 == 0x1D178 /* MUSICAL SYMBOL END SLUR */
74cdf0e10cSrcweir || nUtf32 == 0x1D179 /* MUSICAL SYMBOL BEGIN PHRASE */
75cdf0e10cSrcweir || nUtf32 == 0x1D17A /* MUSICAL SYMBOL END PHRASE */
76cdf0e10cSrcweir || nUtf32 == 0xE0001 /* LANGUAGE TAG */
77cdf0e10cSrcweir || (nUtf32 >= 0xE0020 && nUtf32 <= 0xE007F);
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
ImplIsHighSurrogate(sal_uInt32 nUtf32)80cdf0e10cSrcweir int ImplIsHighSurrogate(sal_uInt32 nUtf32)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir /* All code points that are high-surrogates, as of Unicode 3.1.1. */
83cdf0e10cSrcweir return nUtf32 >= 0xD800 && nUtf32 <= 0xDBFF;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
ImplIsLowSurrogate(sal_uInt32 nUtf32)86cdf0e10cSrcweir int ImplIsLowSurrogate(sal_uInt32 nUtf32)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir /* All code points that are low-surrogates, as of Unicode 3.1.1. */
89cdf0e10cSrcweir return nUtf32 >= 0xDC00 && nUtf32 <= 0xDFFF;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
ImplIsPrivateUse(sal_uInt32 nUtf32)92cdf0e10cSrcweir int ImplIsPrivateUse(sal_uInt32 nUtf32)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir /* All code points of <http://www.unicode.org/Public/UNIDATA/
95cdf0e10cSrcweir UnicodeData.txt>, Version 3.1.1, that have a General Category of Co
96cdf0e10cSrcweir (Other, Private Use).
97cdf0e10cSrcweir */
98cdf0e10cSrcweir return (nUtf32 >= 0xE000 && nUtf32 <= 0xF8FF)
99cdf0e10cSrcweir || (nUtf32 >= 0xF0000 && nUtf32 <= 0xFFFFD)
100cdf0e10cSrcweir || (nUtf32 >= 0x100000 && nUtf32 <= 0x10FFFD);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
ImplIsZeroWidth(sal_uInt32 nUtf32)103cdf0e10cSrcweir int ImplIsZeroWidth(sal_uInt32 nUtf32)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir /* All code points of <http://www.unicode.org/Public/UNIDATA/
106cdf0e10cSrcweir UnicodeData.txt>, Version 3.1.1, that have "ZERO WIDTH" in their
107cdf0e10cSrcweir Character name.
108cdf0e10cSrcweir */
109cdf0e10cSrcweir return nUtf32 == 0x200B /* ZERO WIDTH SPACE */
110cdf0e10cSrcweir || nUtf32 == 0x200C /* ZERO WIDTH NON-JOINER */
111cdf0e10cSrcweir || nUtf32 == 0x200D /* ZERO WIDTH JOINER */
112cdf0e10cSrcweir || nUtf32 == 0xFEFF; /* ZEOR WIDTH NO-BREAK SPACE */
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
ImplGetHighSurrogate(sal_uInt32 nUtf32)115cdf0e10cSrcweir sal_uInt32 ImplGetHighSurrogate(sal_uInt32 nUtf32)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir OSL_ENSURE(nUtf32 >= 0x10000, "specification violation");
118cdf0e10cSrcweir return ((nUtf32 - 0x10000) >> 10) | 0xD800;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
ImplGetLowSurrogate(sal_uInt32 nUtf32)121cdf0e10cSrcweir sal_uInt32 ImplGetLowSurrogate(sal_uInt32 nUtf32)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir OSL_ENSURE(nUtf32 >= 0x10000, "specification violation");
124cdf0e10cSrcweir return ((nUtf32 - 0x10000) & 0x3FF) | 0xDC00;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
ImplCombineSurrogates(sal_uInt32 nHigh,sal_uInt32 nLow)127cdf0e10cSrcweir sal_uInt32 ImplCombineSurrogates(sal_uInt32 nHigh, sal_uInt32 nLow)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir OSL_ENSURE(ImplIsHighSurrogate(nHigh) && ImplIsLowSurrogate(nLow),
130cdf0e10cSrcweir "specification violation");
131cdf0e10cSrcweir return (((nHigh & 0x3FF) << 10) | (nLow & 0x3FF)) + 0x10000;
132cdf0e10cSrcweir }
133