summaryrefslogtreecommitdiff
path: root/i18npool/source/breakiterator/xdictionary.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'i18npool/source/breakiterator/xdictionary.cxx')
-rw-r--r--i18npool/source/breakiterator/xdictionary.cxx160
1 files changed, 65 insertions, 95 deletions
diff --git a/i18npool/source/breakiterator/xdictionary.cxx b/i18npool/source/breakiterator/xdictionary.cxx
index aba69b5e9a21..0bff3d0b174c 100644
--- a/i18npool/source/breakiterator/xdictionary.cxx
+++ b/i18npool/source/breakiterator/xdictionary.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -45,7 +46,8 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-using namespace rtl;
+using ::rtl::OUString;
+using ::rtl::OUStringBuffer;
namespace com { namespace sun { namespace star { namespace i18n {
@@ -60,12 +62,6 @@ xdictionary::xdictionary(const sal_Char *lang) :
hModule( NULL ),
boundary(),
japaneseWordBreak( sal_False )
-#if USE_CELL_BOUNDARY_CODE
- // For CTL breakiterator, where the word boundary should not be inside cell.
- ,
- useCellBoundary( sal_False ),
- cellBoundary( NULL )
-#endif
{
index1 = 0;
#ifdef SAL_DLLPREFIX
@@ -78,15 +74,15 @@ xdictionary::xdictionary(const sal_Char *lang) :
hModule = osl_loadModuleRelative( &thisModule, aBuf.makeStringAndClear().pData, SAL_LOADMODULE_DEFAULT );
if( hModule ) {
sal_IntPtr (*func)();
- func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString::createFromAscii("getExistMark").pData );
+ func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString(RTL_CONSTASCII_USTRINGPARAM("getExistMark")).pData );
existMark = (sal_uInt8*) (*func)();
- func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString::createFromAscii("getIndex1").pData );
+ func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString(RTL_CONSTASCII_USTRINGPARAM("getIndex1")).pData );
index1 = (sal_Int16*) (*func)();
- func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString::createFromAscii("getIndex2").pData );
+ func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString(RTL_CONSTASCII_USTRINGPARAM("getIndex2")).pData );
index2 = (sal_Int32*) (*func)();
- func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString::createFromAscii("getLenArray").pData );
+ func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString(RTL_CONSTASCII_USTRINGPARAM("getLenArray")).pData );
lenArray = (sal_Int32*) (*func)();
- func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString::createFromAscii("getDataArea").pData );
+ func = (sal_IntPtr(*)()) osl_getFunctionSymbol( hModule, OUString(RTL_CONSTASCII_USTRINGPARAM("getDataArea")).pData );
dataArea = (sal_Unicode*) (*func)();
}
else
@@ -101,10 +97,6 @@ xdictionary::xdictionary(const sal_Char *lang) :
for (sal_Int32 i = 0; i < CACHE_MAX; i++)
cache[i].size = 0;
-#if USE_CELL_BOUNDARY_CODE
- useCellBoundary = sal_False;
- cellBoundary = NULL;
-#endif
japaneseWordBreak = sal_False;
}
@@ -112,8 +104,8 @@ xdictionary::~xdictionary() {
osl_unloadModule(hModule);
for (sal_Int32 i = 0; i < CACHE_MAX; i++) {
if (cache[i].size > 0) {
- delete cache[i].contents;
- delete cache[i].wordboundary;
+ delete [] cache[i].contents;
+ delete [] cache[i].wordboundary;
}
}
}
@@ -241,86 +233,70 @@ static sal_Int16 JapaneseCharType(sal_Unicode c)
WordBreakCache& xdictionary::getCache(const sal_Unicode *text, Boundary& wordBoundary)
{
+ WordBreakCache& rCache = cache[text[0] & 0x1f];
- WordBreakCache& aCache = cache[text[0] & 0x1f];
-
- if (aCache.size != 0 && aCache.equals(text, wordBoundary))
- return aCache;
+ if (rCache.size != 0 && rCache.equals(text, wordBoundary))
+ return rCache;
- sal_Int32 len = wordBoundary.endPos - wordBoundary.startPos;
+ sal_Int32 len = wordBoundary.endPos - wordBoundary.startPos;
- if (aCache.size == 0 || len > aCache.size) {
- if (aCache.size != 0) {
- delete aCache.contents;
- delete aCache.wordboundary;
- aCache.size = len;
- }
- else
- aCache.size = len > DEFAULT_SIZE ? len : DEFAULT_SIZE;
- aCache.contents = new sal_Unicode[aCache.size + 1];
- aCache.wordboundary = new sal_Int32[aCache.size + 2];
+ if (rCache.size == 0 || len > rCache.size) {
+ if (rCache.size != 0) {
+ delete rCache.contents;
+ delete rCache.wordboundary;
+ rCache.size = len;
}
- aCache.length = len;
- memcpy(aCache.contents, text + wordBoundary.startPos, len * sizeof(sal_Unicode));
- *(aCache.contents + len) = 0x0000;
- // reset the wordboundary in cache
- memset(aCache.wordboundary, '\0', sizeof(sal_Int32)*(len + 2));
-
- sal_Int32 i = 0; // loop variable
- while (aCache.wordboundary[i] < aCache.length) {
- len = 0;
- // look the continuous white space as one word and cashe it
- while (u_isWhitespace((sal_uInt32)text[wordBoundary.startPos + aCache.wordboundary[i] + len]))
- len ++;
-
- if (len == 0) {
- const sal_Unicode *str = text + wordBoundary.startPos + aCache.wordboundary[i];
- sal_Int32 slen = aCache.length - aCache.wordboundary[i];
- sal_Int16 type = 0, count = 0;
- for (;len == 0 && slen > 0; str++, slen--) {
- len = getLongestMatch(str, slen);
- if (len == 0) {
- if (!japaneseWordBreak) {
- len = 1;
- } else {
- if (count == 0)
- type = JapaneseCharType(*str);
- else if (type != JapaneseCharType(*str))
- break;
- count++;
- }
- }
- }
- if (count) {
- aCache.wordboundary[i+1] = aCache.wordboundary[i] + count;
- i++;
-
-#if USE_CELL_BOUNDARY_CODE
- if (useCellBoundary) {
- sal_Int32 cBoundary = cellBoundary[aCache.wordboundary[i] + wordBoundary.startPos - 1];
- if (cBoundary > 0)
- aCache.wordboundary[i] = cBoundary - wordBoundary.startPos;
+ else
+ rCache.size = len > DEFAULT_SIZE ? len : DEFAULT_SIZE;
+ rCache.contents = new sal_Unicode[rCache.size + 1];
+ rCache.wordboundary = new sal_Int32[rCache.size + 2];
+ }
+ rCache.length = len;
+ memcpy(rCache.contents, text + wordBoundary.startPos, len * sizeof(sal_Unicode));
+ *(rCache.contents + len) = 0x0000;
+ // reset the wordboundary in cache
+ memset(rCache.wordboundary, '\0', sizeof(sal_Int32)*(len + 2));
+
+ sal_Int32 i = 0; // loop variable
+ while (rCache.wordboundary[i] < rCache.length) {
+ len = 0;
+ // look the continuous white space as one word and cashe it
+ while (u_isWhitespace((sal_uInt32)text[wordBoundary.startPos + rCache.wordboundary[i] + len]))
+ len ++;
+
+ if (len == 0) {
+ const sal_Unicode *str = text + wordBoundary.startPos + rCache.wordboundary[i];
+ sal_Int32 slen = rCache.length - rCache.wordboundary[i];
+ sal_Int16 type = 0, count = 0;
+ for (;len == 0 && slen > 0; str++, slen--) {
+ len = getLongestMatch(str, slen);
+ if (len == 0) {
+ if (!japaneseWordBreak) {
+ len = 1;
+ } else {
+ if (count == 0)
+ type = JapaneseCharType(*str);
+ else if (type != JapaneseCharType(*str))
+ break;
+ count++;
}
-#endif
}
}
-
- if (len) {
- aCache.wordboundary[i+1] = aCache.wordboundary[i] + len;
+ if (count)
+ {
+ rCache.wordboundary[i+1] = rCache.wordboundary[i] + count;
i++;
-
-#if USE_CELL_BOUNDARY_CODE
- if (useCellBoundary) {
- sal_Int32 cBoundary = cellBoundary[aCache.wordboundary[i] + wordBoundary.startPos - 1];
- if (cBoundary > 0)
- aCache.wordboundary[i] = cBoundary - wordBoundary.startPos;
- }
-#endif
}
}
- aCache.wordboundary[i + 1] = aCache.length + 1;
- return aCache;
+ if (len) {
+ rCache.wordboundary[i+1] = rCache.wordboundary[i] + len;
+ i++;
+ }
+ }
+ rCache.wordboundary[i + 1] = rCache.length + 1;
+
+ return rCache;
}
Boundary xdictionary::previousWord(const OUString& rText, sal_Int32 anyPos, sal_Int16 wordType)
@@ -391,12 +367,6 @@ Boundary xdictionary::getWordBoundary(const OUString& rText, sal_Int32 anyPos, s
return boundary;
}
-#if USE_CELL_BOUNDARY_CODE
-void xdictionary::setCellBoundary(sal_Int32* cellArray)
-{
- useCellBoundary = sal_True;
- cellBoundary = cellArray;
-}
-#endif
-
} } } }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */