Kaydet (Commit) f647df27 authored tarafından Bustamam Harun's avatar Bustamam Harun

#97583# Add inputsequencechecker

üst 7f3fe721
/*************************************************************************
*
* $RCSfile: inputsequencechecker.cxx,v $
*
* $Revision: 1.1 $
*
* last change: $Author: bustamam $ $Date: 2002-03-26 12:54:35 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#include <inputsequencechecker.hxx>
#include <drafts/com/sun/star/i18n/InputSequenceCheckMode.hpp>
#include <com/sun/star/i18n/UnicodeType.hpp>
#include <unicode.hxx>
#include <rtl/ustrbuf.hxx>
using namespace ::drafts::com::sun::star::i18n;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::rtl;
namespace com { namespace sun { namespace star { namespace i18n {
InputSequenceCheckerImpl::InputSequenceCheckerImpl( const Reference < XMultiServiceFactory >& rxMSF ) : xMSF( rxMSF )
{
serviceName = "com.sun.star.i18n.InputSequenceCheckerImpl";
cachedItem = NULL;
}
InputSequenceCheckerImpl::InputSequenceCheckerImpl()
{
}
InputSequenceCheckerImpl::~InputSequenceCheckerImpl()
{
// Clear lookuptable
for (cachedItem = (lookupTableItem*)lookupTable.First();
cachedItem; cachedItem = (lookupTableItem*)lookupTable.Next())
delete cachedItem;
lookupTable.Clear();
}
sal_Bool SAL_CALL
InputSequenceCheckerImpl::checkInputSequence(const OUString& Text, sal_Int32 nStartPos,
sal_Unicode inputChar, sal_Int16 inputCheckMode) throw(RuntimeException)
{
if (inputCheckMode == InputSequenceCheckMode::PASSTHROUGH)
return sal_True;
sal_Char* language = getLanguageByScripType(Text[nStartPos], inputChar);
if (language)
return getInputSequenceChecker(language)->checkInputSequence(Text, nStartPos, inputChar, inputCheckMode);
else
return sal_True; // not a checkable languages.
}
static ScriptTypeList typeList[] = {
//{ UnicodeScript_kHebrew, UnicodeScript_kHebrew }, // 10,
//{ UnicodeScript_kArabic, UnicodeScript_kArabic }, // 11,
//{ UnicodeScript_kDevanagari, UnicodeScript_kDevanagari }, // 14,
{ UnicodeScript_kThai, UnicodeScript_kThai }, // 24,
{ UnicodeScript_kScriptCount, UnicodeScript_kScriptCount } // 88
};
sal_Char* SAL_CALL
InputSequenceCheckerImpl::getLanguageByScripType(sal_Unicode cChar, sal_Unicode nChar)
{
sal_Int16 type = unicode::getUnicodeScriptType( cChar, typeList, UnicodeScript_kScriptCount );
if (type != UnicodeScript_kScriptCount &&
type == unicode::getUnicodeScriptType( nChar, typeList, UnicodeScript_kScriptCount )) {
switch(type) {
case UnicodeScript_kThai: return "th";
//case UnicodeScript_kArabic: return "ar";
//case UnicodeScript_kHebrew: return "he";
//cace UnicodeScript_kDevanagari: return "hi";
}
}
return NULL;
}
Reference< XInputSequenceChecker >& SAL_CALL
InputSequenceCheckerImpl::getInputSequenceChecker(sal_Char* rLanguage) throw (RuntimeException)
{
if (cachedItem && cachedItem->aLanguage == rLanguage) {
return cachedItem->xISC;
}
else if (xMSF.is()) {
for (cachedItem = (lookupTableItem*)lookupTable.First();
cachedItem; cachedItem = (lookupTableItem*)lookupTable.Next()) {
if (cachedItem->aLanguage == rLanguage) {
return cachedItem->xISC;
}
}
Reference < uno::XInterface > xI = xMSF->createInstance(
OUString::createFromAscii("com.sun.star.i18n.InputSequenceChecker_") +
OUString::createFromAscii(rLanguage));
if ( xI.is() ) {
Reference< XInputSequenceChecker > xISC;
xI->queryInterface( getCppuType((const Reference< XInputSequenceChecker>*)0) ) >>= xISC;
if (xISC.is()) {
lookupTable.Insert(cachedItem = new lookupTableItem(rLanguage, xISC));
return cachedItem->xISC;
}
}
}
throw RuntimeException();
}
OUString SAL_CALL
InputSequenceCheckerImpl::getImplementationName(void) throw( RuntimeException )
{
return OUString::createFromAscii(serviceName);
}
sal_Bool SAL_CALL
InputSequenceCheckerImpl::supportsService(const OUString& rServiceName) throw( RuntimeException )
{
return !rServiceName.compareToAscii(serviceName);
}
Sequence< OUString > SAL_CALL
InputSequenceCheckerImpl::getSupportedServiceNames(void) throw( RuntimeException )
{
Sequence< OUString > aRet(1);
aRet[0] = OUString::createFromAscii(serviceName);
return aRet;
}
} } } }
/*************************************************************************
*
* $RCSfile: inputsequencechecker_th.cxx,v $
*
* $Revision: 1.1 $
*
* last change: $Author: bustamam $ $Date: 2002-03-26 12:54:35 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#include <inputsequencechecker_th.hxx>
#include <wtt.h>
using namespace rtl;
namespace com { namespace sun { namespace star { namespace i18n {
InputSequenceChecker_th::InputSequenceChecker_th()
{
serviceName = "com.sun.star.i18n.InputSequenceChecker_th";
}
InputSequenceChecker_th::~InputSequenceChecker_th()
{
}
/* Table for Thai Cell Manipulation */
sal_Char _TAC_celltype_inputcheck[17][17] = {
/* Cn */ /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F */
/* Cn-1 00 */ 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* 10 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* 20 */ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
/* 30 */ 'X', 'S', 'A', 'S', 'S', 'S', 'S', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* 40 */ 'X', 'S', 'A', 'S', 'A', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* 50 */ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* 60 */ 'X', 'A', 'A', 'A', 'S', 'A', 'S', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* 70 */ 'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R',
/* 80 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R',
/* 90 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* A0 */ 'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* B0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* C0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* D0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
/* E0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R',
/* F0 */ 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R',
'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'R', 'C', 'R', 'R', 'R', 'R'
};
sal_Bool _TAC_Composible[3][5] = {
/* 'A', 'C', 'S', 'R', 'X' */
/* Mode 0 */ {sal_True, sal_True, sal_True, sal_True, sal_True}, // PASSTHROUGH = 0
/* Mode 1 */ {sal_True, sal_True, sal_True, sal_False, sal_True}, // BASIC = 1
/* Mode 2 */ {sal_True, sal_True, sal_False, sal_False, sal_True} // STRICT = 2
};
sal_Bool SAL_CALL
InputSequenceChecker_th::checkInputSequence(const OUString& Text, sal_Int32 nStartPos,
sal_Unicode inputChar, sal_Int16 inputCheckMode) throw(com::sun::star::uno::RuntimeException)
{
sal_Int16 composible_class;
sal_Unicode currentChar = Text[nStartPos];
switch (_TAC_celltype_inputcheck[getCharType(currentChar)][getCharType(inputChar)]) {
case 'A': composible_class = 0; break;
case 'C': composible_class = 1; break;
case 'S': composible_class = 2; break;
case 'R': composible_class = 3; break;
case 'X': composible_class = 4; break;
default: composible_class = 0;
}
return (_TAC_Composible[inputCheckMode][composible_class]);
}
} } } }
#*************************************************************************
#*
#* $RCSfile: makefile.mk,v $
#*
#* $Revision: 1.1 $
#*
#* last change: $Author: bustamam $ $Date: 2002-03-26 12:54:35 $
#*
#* The Contents of this file are made available subject to the terms of
#* either of the following licenses
#*
#* - Sun Industry Standards Source License Version 1.1
#*
#* Sun Microsystems Inc., October, 2000
#*
#* Sun Industry Standards Source License Version 1.1
#* =================================================
#* The contents of this file are subject to the Sun Industry Standards
#* Source License Version 1.1 (the "License"); You may not use this file
#* except in compliance with the License. You may obtain a copy of the
#* License at http://www.openoffice.org/license.html.
#*
#* Software provided under this License is provided on an "AS IS" basis,
#* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
#* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
#* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
#* See the License for the specific provisions governing your rights and
#* obligations concerning the Software.
#*
#* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
#*
#* Copyright: 2000 by Sun Microsystems, Inc.
#*
#* All Rights Reserved.
#*
#* Contributor(s): _______________________________________
#*
#*
#************************************************************************/
PRJ=..$/..
PRJNAME=i18npool
TARGET=inputchecker
ENABLE_EXCEPTIONS=TRUE
# --- Settings -----------------------------------------------------
.INCLUDE : svpre.mk
.INCLUDE : settings.mk
.INCLUDE : sv.mk
# --- Files --------------------------------------------------------
SLOFILES= \
$(SLO)$/inputsequencechecker.obj \
$(SLO)$/inputsequencechecker_th.obj
# --- Targets ------------------------------------------------------
.INCLUDE : target.mk
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment