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