LibreOffice Module i18npool (master) 1
inputsequencechecker_hi.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
22
23
24namespace i18npool {
25
27 : InputSequenceCheckerImpl("com.sun.star.i18n.InputSequenceChecker_hi")
28{
29}
30
32{
33}
34/* Non-Defined Class type */
35#define ND_ 0
36
37/*
38 * Devanagari character type definitions
39 */
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
53
54/*
55 * Devanagari character type table
56 */
57const 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_,
76};
77
78/*
79 * Devanagari character composition table
80 */
81const 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 */
97};
98
99bool const DEV_Composible[2][2] = {
100/* Mode 0 */ {true, true }, // PASSTHROUGH = 0
101/* Mode 1 */ {false, true} // STRICT = 1
102};
103
104static constexpr sal_uInt16 getCharType(sal_Unicode x)
105{
106 return (x >= 0x0900 && x < 0x097f) ? devaCT[x - 0x0900] : ND_;
107}
108
109sal_Bool SAL_CALL
111 sal_Int32 nStartPos,
112 sal_Unicode inputChar,
113 sal_Int16 inputCheckMode)
114{
115 sal_Unicode currentChar = Text[nStartPos];
116 sal_uInt16 ch1 = getCharType(inputChar);
117 sal_uInt16 ch2 = getCharType(currentChar);
118
119 return (DEV_Composible[inputCheckMode][dev_cell_check[ch2][ch1]]);
120}
121
122sal_Int32 SAL_CALL
124 sal_Int32 nStartPos,
125 sal_Unicode inputChar,
126 sal_Int16 inputCheckMode)
127{
128 if (checkInputSequence(Text, nStartPos, inputChar, inputCheckMode))
129 Text = Text.replaceAt(++nStartPos, 0, rtl::OUStringChar(inputChar));
130 else
131 nStartPos=Text.getLength();
132 return nStartPos;
133}
134}
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 SAL_CALL correctInputSequence(OUString &Text, sal_Int32 nStartPos, sal_Unicode inputChar, sal_Int16 inputCheckMode) override
sal_Bool SAL_CALL checkInputSequence(const OUString &Text, sal_Int32 nStartPos, sal_Unicode inputChar, sal_Int16 inputCheckMode) override
float x
#define NM_
#define UP_
#define VD_
#define CN_
#define CK_
#define IV_
#define RM_
#define ND_
#define NK_
#define HD_
#define RC_
#define IM_
#define HL_
#define NP_
Constant values shared between i18npool and, for example, the number formatter.
const sal_uInt16 dev_cell_check[14][14]
bool const DEV_Composible[2][2]
static constexpr sal_uInt16 getCharType(sal_Unicode x)
const sal_uInt16 devaCT[128]
unsigned char sal_Bool
sal_uInt16 sal_Unicode