1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <inputsequencechecker_hi.hxx>
23 using ::rtl::OUString
;
30 InputSequenceChecker_hi::InputSequenceChecker_hi()
32 serviceName
= "com.sun.star.i18n.InputSequenceChecker_hi";
35 InputSequenceChecker_hi::~InputSequenceChecker_hi()
38 /* Non-Defined Class type */
42 * Devanagari character type definitions
44 #define __UP 1 // ChandraBindu & Anuswar
45 #define __NP 2 // Visarg
46 #define __IV 3 // Independant Vowels
47 #define __CN 4 // Consonants except _CK & _RC
48 #define __CK 5 // Consonants that can be followed by Nukta
50 #define __NM 7 // Matra
51 #define __RM 8 // Ra + HAL
52 #define __IM 9 // Choti I Matra
53 #define __HL 10 // HAL
54 #define __NK 11 // Nukta
55 #define __VD 12 // Vedic
56 #define __HD 13 // Hindu Numerals
59 * Devanagari character type table
61 static const sal_uInt16 devaCT
[128] = {
62 /* 0, 1, 2, 3, 4, 5, 6, 7,
63 8, 9, A, B, C, D, E, F, */
64 /* 0900 */ __ND
, __UP
, __UP
, __NP
, __ND
, __IV
, __IV
, __IV
,
65 __IV
, __IV
, __IV
, __IV
, __IV
, __IV
, __IV
, __IV
,
66 /* 0910 */ __IV
, __IV
, __IV
, __IV
, __IV
, __CK
, __CK
, __CK
,
67 __CN
, __CN
, __CN
, __CN
, __CK
, __CN
, __CN
, __CN
,
68 /* 0920 */ __CN
, __CK
, __CK
, __CN
, __CN
, __CN
, __CN
, __CN
,
69 __CN
, __CN
, __CN
, __CK
, __CN
, __CN
, __CN
, __CN
,
70 /* 0930 */ __RC
, __CN
, __CN
, __CN
, __CN
, __CN
, __CN
, __CN
,
71 __CN
, __CN
, __ND
, __ND
, __NK
, __VD
, __NM
, __IM
,
72 /* 0940 */ __RM
, __NM
, __NM
, __NM
, __NM
, __RM
, __RM
, __RM
,
73 __RM
, __RM
, __RM
, __RM
, __RM
, __HL
, __ND
, __ND
,
74 /* 0950 */ __ND
, __VD
, __VD
, __VD
, __VD
, __ND
, __ND
, __ND
,
75 __CN
, __CN
, __CN
, __CN
, __CN
, __CN
, __CN
, __CN
,
76 /* 0960 */ __IV
, __IV
, __NM
, __NM
, __ND
, __ND
, __HD
, __HD
,
77 __HD
, __HD
, __HD
, __HD
, __HD
, __HD
, __HD
, __HD
,
78 /* 0970 */ __ND
, __ND
, __ND
, __ND
, __ND
, __ND
, __ND
, __ND
,
79 __ND
, __ND
, __ND
, __ND
, __ND
, __ND
, __ND
, __ND
,
83 * Devanagari character composition table
85 static const sal_uInt16 dev_cell_check
[14][14] = {
86 /* ND, UP, NP, IV, CN, CK, RC, NM, RM, IM, HL, NK, VD, HD, */
87 /* 0 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ND */
88 /* 1 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* UP */
89 /* 2 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* NP */
90 /* 3 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* IV */
91 /* 4 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* CN */
92 /* 5 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0 }, /* CK */
93 /* 6 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* RC */
94 /* 7 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* NM */
95 /* 8 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* RM */
96 /* 9 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* IM */
97 /* 10 */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, /* HL */
98 /* 11 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* NK */
99 /* 12 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* VD */
100 /* 13 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* HD */
103 sal_Bool _DEV_Composible
[2][2] = {
104 /* Mode 0 */ {sal_True
, sal_True
}, // PASSTHROUGH = 0
105 /* Mode 1 */ {sal_False
, sal_True
} // STRICT = 1
108 #define getCharType(x) \
109 ((x >= 0x0900 && x < 0x097f) ? devaCT[x - 0x0900] : __ND)
112 InputSequenceChecker_hi::checkInputSequence(const OUString
& Text
,
114 sal_Unicode inputChar
,
115 sal_Int16 inputCheckMode
)
116 throw(com::sun::star::uno::RuntimeException
)
118 sal_Unicode currentChar
= Text
[nStartPos
];
119 sal_uInt16 ch1
= getCharType(inputChar
);
120 sal_uInt16 ch2
= getCharType(currentChar
);
122 return (_DEV_Composible
[inputCheckMode
][dev_cell_check
[ch2
][ch1
]]);
126 InputSequenceChecker_hi::correctInputSequence(OUString
& Text
,
128 sal_Unicode inputChar
,
129 sal_Int16 inputCheckMode
)
130 throw(com::sun::star::uno::RuntimeException
)
132 if (checkInputSequence(Text
, nStartPos
, inputChar
, inputCheckMode
))
133 Text
= Text
.replaceAt(++nStartPos
, 0, OUString(inputChar
));
135 nStartPos
=Text
.getLength();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */