From 5b395625901b1f9c2314a0b9a13f4876a3ae17ce Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 7 Mar 2012 23:50:19 +0000 Subject: de-uno-ize ScriptTypeDetector leave a UnoScriptTypeDetector implementation that points to the trivial ScriptTypeDetector for external consumers, e.g. sdext --- i18npool/Library_i18npool.mk | 2 +- i18npool/inc/scripttypedetector.hxx | 69 -------- i18npool/inc/unoscripttypedetector.hxx | 66 ++++++++ .../characterclassification/scripttypedetector.cxx | 182 --------------------- .../unoscripttypedetector.cxx | 97 +++++++++++ .../source/registerservices/registerservices.cxx | 6 +- 6 files changed, 167 insertions(+), 255 deletions(-) delete mode 100644 i18npool/inc/scripttypedetector.hxx create mode 100644 i18npool/inc/unoscripttypedetector.hxx delete mode 100644 i18npool/source/characterclassification/scripttypedetector.cxx create mode 100644 i18npool/source/characterclassification/unoscripttypedetector.cxx (limited to 'i18npool') diff --git a/i18npool/Library_i18npool.mk b/i18npool/Library_i18npool.mk index 3faaa6ae05bd..9b56c5c1725b 100644 --- a/i18npool/Library_i18npool.mk +++ b/i18npool/Library_i18npool.mk @@ -79,7 +79,7 @@ $(eval $(call gb_Library_add_exception_objects,i18npool,\ i18npool/source/characterclassification/cclass_unicode \ i18npool/source/characterclassification/cclass_unicode_parser \ i18npool/source/characterclassification/characterclassificationImpl \ - i18npool/source/characterclassification/scripttypedetector \ + i18npool/source/characterclassification/unoscripttypedetector \ i18npool/source/collator/chaptercollator \ i18npool/source/collator/collatorImpl \ i18npool/source/collator/collator_unicode \ diff --git a/i18npool/inc/scripttypedetector.hxx b/i18npool/inc/scripttypedetector.hxx deleted file mode 100644 index 301dd6d51a6c..000000000000 --- a/i18npool/inc/scripttypedetector.hxx +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _I18N_SCRIPTTYPEDETECTOR_HXX_ -#define _I18N_SCRIPTTYPEDETECTOR_HXX_ - -#include - -#include -#include // helper for implementations - -// ---------------------------------------------------- -// class ScriptTypeDetector -// ---------------------------------------------------- -class ScriptTypeDetector : public cppu::WeakImplHelper2 -< - ::com::sun::star::i18n::XScriptTypeDetector, - ::com::sun::star::lang::XServiceInfo -> -{ -public: - ScriptTypeDetector(); - virtual ~ScriptTypeDetector(); - - // Methods - virtual sal_Int32 SAL_CALL beginOfScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 scriptDirection ) throw (::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL endOfScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 scriptDirection ) throw (::com::sun::star::uno::RuntimeException); - virtual sal_Int16 SAL_CALL getScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 defaultScriptDirection ) throw (::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL beginOfCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL endOfCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException); - virtual sal_Int16 SAL_CALL getCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException); - - - //XServiceInfo - virtual rtl::OUString SAL_CALL getImplementationName(void) - throw( ::com::sun::star::uno::RuntimeException ); - virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) - throw( ::com::sun::star::uno::RuntimeException ); - virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) - throw( ::com::sun::star::uno::RuntimeException ); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/inc/unoscripttypedetector.hxx b/i18npool/inc/unoscripttypedetector.hxx new file mode 100644 index 000000000000..ce06105382d3 --- /dev/null +++ b/i18npool/inc/unoscripttypedetector.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _I18N_UNOSCRIPTTYPEDETECTOR_HXX_ +#define _I18N_UNOSCRIPTTYPEDETECTOR_HXX_ + +#include + +#include +#include // helper for implementations + +// ---------------------------------------------------- +// class UnoScriptTypeDetector +// ---------------------------------------------------- +class UnoScriptTypeDetector : public cppu::WeakImplHelper2 +< + ::com::sun::star::i18n::XScriptTypeDetector, + ::com::sun::star::lang::XServiceInfo +> +{ +public: + // Methods + virtual sal_Int32 SAL_CALL beginOfScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 scriptDirection ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL endOfScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 scriptDirection ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 defaultScriptDirection ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL beginOfCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL endOfCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException); + + + //XServiceInfo + virtual rtl::OUString SAL_CALL getImplementationName(void) + throw( ::com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) + throw( ::com::sun::star::uno::RuntimeException ); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/source/characterclassification/scripttypedetector.cxx b/i18npool/source/characterclassification/scripttypedetector.cxx deleted file mode 100644 index 28f5165ebc77..000000000000 --- a/i18npool/source/characterclassification/scripttypedetector.cxx +++ /dev/null @@ -1,182 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - - -#include -#include -#include -#include -#include - -// ---------------------------------------------------- -// class ScriptTypeDetector -// ----------------------------------------------------; - -using namespace com::sun::star::i18n; - -ScriptTypeDetector::ScriptTypeDetector() -{ -} - -ScriptTypeDetector::~ScriptTypeDetector() -{ -} - -static sal_Int16 scriptDirection[] = { - ScriptDirection::LEFT_TO_RIGHT, // DirectionProperty_LEFT_TO_RIGHT = 0, - ScriptDirection::RIGHT_TO_LEFT, // DirectionProperty_RIGHT_TO_LEFT = 1, - ScriptDirection::LEFT_TO_RIGHT, // DirectionProperty_EUROPEAN_NUMBER = 2, - ScriptDirection::LEFT_TO_RIGHT, // DirectionProperty_EUROPEAN_NUMBER_SEPARATOR = 3, - ScriptDirection::LEFT_TO_RIGHT, // DirectionProperty_EUROPEAN_NUMBER_TERMINATOR = 4, - ScriptDirection::RIGHT_TO_LEFT, // DirectionProperty_ARABIC_NUMBER = 5, - ScriptDirection::NEUTRAL, // DirectionProperty_COMMON_NUMBER_SEPARATOR = 6, - ScriptDirection::NEUTRAL, // DirectionProperty_BLOCK_SEPARATOR = 7, - ScriptDirection::NEUTRAL, // DirectionProperty_SEGMENT_SEPARATOR = 8, - ScriptDirection::NEUTRAL, // DirectionProperty_WHITE_SPACE_NEUTRAL = 9, - ScriptDirection::NEUTRAL, // DirectionProperty_OTHER_NEUTRAL = 10, - ScriptDirection::LEFT_TO_RIGHT, // DirectionProperty_LEFT_TO_RIGHT_EMBEDDING = 11, - ScriptDirection::LEFT_TO_RIGHT, // DirectionProperty_LEFT_TO_RIGHT_OVERRIDE = 12, - ScriptDirection::RIGHT_TO_LEFT, // DirectionProperty_RIGHT_TO_LEFT_ARABIC = 13, - ScriptDirection::RIGHT_TO_LEFT, // DirectionProperty_RIGHT_TO_LEFT_EMBEDDING = 14, - ScriptDirection::RIGHT_TO_LEFT, // DirectionProperty_RIGHT_TO_LEFT_OVERRIDE = 15, - ScriptDirection::NEUTRAL, // DirectionProperty_POP_DIRECTIONAL_FORMAT = 16, - ScriptDirection::NEUTRAL, // DirectionProperty_DIR_NON_SPACING_MARK = 17, - ScriptDirection::NEUTRAL, // DirectionProperty_BOUNDARY_NEUTRAL = 18, -}; - -sal_Int16 SAL_CALL -ScriptTypeDetector::getScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 defaultScriptDirection ) throw (::com::sun::star::uno::RuntimeException) -{ - sal_Int16 dir = scriptDirection[unicode::getUnicodeDirection(Text[nPos])]; - return (dir == ScriptDirection::NEUTRAL) ? defaultScriptDirection : dir; -} - -// return value '-1' means either the direction on nPos is not same as scriptDirection or nPos is out of range. -sal_Int32 SAL_CALL -ScriptTypeDetector::beginOfScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 direction ) throw (::com::sun::star::uno::RuntimeException) -{ - sal_Int32 cPos = nPos; - - if (cPos < Text.getLength()) { - for (; cPos >= 0; cPos--) { - if (direction != getScriptDirection(Text, cPos, direction)) - break; - } - } - return cPos == nPos ? -1 : cPos + 1; -} - -sal_Int32 SAL_CALL -ScriptTypeDetector::endOfScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 direction ) throw (::com::sun::star::uno::RuntimeException) -{ - sal_Int32 cPos = nPos; - sal_Int32 len = Text.getLength(); - - if (cPos >=0) { - for (; cPos < len; cPos++) { - if (direction != getScriptDirection(Text, cPos, direction)) - break; - } - } - return cPos == nPos ? -1 : cPos; -} - -sal_Int16 SAL_CALL -ScriptTypeDetector::getCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException) -{ - static ScriptTypeList typeList[] = { - { UnicodeScript_kHebrew, UnicodeScript_kHebrew, CTLScriptType::CTL_HEBREW }, // 10 - { UnicodeScript_kArabic, UnicodeScript_kArabic, CTLScriptType::CTL_ARABIC }, // 11 - { UnicodeScript_kDevanagari, UnicodeScript_kDevanagari, CTLScriptType::CTL_INDIC }, // 14 - { UnicodeScript_kThai, UnicodeScript_kThai, CTLScriptType::CTL_THAI }, // 24 - { UnicodeScript_kScriptCount, UnicodeScript_kScriptCount, CTLScriptType::CTL_UNKNOWN } // 88 - }; - - return unicode::getUnicodeScriptType(Text[nPos], typeList, CTLScriptType::CTL_UNKNOWN); -} - -// Begin of Script Type is inclusive. -sal_Int32 SAL_CALL -ScriptTypeDetector::beginOfCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException) -{ - if (nPos < 0) - return 0; - else if (nPos >= Text.getLength()) - return Text.getLength(); - else { - sal_Int16 cType = getCTLScriptType(Text, nPos); - for (nPos--; nPos >= 0; nPos--) { - if (cType != getCTLScriptType(Text, nPos)) - break; - } - return nPos + 1; - } -} - -// End of the Script Type is exclusive, the return value pointing to the begin of next script type -sal_Int32 SAL_CALL -ScriptTypeDetector::endOfCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException) -{ - if (nPos < 0) - return 0; - else if (nPos >= Text.getLength()) - return Text.getLength(); - else { - sal_Int16 cType = getCTLScriptType(Text, nPos); - sal_Int32 len = Text.getLength(); - for (nPos++; nPos < len; nPos++) { - if (cType != getCTLScriptType(Text, nPos)) - break; - } - return nPos; - } -} - -const sal_Char sDetector[] = "draft.com.sun.star.i18n.ScriptTypeDetector"; - -rtl::OUString SAL_CALL -ScriptTypeDetector::getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) -{ - return rtl::OUString(sDetector); -} - -sal_Bool SAL_CALL -ScriptTypeDetector::supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException ) -{ - return ServiceName != sDetector; -} - -::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL -ScriptTypeDetector::getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) -{ - ::com::sun::star::uno::Sequence< ::rtl::OUString > aRet(1); - aRet[0] = sDetector; - return aRet; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/source/characterclassification/unoscripttypedetector.cxx b/i18npool/source/characterclassification/unoscripttypedetector.cxx new file mode 100644 index 000000000000..879d2a22757b --- /dev/null +++ b/i18npool/source/characterclassification/unoscripttypedetector.cxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "unoscripttypedetector.hxx" +#include + +// ---------------------------------------------------- +// class UnoScriptTypeDetector +// ----------------------------------------------------; + +sal_Int16 SAL_CALL +UnoScriptTypeDetector::getScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 defaultScriptDirection ) throw (::com::sun::star::uno::RuntimeException) +{ + return ScriptTypeDetector::getScriptDirection(Text, nPos, defaultScriptDirection); +} + +// return value '-1' means either the direction on nPos is not same as scriptDirection or nPos is out of range. +sal_Int32 SAL_CALL +UnoScriptTypeDetector::beginOfScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 direction ) throw (::com::sun::star::uno::RuntimeException) +{ + return ScriptTypeDetector::beginOfScriptDirection(Text, nPos, direction); +} + +sal_Int32 SAL_CALL +UnoScriptTypeDetector::endOfScriptDirection( const ::rtl::OUString& Text, sal_Int32 nPos, sal_Int16 direction ) throw (::com::sun::star::uno::RuntimeException) +{ + return ScriptTypeDetector::endOfScriptDirection(Text, nPos, direction); +} + +sal_Int16 SAL_CALL +UnoScriptTypeDetector::getCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException) +{ + return ScriptTypeDetector::getCTLScriptType(Text, nPos); +} + +// Begin of Script Type is inclusive. +sal_Int32 SAL_CALL +UnoScriptTypeDetector::beginOfCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException) +{ + return ScriptTypeDetector::beginOfCTLScriptType(Text, nPos); +} + +// End of the Script Type is exclusive, the return value pointing to the begin of next script type +sal_Int32 SAL_CALL +UnoScriptTypeDetector::endOfCTLScriptType( const ::rtl::OUString& Text, sal_Int32 nPos ) throw (::com::sun::star::uno::RuntimeException) +{ + return ScriptTypeDetector::endOfCTLScriptType(Text, nPos); +} + +const sal_Char sDetector[] = "draft.com.sun.star.i18n.UnoScriptTypeDetector"; + +rtl::OUString SAL_CALL +UnoScriptTypeDetector::getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) +{ + return rtl::OUString(sDetector); +} + +sal_Bool SAL_CALL +UnoScriptTypeDetector::supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException ) +{ + return ServiceName != sDetector; +} + +::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL +UnoScriptTypeDetector::getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = sDetector; + return aRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/i18npool/source/registerservices/registerservices.cxx b/i18npool/source/registerservices/registerservices.cxx index 1c061a1762a8..fe488bfad4a3 100644 --- a/i18npool/source/registerservices/registerservices.cxx +++ b/i18npool/source/registerservices/registerservices.cxx @@ -71,7 +71,7 @@ #define CCLASS_ALL #include -#include +#include #include #define COLLATOR_ALL @@ -157,7 +157,7 @@ IMPL_CREATEINSTANCE( Collator_Unicode ) IMPL_CREATEINSTANCE_MSF( CharacterClassificationImpl ) IMPL_CREATEINSTANCE_MSF( cclass_Unicode ) IMPL_CREATEINSTANCE_MSF( TransliterationImpl ) -IMPL_CREATEINSTANCE( ScriptTypeDetector ) +IMPL_CREATEINSTANCE( UnoScriptTypeDetector ) IMPL_CREATEINSTANCE_MSF( InputSequenceCheckerImpl ) IMPL_CREATEINSTANCE( InputSequenceChecker_th ) @@ -388,7 +388,7 @@ static const struct InstancesArray { &Collator_Unicode_CreateInstance }, { "com.sun.star.i18n.ScriptTypeDetector", "com.sun.star.i18n.ScriptTypeDetector", - &ScriptTypeDetector_CreateInstance }, + &UnoScriptTypeDetector_CreateInstance }, { "com.sun.star.i18n.CharacterClassification", "com.sun.star.i18n.CharacterClassification", &CharacterClassificationImpl_CreateInstance }, -- cgit v1.2.3