summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorThomas Lange <tl@openoffice.org>2009-07-13 11:08:01 +0000
committerThomas Lange <tl@openoffice.org>2009-07-13 11:08:01 +0000
commitf74002df591f62452ef9181068cda76e355f75e7 (patch)
tree176852193b26e06b6a6ad5f5c9b642c970a382e4 /i18npool
parent8be7ea6f79a756936ab4a38d6086740dd00338c9 (diff)
#i1601# sentence case transliteration
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/transliteration_sentencecase.hxx69
-rw-r--r--i18npool/source/localedata/data/en_US.xml1
-rw-r--r--i18npool/source/registerservices/registerservices.cxx5
-rw-r--r--i18npool/source/transliteration/makefile.mk3
-rw-r--r--i18npool/source/transliteration/transliteration_sentencecase.cxx190
5 files changed, 267 insertions, 1 deletions
diff --git a/i18npool/inc/transliteration_sentencecase.hxx b/i18npool/inc/transliteration_sentencecase.hxx
new file mode 100644
index 000000000000..11318f5cc963
--- /dev/null
+++ b/i18npool/inc/transliteration_sentencecase.hxx
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: transliteration_Numeric.hxx,v $
+ * $Revision: 1.6 $
+ *
+ * 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
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef _I18NPPOL_TRANSLITERATION_SENTENCECASE_HXX_
+#define _I18NPPOL_TRANSLITERATION_SENTENCECASE_HXX_
+
+#include <transliteration_commonclass.hxx>
+
+namespace com { namespace sun { namespace star { namespace i18n {
+
+class Transliteration_sentencecase : public transliteration_commonclass {
+public:
+ Transliteration_sentencecase( );
+
+ ::rtl::OUString SAL_CALL
+ transliterate( const ::rtl::OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, ::com::sun::star::uno::Sequence< sal_Int32 >& offset )
+ throw(::com::sun::star::uno::RuntimeException);
+
+ sal_Unicode SAL_CALL
+ transliterateChar2Char( sal_Unicode inChar)
+ throw(com::sun::star::i18n::MultipleCharsOutputException,
+ com::sun::star::uno::RuntimeException);
+
+ // Methods which are shared.
+ sal_Int16 SAL_CALL getType( ) throw(::com::sun::star::uno::RuntimeException);
+
+ ::rtl::OUString SAL_CALL
+ folding( const ::rtl::OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, ::com::sun::star::uno::Sequence< sal_Int32 >& offset )
+ throw(::com::sun::star::uno::RuntimeException);
+
+ sal_Bool SAL_CALL
+ equals( const ::rtl::OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1, const ::rtl::OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2 )
+ throw(::com::sun::star::uno::RuntimeException);
+
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
+ transliterateRange( const ::rtl::OUString& str1, const ::rtl::OUString& str2 )
+ throw(::com::sun::star::uno::RuntimeException);
+};
+
+} } } }
+
+#endif // _I18NPPOL_TRANSLITERATION_SENTENCECASE_HXX_
+
diff --git a/i18npool/source/localedata/data/en_US.xml b/i18npool/source/localedata/data/en_US.xml
index 2a99dcd0fb14..57cc189e6c91 100644
--- a/i18npool/source/localedata/data/en_US.xml
+++ b/i18npool/source/localedata/data/en_US.xml
@@ -477,6 +477,7 @@
<LC_TRANSLITERATION>
<Transliteration unoid="LOWERCASE_UPPERCASE"/>
<Transliteration unoid="UPPERCASE_LOWERCASE"/>
+ <Transliteration unoid="SENTENCE_CASE"/>
<Transliteration unoid="IGNORE_CASE"/>
</LC_TRANSLITERATION>
<LC_MISC>
diff --git a/i18npool/source/registerservices/registerservices.cxx b/i18npool/source/registerservices/registerservices.cxx
index 870c49939648..280d6d0aaecf 100644
--- a/i18npool/source/registerservices/registerservices.cxx
+++ b/i18npool/source/registerservices/registerservices.cxx
@@ -50,6 +50,7 @@
#include <transliteration_caseignore.hxx>
#include <transliteration_Ignore.hxx>
#include <transliteration_OneToOne.hxx>
+#include <transliteration_sentencecase.hxx>
#include <textToPronounce_zh.hxx>
#include <numtotext_cjk.hxx>
#include <numtochar.hxx>
@@ -173,6 +174,7 @@ IMPL_CREATEINSTANCE_MSF( TextConversion_zh )
IMPL_CREATEINSTANCE( Transliteration_u2l )
IMPL_CREATEINSTANCE( Transliteration_l2u )
+IMPL_CREATEINSTANCE( Transliteration_sentencecase )
IMPL_CREATEINSTANCE( Transliteration_caseignore )
IMPL_CREATEINSTANCE( hiraganaToKatakana )
IMPL_CREATEINSTANCE( katakanaToHiragana )
@@ -423,6 +425,9 @@ static const struct InstancesArray {
TRLT_IMPLNAME_PREFIX "LOWERCASE_UPPERCASE",
&Transliteration_l2u_CreateInstance },
{ TRLT_SERVICELNAME_L10N,
+ TRLT_IMPLNAME_PREFIX "SENTENCE_CASE",
+ &Transliteration_sentencecase_CreateInstance },
+ { TRLT_SERVICELNAME_L10N,
TRLT_IMPLNAME_PREFIX "IGNORE_CASE",
&Transliteration_caseignore_CreateInstance },
{ TRLT_SERVICELNAME_L10N,
diff --git a/i18npool/source/transliteration/makefile.mk b/i18npool/source/transliteration/makefile.mk
index daf3068d4d20..83317183beff 100644
--- a/i18npool/source/transliteration/makefile.mk
+++ b/i18npool/source/transliteration/makefile.mk
@@ -78,7 +78,8 @@ SLOFILES= \
$(SLO)$/numtochar.obj \
$(SLO)$/numtotext_cjk.obj \
$(SLO)$/chartonum.obj \
- $(SLO)$/texttonum.obj
+ $(SLO)$/texttonum.obj \
+ $(SLO)$/transliteration_sentencecase.obj
# --- Targets ------------------------------------------------------
diff --git a/i18npool/source/transliteration/transliteration_sentencecase.cxx b/i18npool/source/transliteration/transliteration_sentencecase.cxx
new file mode 100644
index 000000000000..35f9a69abb4d
--- /dev/null
+++ b/i18npool/source/transliteration/transliteration_sentencecase.cxx
@@ -0,0 +1,190 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: halfwidthToFullwidth.cxx,v $
+ * $Revision: 1.12 $
+ *
+ * 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
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_i18npool.hxx"
+
+// prevent internal compiler error with MSVC6SP3
+#include <utility>
+
+#include <i18nutil/widthfolding.hxx>
+#include <i18nutil/casefolding.hxx>
+#define TRANSLITERATION_sentencecase
+#include <transliteration_sentencecase.hxx>
+#include <rtl/ustring.hxx>
+#include <i18nutil/x_rtl_ustring.h>
+#include <i18nutil/unicode.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <rtl/strbuf.hxx>
+
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace rtl;
+
+namespace com { namespace sun { namespace star { namespace i18n {
+
+
+Transliteration_sentencecase::Transliteration_sentencecase()
+{
+ transliterationName = "sentenceCase";
+ implementationName = "com.sun.star.i18n.Transliteration.SENTENCE_CASE";
+}
+
+OUString SAL_CALL
+Transliteration_sentencecase::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset )
+ throw(RuntimeException)
+{
+ // inspired from Transliteration_body::transliterate
+ sal_Int32 nOffCount = 0, i;
+ bool bPoint = true;
+ if (useOffset)
+ {
+ for( i = 0; i < nCount; ++i ) {
+ sal_Unicode c = inStr.getStr()[ i + startPos ];
+ if( sal_Unicode('.') == c || sal_Unicode('!') == c || sal_Unicode('?') == c ) {
+ bPoint = true;
+ nOffCount++;
+ }
+ else if( unicode::isAlpha( c ) || unicode::isDigit( c ) )
+ {
+ const Mapping* map = 0;
+ if( bPoint && unicode::isLower( c ))
+ {
+ map = &casefolding::getValue(&c, 0, 1, aLocale, MappingTypeLowerToUpper);
+ }
+ bPoint = false;
+
+ if(map == 0)
+ {
+ nOffCount++;
+ }
+ else
+ {
+ nOffCount += map->nmap;
+ }
+ }
+ else
+ {
+ nOffCount++;
+ }
+ }
+ }
+
+ bPoint = true;
+ rtl::OUStringBuffer result;
+
+ if (useOffset)
+ {
+ result.ensureCapacity(nOffCount);
+ if ( nOffCount != offset.getLength() )
+ offset.realloc( nOffCount );
+ }
+
+
+ sal_Int32 j = 0;
+ sal_Int32 * pArr = offset.getArray();
+ for( i = 0; i < nCount; ++i ) {
+ sal_Unicode c = inStr.getStr()[ i + startPos ];
+ if( sal_Unicode('.') == c || sal_Unicode('!') == c || sal_Unicode('?') == c ) {
+ bPoint = true;
+ result.append(c);
+ pArr[j++] = i + startPos;
+ }
+ else if( unicode::isAlpha( c ) || unicode::isDigit( c ) )
+ {
+ const Mapping* map = 0;
+ if( bPoint && unicode::isLower( c ))
+ {
+ map = &casefolding::getValue(&c, 0, 1, aLocale, MappingTypeLowerToUpper);
+ }
+ bPoint = false;
+
+ if(map == 0)
+ {
+ result.append( c );
+ pArr[j++] = i + startPos;
+ }
+ else
+ {
+ for (sal_Int32 k = 0; k < map->nmap; k++)
+ {
+ result.append( map->map[k] );
+ pArr[j++] = i + startPos;
+ }
+ }
+ }
+ else
+ {
+ result.append( c );
+ pArr[j++] = i + startPos;
+ }
+ }
+ return result.makeStringAndClear();
+}
+
+sal_Unicode SAL_CALL
+Transliteration_sentencecase::transliterateChar2Char( sal_Unicode inChar)
+ throw(RuntimeException, MultipleCharsOutputException)
+{
+ return inChar;
+}
+
+sal_Int16 SAL_CALL Transliteration_sentencecase::getType() throw(RuntimeException)
+{
+ return TransliterationType::IGNORE;
+}
+
+OUString SAL_CALL
+Transliteration_sentencecase::folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
+ Sequence< sal_Int32 >& offset) throw(RuntimeException)
+{
+ return this->transliterate(inStr, startPos, nCount, offset);
+}
+
+sal_Bool SAL_CALL Transliteration_sentencecase::equals(
+ const OUString& /*str1*/, sal_Int32 /*pos1*/, sal_Int32 /*nCount1*/, sal_Int32& /*nMatch1*/,
+ const OUString& /*str2*/, sal_Int32 /*pos2*/, sal_Int32 /*nCount2*/, sal_Int32& /*nMatch2*/)
+ throw(RuntimeException)
+{
+ throw RuntimeException();
+}
+
+Sequence< OUString > SAL_CALL
+Transliteration_sentencecase::transliterateRange( const OUString& str1, const OUString& str2 )
+ throw( RuntimeException)
+{
+ Sequence< OUString > ostr(2);
+ ostr[0] = str1;
+ ostr[1] = str2;
+ return ostr;
+}
+
+} } } }
+