bump product version to 6.3.0.0.beta1
[LibreOffice.git] / i18npool / source / inputchecker / inputsequencechecker_hi.cxx
blob2a33fe104d7cb1c279a165e86bcd0991275b1c7f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 namespace i18npool {
26 InputSequenceChecker_hi::InputSequenceChecker_hi()
27 : InputSequenceCheckerImpl("com.sun.star.i18n.InputSequenceChecker_hi")
31 InputSequenceChecker_hi::~InputSequenceChecker_hi()
34 /* Non-Defined Class type */
35 #define ND_ 0
38 * Devanagari character type definitions
40 #define UP_ 1 // ChandraBindu & Anuswar
41 #define NP_ 2 // Visarg
42 #define IV_ 3 // Independent Vowels
43 #define CN_ 4 // Consonants except _CK & _RC
44 #define CK_ 5 // Consonants that can be followed by Nukta
45 #define RC_ 6 // Ra
46 #define NM_ 7 // Matra
47 #define RM_ 8 // Ra + HAL
48 #define IM_ 9 // Choti I Matra
49 #define HL_ 10 // HAL
50 #define NK_ 11 // Nukta
51 #define VD_ 12 // Vedic
52 #define HD_ 13 // Hindu Numerals
55 * Devanagari character type table
57 static const sal_uInt16 devaCT[128] = {
58 /* 0, 1, 2, 3, 4, 5, 6, 7,
59 8, 9, A, B, C, D, E, F, */
60 /* 0900 */ ND_, UP_, UP_, NP_, ND_, IV_, IV_, IV_,
61 IV_, IV_, IV_, IV_, IV_, IV_, IV_, IV_,
62 /* 0910 */ IV_, IV_, IV_, IV_, IV_, CK_, CK_, CK_,
63 CN_, CN_, CN_, CN_, CK_, CN_, CN_, CN_,
64 /* 0920 */ CN_, CK_, CK_, CN_, CN_, CN_, CN_, CN_,
65 CN_, CN_, CN_, CK_, CN_, CN_, CN_, CN_,
66 /* 0930 */ RC_, CN_, CN_, CN_, CN_, CN_, CN_, CN_,
67 CN_, CN_, ND_, ND_, NK_, VD_, NM_, IM_,
68 /* 0940 */ RM_, NM_, NM_, NM_, NM_, RM_, RM_, RM_,
69 RM_, RM_, RM_, RM_, RM_, HL_, ND_, ND_,
70 /* 0950 */ ND_, VD_, VD_, VD_, VD_, ND_, ND_, ND_,
71 CN_, CN_, CN_, CN_, CN_, CN_, CN_, CN_,
72 /* 0960 */ IV_, IV_, NM_, NM_, ND_, ND_, HD_, HD_,
73 HD_, HD_, HD_, HD_, HD_, HD_, HD_, HD_,
74 /* 0970 */ ND_, ND_, ND_, ND_, ND_, ND_, ND_, ND_,
75 ND_, ND_, ND_, ND_, ND_, ND_, ND_, ND_,
79 * Devanagari character composition table
81 static const sal_uInt16 dev_cell_check[14][14] = {
82 /* ND, UP, NP, IV, CN, CK, RC, NM, RM, IM, HL, NK, VD, HD, */
83 /* 0 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ND */
84 /* 1 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* UP */
85 /* 2 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* NP */
86 /* 3 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* IV */
87 /* 4 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* CN */
88 /* 5 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0 }, /* CK */
89 /* 6 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* RC */
90 /* 7 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* NM */
91 /* 8 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* RM */
92 /* 9 */ { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* IM */
93 /* 10 */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, /* HL */
94 /* 11 */ { 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }, /* NK */
95 /* 12 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* VD */
96 /* 13 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* HD */
99 bool const DEV_Composible[2][2] = {
100 /* Mode 0 */ {true, true }, // PASSTHROUGH = 0
101 /* Mode 1 */ {false, true} // STRICT = 1
104 static constexpr sal_uInt16 getCharType(sal_Unicode x)
106 return (x >= 0x0900 && x < 0x097f) ? devaCT[x - 0x0900] : ND_;
109 sal_Bool SAL_CALL
110 InputSequenceChecker_hi::checkInputSequence(const OUString& Text,
111 sal_Int32 nStartPos,
112 sal_Unicode inputChar,
113 sal_Int16 inputCheckMode)
115 sal_Unicode currentChar = Text[nStartPos];
116 sal_uInt16 ch1 = getCharType(inputChar);
117 sal_uInt16 ch2 = getCharType(currentChar);
119 return (DEV_Composible[inputCheckMode][dev_cell_check[ch2][ch1]]);
122 sal_Int32 SAL_CALL
123 InputSequenceChecker_hi::correctInputSequence(OUString& Text,
124 sal_Int32 nStartPos,
125 sal_Unicode inputChar,
126 sal_Int16 inputCheckMode)
128 if (checkInputSequence(Text, nStartPos, inputChar, inputCheckMode))
129 Text = Text.replaceAt(++nStartPos, 0, OUString(inputChar));
130 else
131 nStartPos=Text.getLength();
132 return nStartPos;
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */