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