merge the formfield patch from ooo-build
[ooovba.git] / i18npool / source / inputchecker / inputsequencechecker_th.cxx
blob3961e4ebac9abee53afd9088e8bd42be47f47180
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inputsequencechecker_th.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
34 #include <inputsequencechecker_th.hxx>
35 #include <wtt.h>
37 using namespace rtl;
39 namespace com { namespace sun { namespace star { namespace i18n {
41 InputSequenceChecker_th::InputSequenceChecker_th()
43 serviceName = "com.sun.star.i18n.InputSequenceChecker_th";
46 InputSequenceChecker_th::~InputSequenceChecker_th()
50 /* Table for Thai Cell Manipulation */
51 sal_Char _TAC_celltype_inputcheck[17][17] = {
52 /* Cn */ /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F */
53 /* Cn-1 00 */{ 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
54 /* 10 */{ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
55 /* 20 */{ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C' },
56 /* 30 */{ 'X', 'S', 'A', 'S', 'S', 'S', 'S', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
57 /* 40 */{ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
58 /* 50 */{ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
59 /* 60 */{ 'X', 'A', 'A', 'A', 'S', 'A', 'S', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
60 /* 70 */{ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R' },
61 /* 80 */{ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R' },
62 /* 90 */{ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
63 /* A0 */{ 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
64 /* B0 */{ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
65 /* C0 */{ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
66 /* D0 */{ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
67 /* E0 */{ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R' },
68 /* F0 */{ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R' },
69 { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'R', 'C', 'R', 'R', 'R', 'R' }
72 sal_Bool _TAC_Composible[3][5] = {
73 /* 'A', 'C', 'S', 'R', 'X' */
74 /* Mode 0 */ {sal_True, sal_True, sal_True, sal_True, sal_True}, // PASSTHROUGH = 0
75 /* Mode 1 */ {sal_True, sal_True, sal_True, sal_False, sal_True}, // BASIC = 1
76 /* Mode 2 */ {sal_True, sal_True, sal_False, sal_False, sal_True} // STRICT = 2
79 static sal_Bool SAL_CALL check(sal_Unicode ch1, sal_Unicode ch2, sal_Int16 inputCheckMode)
81 sal_Int16 composible_class;
82 switch (_TAC_celltype_inputcheck[getCharType(ch1)][getCharType(ch2)]) {
83 case 'A': composible_class = 0; break;
84 case 'C': composible_class = 1; break;
85 case 'S': composible_class = 2; break;
86 case 'R': composible_class = 3; break;
87 case 'X': composible_class = 4; break;
88 default: composible_class = 0;
90 return (_TAC_Composible[inputCheckMode][composible_class]);
93 sal_Bool SAL_CALL
94 InputSequenceChecker_th::checkInputSequence(const OUString& Text, sal_Int32 nStartPos,
95 sal_Unicode inputChar, sal_Int16 inputCheckMode) throw(com::sun::star::uno::RuntimeException)
97 return check(Text[nStartPos], inputChar, inputCheckMode);
100 sal_Int32 SAL_CALL
101 InputSequenceChecker_th::correctInputSequence(OUString& Text,
102 sal_Int32 nStartPos,
103 sal_Unicode inputChar,
104 sal_Int16 inputCheckMode)
105 throw(com::sun::star::uno::RuntimeException)
107 /* 9 rules for input sequence correction, see issue i42661 for detail,
109 http://www.openoffice.org/issues/show_bug.cgi?id=42661
111 <abv> = <av1>|<av2>|<av3>|<bv1>|<bv2>
112 <abv1> = <av1>|<bv1>
113 <thanthakhat> = 0E4C (karan)
115 1. <cons> <abv>_x + <abv>_y => <cons> <abv>_y (replace)
116 2. <cons> <tone>_x + <tone>_y => <cons> <tone>_y (replace)
117 3. <cons> <abv> <tone>_x + <tone>_y => <cons> <abv> <tone>_y (replace)
118 4. <cons> <abv>_x <tone> + <abv>_y => <cons> <abv>_y <tone> (replace, reorder)
119 5. <cons> <tone> + <abv> => <cons> <abv> <tone> (reorder)
120 6. <cons> <fv1> + <tone> => <cons> <tone> <fv1> (reorder)
121 7. <cons> <tone>_x <fv1> + <tone>_y => <cons> <tone>_y <fv1> (replace, reorder)
122 8. <cons> <thanthakhat> + <abv1> => <cons> <abv1> <thanthakhat> (reorder)
123 9. <cons> <abv1>_x <thanthakhat> + <abv1>_y => <cons> <abv1>_y <thanthakhat>(reorder, replace)
125 #define CT_ABV(t) ( (t>=CT_AV1 && t<=CT_AV3) || t==CT_BV1 || t==CT_BV2)
126 #define CT_ABV1(t) (t==CT_AV1 || t==CT_BV1)
128 if (check(Text[nStartPos], inputChar, inputCheckMode))
129 Text = Text.replaceAt(++nStartPos, 0, OUString(inputChar));
130 else if (nStartPos > 0 && getCharType(Text[nStartPos-1]) == CT_CONS) {
131 sal_uInt16 t1=getCharType(Text[nStartPos]), t2=getCharType(inputChar);
132 if ( (CT_ABV(t1) && CT_ABV(t2)) || // 1.
133 (t1==CT_TONE && t2==CT_TONE) )// 2.
134 Text = Text.replaceAt(nStartPos, 1, OUString(inputChar));
135 else if ( (t1==CT_TONE && CT_ABV(t2)) || // 5.
136 (t1==CT_FV1 && t2==CT_TONE) || // 6.
137 (Text[nStartPos]==0x0E4C && CT_ABV1(t2)) ) // 8.
138 Text = Text.replaceAt(nStartPos++, 0, OUString(inputChar));
139 else
140 nStartPos=Text.getLength();
141 } else if (nStartPos > 1 && getCharType(Text[nStartPos-2]) == CT_CONS) {
142 sal_uInt16 t1=getCharType(Text[nStartPos-1]), t2=getCharType(Text[nStartPos]), t3=getCharType(inputChar);
143 if (CT_ABV(t1) && t2==CT_TONE && t3==CT_TONE) // 3.
144 Text = Text.replaceAt(nStartPos, 1, OUString(inputChar));
145 else if ( (CT_ABV(t1) && t2==CT_TONE && CT_ABV(t3)) || // 4.
146 (t1==CT_TONE && t2==CT_FV1 && t3==CT_TONE) || // 7.
147 (CT_ABV1(t1) && Text[nStartPos]==0x0E4C && CT_ABV1(t3)) ) // 9.
148 Text = Text.replaceAt(nStartPos-1, 1, OUString(inputChar));
149 else
150 nStartPos=Text.getLength();
151 } else
152 nStartPos=Text.getLength();
154 return nStartPos;
157 } } } }