Kaydet (Commit) 900060a2 authored tarafından Rüdiger Timm's avatar Rüdiger Timm

INTEGRATION: CWS calc06 (1.2.42); FILE MERGED

2003/03/21 22:08:17 khong 1.2.42.1: #106680# Implementing new XExtendedTransliteration interface
üst a47035a4
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: transliteration_OneToOne.cxx,v $ * $RCSfile: transliteration_OneToOne.cxx,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: hr $ $Date: 2003-03-26 10:54:50 $ * last change: $Author: rt $ $Date: 2003-04-08 16:07:19 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include <transliteration_OneToOne.hxx> #include <transliteration_OneToOne.hxx>
using namespace drafts::com::sun::star::i18n;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace rtl; using namespace rtl;
...@@ -71,103 +72,67 @@ namespace com { namespace sun { namespace star { namespace i18n { ...@@ -71,103 +72,67 @@ namespace com { namespace sun { namespace star { namespace i18n {
sal_Int16 SAL_CALL transliteration_OneToOne::getType() throw(RuntimeException) sal_Int16 SAL_CALL transliteration_OneToOne::getType() throw(RuntimeException)
{ {
// This type is also defined in com/sun/star/util/TransliterationType.hdl // This type is also defined in com/sun/star/util/TransliterationType.hdl
return TransliterationType::ONE_TO_ONE; return TransliterationType::ONE_TO_ONE;
} }
OUString SAL_CALL OUString SAL_CALL
transliteration_OneToOne::folding( const OUString& inStr, sal_Int32 startPos, transliteration_OneToOne::folding( const OUString& inStr, sal_Int32 startPos,
sal_Int32 nCount, Sequence< sal_Int32 >& offset) throw(RuntimeException) sal_Int32 nCount, Sequence< sal_Int32 >& offset) throw(RuntimeException)
{ {
throw RuntimeException(); throw RuntimeException();
} }
sal_Bool SAL_CALL sal_Bool SAL_CALL
transliteration_OneToOne::equals( const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, transliteration_OneToOne::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 ) sal_Int32& nMatch1, const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2 )
throw(RuntimeException) throw(RuntimeException)
{ {
throw RuntimeException(); throw RuntimeException();
} }
Sequence< OUString > SAL_CALL Sequence< OUString > SAL_CALL
transliteration_OneToOne::transliterateRange( const OUString& str1, const OUString& str2 ) transliteration_OneToOne::transliterateRange( const OUString& str1, const OUString& str2 )
throw(RuntimeException) throw(RuntimeException)
{ {
throw RuntimeException(); throw RuntimeException();
} }
OUString SAL_CALL OUString SAL_CALL
transliteration_OneToOne::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, oneToOneMapping& table ) transliteration_OneToOne::transliterate( const OUString& inStr, sal_Int32 startPos,
throw(RuntimeException) sal_Int32 nCount, Sequence< sal_Int32 >& offset)
{ throw(RuntimeException)
// Create a string buffer which can hold nCount + 1 characters.
// The reference count is 0 now.
rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h
sal_Unicode * dst = newStr->buffer;
const sal_Unicode * src = inStr.getStr() + startPos;
// Translation
while (nCount -- > 0) {
sal_Unicode c = *src++;
*dst ++ = table[ c ];
}
*dst = (sal_Unicode) 0;
return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
}
OUString SAL_CALL
transliteration_OneToOne::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset, oneToOneMapping& table )
throw(RuntimeException)
{ {
// Create a string buffer which can hold nCount + 1 characters. // Create a string buffer which can hold nCount + 1 characters.
// The reference count is 0 now. // The reference count is 0 now.
rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h
sal_Unicode * dst = newStr->buffer; sal_Unicode * dst = newStr->buffer;
const sal_Unicode * src = inStr.getStr() + startPos; const sal_Unicode * src = inStr.getStr() + startPos;
// Allocate nCount length to offset argument. // Allocate nCount length to offset argument.
offset.realloc( nCount ); sal_Int32 *p, position;
sal_Int32 *p = offset.getArray(); if (useOffset) {
sal_Int32 position = startPos; offset.realloc( nCount );
p = offset.getArray();
// Translation position = startPos;
while (nCount -- > 0) { }
// Translation
while (nCount -- > 0) {
sal_Unicode c = *src++; sal_Unicode c = *src++;
*dst ++ = table[ c ]; *dst ++ = func ? func( c) : (*table)[ c ];
*p ++ = position ++; if (useOffset)
} *p ++ = position ++;
*dst = (sal_Unicode) 0; }
*dst = (sal_Unicode) 0;
return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1. return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
} }
OUString SAL_CALL sal_Unicode SAL_CALL
transliteration_OneToOne::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset, TransFunc func ) transliteration_OneToOne::transliterateChar2Char( sal_Unicode inChar) throw(RuntimeException, MultipleCharsOutputException)
throw(RuntimeException)
{ {
// Create a string buffer which can hold nCount + 1 characters. return func ? func( inChar) : (*table)[ inChar ];
// The reference count is 0 now.
rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h
sal_Unicode * dst = newStr->buffer;
const sal_Unicode * src = inStr.getStr() + startPos;
// Allocate nCount length to offset argument.
offset.realloc( nCount );
sal_Int32 *p = offset.getArray();
sal_Int32 position = startPos;
// Translation
while (nCount -- > 0) {
sal_Unicode c = *src++;
*dst ++ = func( c );
*p ++ = position ++;
}
*dst = (sal_Unicode) 0;
return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
} }
} } } } } } } }
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: transliteration_caseignore.cxx,v $ * $RCSfile: transliteration_caseignore.cxx,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: hr $ $Date: 2003-03-26 10:54:50 $ * last change: $Author: rt $ $Date: 2003-04-08 16:07:40 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include "oneToOneMapping.hxx" #include "oneToOneMapping.hxx"
#include "transliteration_caseignore.hxx" #include "transliteration_caseignore.hxx"
#include "casefolding.hxx"
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang; using namespace ::com::sun::star::lang;
...@@ -71,12 +72,9 @@ using namespace ::rtl; ...@@ -71,12 +72,9 @@ using namespace ::rtl;
namespace com { namespace sun { namespace star { namespace i18n { namespace com { namespace sun { namespace star { namespace i18n {
oneToOneMapping& gethalf2fullTable(void);
sal_Unicode getCompositionChar(sal_Unicode c1, sal_Unicode c2);
Transliteration_caseignore::Transliteration_caseignore() Transliteration_caseignore::Transliteration_caseignore()
{ {
aMappingType = MappingTypeFullFolding; nMappingType = MappingTypeFullFolding;
moduleLoaded = (TransliterationModules)0; moduleLoaded = (TransliterationModules)0;
transliterationName = "case ignore (generic)"; transliterationName = "case ignore (generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore"; implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
...@@ -84,7 +82,7 @@ Transliteration_caseignore::Transliteration_caseignore() ...@@ -84,7 +82,7 @@ Transliteration_caseignore::Transliteration_caseignore()
Transliteration_simplecaseignore::Transliteration_simplecaseignore() Transliteration_simplecaseignore::Transliteration_simplecaseignore()
{ {
aMappingType = MappingTypeSimpleFolding; nMappingType = MappingTypeSimpleFolding;
moduleLoaded = (TransliterationModules)0; moduleLoaded = (TransliterationModules)0;
transliterationName = "simple case ignore (generic)"; transliterationName = "simple case ignore (generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_simplecaseignore"; implementationName = "com.sun.star.i18n.Transliteration.Transliteration_simplecaseignore";
...@@ -118,12 +116,10 @@ Transliteration_caseignore::transliterateRange( const OUString& str1, const OUSt ...@@ -118,12 +116,10 @@ Transliteration_caseignore::transliterateRange( const OUString& str1, const OUSt
u2l.loadModule((TransliterationModules)0, aLocale); u2l.loadModule((TransliterationModules)0, aLocale);
l2u.loadModule((TransliterationModules)0, aLocale); l2u.loadModule((TransliterationModules)0, aLocale);
Sequence< sal_Int32 > offset; OUString l1 = u2l.transliterateString2String(str1, 0, str1.getLength());
OUString u1 = l2u.transliterateString2String(str1, 0, str1.getLength());
OUString l1 = u2l.transliterate(str1, 0, str1.getLength(), offset); OUString l2 = u2l.transliterateString2String(str2, 0, str2.getLength());
OUString u1 = l2u.transliterate(str1, 0, str1.getLength(), offset); OUString u2 = l2u.transliterateString2String(str2, 0, str2.getLength());
OUString l2 = u2l.transliterate(str2, 0, str2.getLength(), offset);
OUString u2 = l2u.transliterate(str2, 0, str2.getLength(), offset);
if ((l1 == u1) && (l2 == u2)) { if ((l1 == u1) && (l2 == u2)) {
Sequence< OUString > &r = *new Sequence< OUString > (2); Sequence< OUString > &r = *new Sequence< OUString > (2);
...@@ -170,48 +166,6 @@ Transliteration_caseignore::compareString( ...@@ -170,48 +166,6 @@ Transliteration_caseignore::compareString(
return compare(str1, 0, str1.getLength(), nMatch1, str2, 0, str2.getLength(), nMatch2); return compare(str1, 0, str1.getLength(), nMatch1, str2, 0, str2.getLength(), nMatch2);
} }
inline sal_Bool SAL_CALL
is_ja_voice_sound_mark(sal_Unicode& current, sal_Unicode next)
{
sal_Unicode c = 0;
if ((next == 0x3099 || next == 0x309a) && (c = getCompositionChar(current, next)))
current = c;
return c != 0;
}
sal_Unicode SAL_CALL
Transliteration_caseignore::getNextChar(const sal_Unicode *str, sal_Int32& idx, sal_Int32 len, MappingElement& e)
throw(RuntimeException)
{
sal_Unicode c;
if (moduleLoaded & TransliterationModules_IGNORE_CASE) {
if (e.current >= e.element.nmap && idx < len ) {
e.element = getValue(str, idx++, len);
e.current = 0;
}
c = e.element.map[e.current++];
} else {
c = *(str + idx++);
}
if (moduleLoaded & TransliterationModules_IGNORE_KANA) {
if (0x3040 <= c && c <= 0x3094 || 0x309d <= c && c <= 0x309f)
c += 0x60;
}
// composition: KA + voice-mark --> GA. see halfwidthToFullwidth.cxx for detail
if (moduleLoaded & TransliterationModules_IGNORE_WIDTH) {
static oneToOneMapping& half2fullTable = gethalf2fullTable();
c = half2fullTable[c];
if (0x3040 <= c && c <= 0x30ff && idx < len &&
is_ja_voice_sound_mark(c, half2fullTable[*(str + idx)]))
idx++;
}
return c;
}
sal_Int32 SAL_CALL sal_Int32 SAL_CALL
Transliteration_caseignore::compare( Transliteration_caseignore::compare(
const ::rtl::OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1, const ::rtl::OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
...@@ -228,8 +182,8 @@ Transliteration_caseignore::compare( ...@@ -228,8 +182,8 @@ Transliteration_caseignore::compare(
#define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap) #define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
while (NOT_END_OF_STR1 && NOT_END_OF_STR2) { while (NOT_END_OF_STR1 && NOT_END_OF_STR2) {
c1 = getNextChar(unistr1, nMatch1, nCount1, e1); c1 = casefolding::getNextChar(unistr1, nMatch1, nCount1, e1, aLocale, nMappingType, moduleLoaded);
c2 = getNextChar(unistr2, nMatch2, nCount2, e2); c2 = casefolding::getNextChar(unistr2, nMatch2, nCount2, e2, aLocale, nMappingType, moduleLoaded);
if (c1 != c2) { if (c1 != c2) {
nMatch1--; nMatch2--; nMatch1--; nMatch2--;
return c1 > c2 ? 1 : -1; return c1 > c2 ? 1 : -1;
......
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