1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_i18npool.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <inputsequencechecker_hi.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir using namespace rtl;
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir namespace com {
36*cdf0e10cSrcweir namespace sun {
37*cdf0e10cSrcweir namespace star {
38*cdf0e10cSrcweir namespace i18n {
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir InputSequenceChecker_hi::InputSequenceChecker_hi()
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir 	serviceName = "com.sun.star.i18n.InputSequenceChecker_hi";
43*cdf0e10cSrcweir }
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir InputSequenceChecker_hi::~InputSequenceChecker_hi()
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir }
48*cdf0e10cSrcweir /* Non-Defined Class type */
49*cdf0e10cSrcweir #define __ND		0
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir /*
52*cdf0e10cSrcweir  * Devanagari character type definitions
53*cdf0e10cSrcweir  */
54*cdf0e10cSrcweir #define __UP  1  // ChandraBindu & Anuswar
55*cdf0e10cSrcweir #define	__NP  2  // Visarg
56*cdf0e10cSrcweir #define __IV	3  // Independant Vowels
57*cdf0e10cSrcweir #define __CN	4  // Consonants except _CK & _RC
58*cdf0e10cSrcweir #define __CK	5  // Consonants that can be followed by Nukta
59*cdf0e10cSrcweir #define __RC	6  // Ra
60*cdf0e10cSrcweir #define __NM	7  // Matra
61*cdf0e10cSrcweir #define __RM	8  // Ra + HAL
62*cdf0e10cSrcweir #define __IM	9  // Choti I Matra
63*cdf0e10cSrcweir #define __HL	10 // HAL
64*cdf0e10cSrcweir #define __NK	11 // Nukta
65*cdf0e10cSrcweir #define __VD	12 // Vedic
66*cdf0e10cSrcweir #define __HD	13 // Hindu Numerals
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir /*
69*cdf0e10cSrcweir  * Devanagari character type table
70*cdf0e10cSrcweir  */
71*cdf0e10cSrcweir static const sal_uInt16 devaCT[128] = {
72*cdf0e10cSrcweir /*         0,    1,    2,    3,    4,    5,    6,    7,
73*cdf0e10cSrcweir            8,    9,    A,    B,    C,    D,    E,    F, */
74*cdf0e10cSrcweir /* 0900 */ __ND, __UP, __UP, __NP, __ND, __IV, __IV, __IV,
75*cdf0e10cSrcweir            __IV, __IV, __IV, __IV, __IV, __IV, __IV, __IV,
76*cdf0e10cSrcweir /* 0910 */ __IV, __IV, __IV, __IV, __IV, __CK, __CK, __CK,
77*cdf0e10cSrcweir            __CN, __CN, __CN, __CN, __CK, __CN, __CN, __CN,
78*cdf0e10cSrcweir /* 0920 */ __CN, __CK, __CK, __CN, __CN, __CN, __CN, __CN,
79*cdf0e10cSrcweir            __CN, __CN, __CN, __CK, __CN, __CN, __CN, __CN,
80*cdf0e10cSrcweir /* 0930 */ __RC, __CN, __CN, __CN, __CN, __CN, __CN, __CN,
81*cdf0e10cSrcweir            __CN, __CN, __ND, __ND, __NK, __VD, __NM, __IM,
82*cdf0e10cSrcweir /* 0940 */ __RM, __NM, __NM, __NM, __NM, __RM, __RM, __RM,
83*cdf0e10cSrcweir            __RM, __RM, __RM, __RM, __RM, __HL, __ND, __ND,
84*cdf0e10cSrcweir /* 0950 */ __ND, __VD, __VD, __VD, __VD, __ND, __ND, __ND,
85*cdf0e10cSrcweir            __CN, __CN, __CN, __CN, __CN, __CN, __CN, __CN,
86*cdf0e10cSrcweir /* 0960 */ __IV, __IV, __NM, __NM, __ND, __ND, __HD, __HD,
87*cdf0e10cSrcweir            __HD, __HD, __HD, __HD, __HD, __HD, __HD, __HD,
88*cdf0e10cSrcweir /* 0970 */ __ND, __ND, __ND, __ND, __ND, __ND, __ND, __ND,
89*cdf0e10cSrcweir            __ND, __ND, __ND, __ND, __ND, __ND, __ND, __ND,
90*cdf0e10cSrcweir };
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir /*
93*cdf0e10cSrcweir  * Devanagari character composition table
94*cdf0e10cSrcweir  */
95*cdf0e10cSrcweir static const sal_uInt16 dev_cell_check[14][14] = {
96*cdf0e10cSrcweir   /*        ND, UP, NP, IV, CN, CK, RC, NM, RM, IM, HL, NK, VD, HD, */
97*cdf0e10cSrcweir   /* 0  */ { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* ND */
98*cdf0e10cSrcweir   /* 1  */ { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* UP */
99*cdf0e10cSrcweir   /* 2  */ { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* NP */
100*cdf0e10cSrcweir   /* 3  */ { 0,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* IV */
101*cdf0e10cSrcweir   /* 4  */ { 0,  1,  1,  0,  0,  0,  0,  1,  1,  1,  1,  0,  0,  0 }, /* CN */
102*cdf0e10cSrcweir   /* 5  */ { 0,  1,  1,  0,  0,  0,  0,  1,  1,  1,  1,  1,  0,  0 }, /* CK */
103*cdf0e10cSrcweir   /* 6  */ { 0,  1,  1,  0,  0,  0,  0,  1,  1,  1,  1,  0,  0,  0 }, /* RC */
104*cdf0e10cSrcweir   /* 7  */ { 0,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* NM */
105*cdf0e10cSrcweir   /* 8  */ { 0,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* RM */
106*cdf0e10cSrcweir   /* 9  */ { 0,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* IM */
107*cdf0e10cSrcweir   /* 10 */ { 0,  0,  0,  0,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0 }, /* HL */
108*cdf0e10cSrcweir   /* 11 */ { 0,  1,  1,  0,  0,  0,  0,  1,  1,  1,  1,  0,  0,  0 }, /* NK */
109*cdf0e10cSrcweir   /* 12 */ { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* VD */
110*cdf0e10cSrcweir   /* 13 */ { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }  /* HD */
111*cdf0e10cSrcweir };
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir sal_Bool _DEV_Composible[2][2] = {
114*cdf0e10cSrcweir /* Mode 0 */    {sal_True, sal_True }, // PASSTHROUGH = 0
115*cdf0e10cSrcweir /* Mode 1 */    {sal_False, sal_True}  // STRICT = 1
116*cdf0e10cSrcweir };
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir #define getCharType(x) \
119*cdf0e10cSrcweir 	((x >= 0x0900 && x < 0x097f) ? devaCT[x - 0x0900] : __ND)
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir sal_Bool SAL_CALL
122*cdf0e10cSrcweir InputSequenceChecker_hi::checkInputSequence(const OUString& Text,
123*cdf0e10cSrcweir                                             sal_Int32       nStartPos,
124*cdf0e10cSrcweir                                             sal_Unicode     inputChar,
125*cdf0e10cSrcweir                                             sal_Int16       inputCheckMode)
126*cdf0e10cSrcweir   throw(com::sun::star::uno::RuntimeException)
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir 	sal_Unicode currentChar = Text[nStartPos];
129*cdf0e10cSrcweir   sal_uInt16  ch1 = getCharType(inputChar);
130*cdf0e10cSrcweir 	sal_uInt16  ch2 = getCharType(currentChar);
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	return (_DEV_Composible[inputCheckMode][dev_cell_check[ch2][ch1]]);
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir sal_Int32 SAL_CALL
136*cdf0e10cSrcweir InputSequenceChecker_hi::correctInputSequence(OUString& Text,
137*cdf0e10cSrcweir                                             sal_Int32       nStartPos,
138*cdf0e10cSrcweir                                             sal_Unicode     inputChar,
139*cdf0e10cSrcweir                                             sal_Int16       inputCheckMode)
140*cdf0e10cSrcweir   throw(com::sun::star::uno::RuntimeException)
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     if (checkInputSequence(Text, nStartPos, inputChar, inputCheckMode))
143*cdf0e10cSrcweir         Text = Text.replaceAt(++nStartPos, 0, OUString(inputChar));
144*cdf0e10cSrcweir     else
145*cdf0e10cSrcweir         nStartPos=Text.getLength();
146*cdf0e10cSrcweir     return nStartPos;
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir } } } }
149