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>
29 InputSequenceChecker_hi::InputSequenceChecker_hi()
30 : InputSequenceCheckerImpl("com.sun.star.i18n.InputSequenceChecker_hi")
34 InputSequenceChecker_hi::~InputSequenceChecker_hi()
37 /* Non-Defined Class type */
41 * Devanagari character type definitions
43 #define __UP 1 // ChandraBindu & Anuswar
44 #define __NP 2 // Visarg
45 #define __IV 3 // Independent Vowels
46 #define __CN 4 // Consonants except _CK & _RC
47 #define __CK 5 // Consonants that can be followed by Nukta
49 #define __NM 7 // Matra
50 #define __RM 8 // Ra + HAL
51 #define __IM 9 // Choti I Matra
52 #define __HL 10 // HAL
53 #define __NK 11 // Nukta
54 #define __VD 12 // Vedic
55 #define __HD 13 // Hindu Numerals
58 * Devanagari character type table
60 static const sal_uInt16 devaCT
[128] = {
61 /* 0, 1, 2, 3, 4, 5, 6, 7,
62 8, 9, A, B, C, D, E, F, */
63 /* 0900 */ __ND
, __UP
, __UP
, __NP
, __ND
, __IV
, __IV
, __IV
,
64 __IV
, __IV
, __IV
, __IV
, __IV
, __IV
, __IV
, __IV
,
65 /* 0910 */ __IV
, __IV
, __IV
, __IV
, __IV
, __CK
, __CK
, __CK
,
66 __CN
, __CN
, __CN
, __CN
, __CK
, __CN
, __CN
, __CN
,
67 /* 0920 */ __CN
, __CK
, __CK
, __CN
, __CN
, __CN
, __CN
, __CN
,
68 __CN
, __CN
, __CN
, __CK
, __CN
, __CN
, __CN
, __CN
,
69 /* 0930 */ __RC
, __CN
, __CN
, __CN
, __CN
, __CN
, __CN
, __CN
,
70 __CN
, __CN
, __ND
, __ND
, __NK
, __VD
, __NM
, __IM
,
71 /* 0940 */ __RM
, __NM
, __NM
, __NM
, __NM
, __RM
, __RM
, __RM
,
72 __RM
, __RM
, __RM
, __RM
, __RM
, __HL
, __ND
, __ND
,
73 /* 0950 */ __ND
, __VD
, __VD
, __VD
, __VD
, __ND
, __ND
, __ND
,
74 __CN
, __CN
, __CN
, __CN
, __CN
, __CN
, __CN
, __CN
,
75 /* 0960 */ __IV
, __IV
, __NM
, __NM
, __ND
, __ND
, __HD
, __HD
,
76 __HD
, __HD
, __HD
, __HD
, __HD
, __HD
, __HD
, __HD
,
77 /* 0970 */ __ND
, __ND
, __ND
, __ND
, __ND
, __ND
, __ND
, __ND
,
78 __ND
, __ND
, __ND
, __ND
, __ND
, __ND
, __ND
, __ND
,
82 * Devanagari character composition table
84 static const sal_uInt16 dev_cell_check
[14][14] = {
85 /* ND, UP, NP, IV, CN, CK, RC, NM, RM, IM, HL, NK, VD, HD, */
86 /* 0 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ND */
87 /* 1 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* UP */
88 /* 2 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* NP */
89 /* 3 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* IV */
90 /* 4 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* CN */
91 /* 5 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0 }, /* CK */
92 /* 6 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* RC */
93 /* 7 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* NM */
94 /* 8 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* RM */
95 /* 9 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* IM */
96 /* 10 */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, /* HL */
97 /* 11 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* NK */
98 /* 12 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* VD */
99 /* 13 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* HD */
102 sal_Bool _DEV_Composible
[2][2] = {
103 /* Mode 0 */ {sal_True
, sal_True
}, // PASSTHROUGH = 0
104 /* Mode 1 */ {sal_False
, sal_True
} // STRICT = 1
107 #define getCharType(x) \
108 ((x >= 0x0900 && x < 0x097f) ? devaCT[x - 0x0900] : __ND)
111 InputSequenceChecker_hi::checkInputSequence(const OUString
& Text
,
113 sal_Unicode inputChar
,
114 sal_Int16 inputCheckMode
)
115 throw(com::sun::star::uno::RuntimeException
, std::exception
)
117 sal_Unicode currentChar
= Text
[nStartPos
];
118 sal_uInt16 ch1
= getCharType(inputChar
);
119 sal_uInt16 ch2
= getCharType(currentChar
);
121 return (_DEV_Composible
[inputCheckMode
][dev_cell_check
[ch2
][ch1
]]);
125 InputSequenceChecker_hi::correctInputSequence(OUString
& Text
,
127 sal_Unicode inputChar
,
128 sal_Int16 inputCheckMode
)
129 throw(com::sun::star::uno::RuntimeException
, std::exception
)
131 if (checkInputSequence(Text
, nStartPos
, inputChar
, inputCheckMode
))
132 Text
= Text
.replaceAt(++nStartPos
, 0, OUString(inputChar
));
134 nStartPos
=Text
.getLength();
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */