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