1*449ab281SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*449ab281SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*449ab281SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*449ab281SAndrew Rist * distributed with this work for additional information
6*449ab281SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*449ab281SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*449ab281SAndrew Rist * "License"); you may not use this file except in compliance
9*449ab281SAndrew Rist * with the License. You may obtain a copy of the License at
10*449ab281SAndrew Rist *
11*449ab281SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*449ab281SAndrew Rist *
13*449ab281SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*449ab281SAndrew Rist * software distributed under the License is distributed on an
15*449ab281SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*449ab281SAndrew Rist * KIND, either express or implied. See the License for the
17*449ab281SAndrew Rist * specific language governing permissions and limitations
18*449ab281SAndrew Rist * under the License.
19*449ab281SAndrew Rist *
20*449ab281SAndrew Rist *************************************************************/
21*449ab281SAndrew Rist
22*449ab281SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_i18npool.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <inputsequencechecker_hi.hxx>
28cdf0e10cSrcweir
29cdf0e10cSrcweir using namespace rtl;
30cdf0e10cSrcweir
31cdf0e10cSrcweir namespace com {
32cdf0e10cSrcweir namespace sun {
33cdf0e10cSrcweir namespace star {
34cdf0e10cSrcweir namespace i18n {
35cdf0e10cSrcweir
InputSequenceChecker_hi()36cdf0e10cSrcweir InputSequenceChecker_hi::InputSequenceChecker_hi()
37cdf0e10cSrcweir {
38cdf0e10cSrcweir serviceName = "com.sun.star.i18n.InputSequenceChecker_hi";
39cdf0e10cSrcweir }
40cdf0e10cSrcweir
~InputSequenceChecker_hi()41cdf0e10cSrcweir InputSequenceChecker_hi::~InputSequenceChecker_hi()
42cdf0e10cSrcweir {
43cdf0e10cSrcweir }
44cdf0e10cSrcweir /* Non-Defined Class type */
45cdf0e10cSrcweir #define __ND 0
46cdf0e10cSrcweir
47cdf0e10cSrcweir /*
48cdf0e10cSrcweir * Devanagari character type definitions
49cdf0e10cSrcweir */
50cdf0e10cSrcweir #define __UP 1 // ChandraBindu & Anuswar
51cdf0e10cSrcweir #define __NP 2 // Visarg
52cdf0e10cSrcweir #define __IV 3 // Independant Vowels
53cdf0e10cSrcweir #define __CN 4 // Consonants except _CK & _RC
54cdf0e10cSrcweir #define __CK 5 // Consonants that can be followed by Nukta
55cdf0e10cSrcweir #define __RC 6 // Ra
56cdf0e10cSrcweir #define __NM 7 // Matra
57cdf0e10cSrcweir #define __RM 8 // Ra + HAL
58cdf0e10cSrcweir #define __IM 9 // Choti I Matra
59cdf0e10cSrcweir #define __HL 10 // HAL
60cdf0e10cSrcweir #define __NK 11 // Nukta
61cdf0e10cSrcweir #define __VD 12 // Vedic
62cdf0e10cSrcweir #define __HD 13 // Hindu Numerals
63cdf0e10cSrcweir
64cdf0e10cSrcweir /*
65cdf0e10cSrcweir * Devanagari character type table
66cdf0e10cSrcweir */
67cdf0e10cSrcweir static const sal_uInt16 devaCT[128] = {
68cdf0e10cSrcweir /* 0, 1, 2, 3, 4, 5, 6, 7,
69cdf0e10cSrcweir 8, 9, A, B, C, D, E, F, */
70cdf0e10cSrcweir /* 0900 */ __ND, __UP, __UP, __NP, __ND, __IV, __IV, __IV,
71cdf0e10cSrcweir __IV, __IV, __IV, __IV, __IV, __IV, __IV, __IV,
72cdf0e10cSrcweir /* 0910 */ __IV, __IV, __IV, __IV, __IV, __CK, __CK, __CK,
73cdf0e10cSrcweir __CN, __CN, __CN, __CN, __CK, __CN, __CN, __CN,
74cdf0e10cSrcweir /* 0920 */ __CN, __CK, __CK, __CN, __CN, __CN, __CN, __CN,
75cdf0e10cSrcweir __CN, __CN, __CN, __CK, __CN, __CN, __CN, __CN,
76cdf0e10cSrcweir /* 0930 */ __RC, __CN, __CN, __CN, __CN, __CN, __CN, __CN,
77cdf0e10cSrcweir __CN, __CN, __ND, __ND, __NK, __VD, __NM, __IM,
78cdf0e10cSrcweir /* 0940 */ __RM, __NM, __NM, __NM, __NM, __RM, __RM, __RM,
79cdf0e10cSrcweir __RM, __RM, __RM, __RM, __RM, __HL, __ND, __ND,
80cdf0e10cSrcweir /* 0950 */ __ND, __VD, __VD, __VD, __VD, __ND, __ND, __ND,
81cdf0e10cSrcweir __CN, __CN, __CN, __CN, __CN, __CN, __CN, __CN,
82cdf0e10cSrcweir /* 0960 */ __IV, __IV, __NM, __NM, __ND, __ND, __HD, __HD,
83cdf0e10cSrcweir __HD, __HD, __HD, __HD, __HD, __HD, __HD, __HD,
84cdf0e10cSrcweir /* 0970 */ __ND, __ND, __ND, __ND, __ND, __ND, __ND, __ND,
85cdf0e10cSrcweir __ND, __ND, __ND, __ND, __ND, __ND, __ND, __ND,
86cdf0e10cSrcweir };
87cdf0e10cSrcweir
88cdf0e10cSrcweir /*
89cdf0e10cSrcweir * Devanagari character composition table
90cdf0e10cSrcweir */
91cdf0e10cSrcweir static const sal_uInt16 dev_cell_check[14][14] = {
92cdf0e10cSrcweir /* ND, UP, NP, IV, CN, CK, RC, NM, RM, IM, HL, NK, VD, HD, */
93cdf0e10cSrcweir /* 0 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ND */
94cdf0e10cSrcweir /* 1 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* UP */
95cdf0e10cSrcweir /* 2 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* NP */
96cdf0e10cSrcweir /* 3 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* IV */
97cdf0e10cSrcweir /* 4 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* CN */
98cdf0e10cSrcweir /* 5 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0 }, /* CK */
99cdf0e10cSrcweir /* 6 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* RC */
100cdf0e10cSrcweir /* 7 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* NM */
101cdf0e10cSrcweir /* 8 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* RM */
102cdf0e10cSrcweir /* 9 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* IM */
103cdf0e10cSrcweir /* 10 */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, /* HL */
104cdf0e10cSrcweir /* 11 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* NK */
105cdf0e10cSrcweir /* 12 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* VD */
106cdf0e10cSrcweir /* 13 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* HD */
107cdf0e10cSrcweir };
108cdf0e10cSrcweir
109cdf0e10cSrcweir sal_Bool _DEV_Composible[2][2] = {
110cdf0e10cSrcweir /* Mode 0 */ {sal_True, sal_True }, // PASSTHROUGH = 0
111cdf0e10cSrcweir /* Mode 1 */ {sal_False, sal_True} // STRICT = 1
112cdf0e10cSrcweir };
113cdf0e10cSrcweir
114cdf0e10cSrcweir #define getCharType(x) \
115cdf0e10cSrcweir ((x >= 0x0900 && x < 0x097f) ? devaCT[x - 0x0900] : __ND)
116cdf0e10cSrcweir
117cdf0e10cSrcweir sal_Bool SAL_CALL
checkInputSequence(const OUString & Text,sal_Int32 nStartPos,sal_Unicode inputChar,sal_Int16 inputCheckMode)118cdf0e10cSrcweir InputSequenceChecker_hi::checkInputSequence(const OUString& Text,
119cdf0e10cSrcweir sal_Int32 nStartPos,
120cdf0e10cSrcweir sal_Unicode inputChar,
121cdf0e10cSrcweir sal_Int16 inputCheckMode)
122cdf0e10cSrcweir throw(com::sun::star::uno::RuntimeException)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir sal_Unicode currentChar = Text[nStartPos];
125cdf0e10cSrcweir sal_uInt16 ch1 = getCharType(inputChar);
126cdf0e10cSrcweir sal_uInt16 ch2 = getCharType(currentChar);
127cdf0e10cSrcweir
128cdf0e10cSrcweir return (_DEV_Composible[inputCheckMode][dev_cell_check[ch2][ch1]]);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir sal_Int32 SAL_CALL
correctInputSequence(OUString & Text,sal_Int32 nStartPos,sal_Unicode inputChar,sal_Int16 inputCheckMode)132cdf0e10cSrcweir InputSequenceChecker_hi::correctInputSequence(OUString& Text,
133cdf0e10cSrcweir sal_Int32 nStartPos,
134cdf0e10cSrcweir sal_Unicode inputChar,
135cdf0e10cSrcweir sal_Int16 inputCheckMode)
136cdf0e10cSrcweir throw(com::sun::star::uno::RuntimeException)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir if (checkInputSequence(Text, nStartPos, inputChar, inputCheckMode))
139cdf0e10cSrcweir Text = Text.replaceAt(++nStartPos, 0, OUString(inputChar));
140cdf0e10cSrcweir else
141cdf0e10cSrcweir nStartPos=Text.getLength();
142cdf0e10cSrcweir return nStartPos;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir } } } }
145