summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-08-24 01:05:14 +0200
committerMichael Stahl <mstahl@redhat.com>2013-08-24 01:08:18 +0200
commit7b28b6cc6116856246ad2f339f5e6fb753197781 (patch)
treead2652cc9ab0d8f98a63df54dd6854a754457ff0 /sw
parent087ee66013916bd009eb0b29460ef1868b4d755c (diff)
fdo#68319: sw: fix Chinese Conversion
... and perhaps other things too: the SwScriptIterator constructor gets passed a temporary String created by implicit conversion from OUString and retains a reference to that; convert the thing to use OUString (and adapt some sCleanStr too not to get the inverse problem...). (regression from 0295c8a34e39326414c1b98cf4da905802f061b0) Change-Id: I038ad0734385cdcae99ec404153f51ee427c7c64
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/txatritr.hxx12
-rw-r--r--sw/source/core/crsr/findtxt.cxx30
-rw-r--r--sw/source/core/txtnode/txatritr.cxx52
3 files changed, 50 insertions, 44 deletions
diff --git a/sw/inc/txatritr.hxx b/sw/inc/txatritr.hxx
index 05ed48fb3dbf..b583f7334bd8 100644
--- a/sw/inc/txatritr.hxx
+++ b/sw/inc/txatritr.hxx
@@ -24,8 +24,8 @@
#include <editeng/langitem.hxx>
#include <hintids.hxx>
#include <deque>
+#include <tools/string.hxx>
-class String;
class SwTxtNode;
class SwTxtAttr;
class SfxPoolItem;
@@ -33,20 +33,20 @@ class SfxPoolItem;
class SwScriptIterator
{
- const String& rText;
- xub_StrLen nChgPos;
+ const OUString& m_rText;
+ sal_Int32 m_nChgPos;
sal_uInt16 nCurScript;
bool bForward;
public:
- SwScriptIterator( const String& rStr, xub_StrLen nStart = 0,
+ SwScriptIterator( const OUString& rStr, xub_StrLen nStart = 0,
bool bFrwrd = true );
bool Next();
sal_uInt16 GetCurrScript() const { return nCurScript; }
- xub_StrLen GetScriptChgPos() const { return nChgPos; }
- const String& GetText() const { return rText; }
+ xub_StrLen GetScriptChgPos() const { return (m_nChgPos == -1) ? STRING_LEN : m_nChgPos; }
+ const OUString& GetText() const { return m_rText; }
};
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index 8439cffdc13d..9518f4f7953d 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -49,11 +49,11 @@ using namespace util;
String *ReplaceBackReferences( const SearchOptions& rSearchOpt, SwPaM* pPam );
-static String& lcl_CleanStr( const SwTxtNode& rNd, xub_StrLen nStart, xub_StrLen& rEnd,
- std::vector<sal_uLong> &rArr, String& rRet,
- bool bRemoveSoftHyphen )
+static OUString
+lcl_CleanStr(const SwTxtNode& rNd, xub_StrLen const nStart, xub_StrLen& rEnd,
+ std::vector<sal_uLong> &rArr, bool const bRemoveSoftHyphen)
{
- rRet = rNd.GetTxt();
+ OUStringBuffer buf(rNd.GetTxt());
rArr.clear();
const SwpHints *pHts = rNd.GetpSwpHints();
@@ -140,13 +140,13 @@ static String& lcl_CleanStr( const SwTxtNode& rNd, xub_StrLen nStart, xub_StrLen
{
rArr.push_back( nAkt );
--rEnd;
- rRet.Erase( nAkt, 1 );
+ buf.remove(nAkt, 1);
}
else
{
if ( bEmpty )
aReplaced.push_back( nAkt );
- rRet.SetChar( nAkt, '\x7f' );
+ buf[nAkt] = '\x7f';
}
}
break;
@@ -162,7 +162,7 @@ static String& lcl_CleanStr( const SwTxtNode& rNd, xub_StrLen nStart, xub_StrLen
{
rArr.push_back( nAkt );
--rEnd;
- rRet.Erase( nAkt, 1 );
+ buf.remove(nAkt, 1);
++nSoftHyphen;
}
}
@@ -171,15 +171,15 @@ static String& lcl_CleanStr( const SwTxtNode& rNd, xub_StrLen nStart, xub_StrLen
for( sal_uInt16 i = aReplaced.size(); i; )
{
const xub_StrLen nTmp = aReplaced[ --i ];
- if( nTmp == rRet.Len() - 1 )
+ if (nTmp == buf.getLength() - 1)
{
- rRet.Erase( nTmp );
+ buf.truncate(nTmp);
rArr.push_back( nTmp );
--rEnd;
}
}
- return rRet;
+ return buf.makeStringAndClear();
}
// skip all non SwPostIts inside the array
@@ -412,7 +412,7 @@ bool SwPaM::DoSearch( const SearchOptions& rSearchOpt, utl::TextSearch& rSTxt,
bool bFound = false;
SwNodeIndex& rNdIdx = pPam->GetPoint()->nNode;
const SwNode* pSttNd = &rNdIdx.GetNode();
- String sCleanStr;
+ OUString sCleanStr;
std::vector<sal_uLong> aFltArr;
LanguageType eLastLang = 0;
// if the search string contains a soft hypen,
@@ -432,11 +432,11 @@ bool SwPaM::DoSearch( const SearchOptions& rSearchOpt, utl::TextSearch& rSTxt,
}
if( bSrchForward )
- lcl_CleanStr( *(SwTxtNode*)pNode, nStart, nEnd,
- aFltArr, sCleanStr, bRemoveSoftHyphens );
+ sCleanStr = lcl_CleanStr(*static_cast<SwTxtNode*>(pNode), nStart, nEnd,
+ aFltArr, bRemoveSoftHyphens);
else
- lcl_CleanStr( *(SwTxtNode*)pNode, nEnd, nStart,
- aFltArr, sCleanStr, bRemoveSoftHyphens );
+ sCleanStr = lcl_CleanStr(*static_cast<SwTxtNode*>(pNode), nEnd, nStart,
+ aFltArr, bRemoveSoftHyphens);
SwScriptIterator* pScriptIter = 0;
sal_uInt16 nSearchScript = 0;
diff --git a/sw/source/core/txtnode/txatritr.cxx b/sw/source/core/txtnode/txatritr.cxx
index 00e007afe99d..77637287fc63 100644
--- a/sw/source/core/txtnode/txatritr.cxx
+++ b/sw/source/core/txtnode/txatritr.cxx
@@ -30,11 +30,12 @@
using namespace ::com::sun::star;
-SwScriptIterator::SwScriptIterator( const String& rStr, xub_StrLen nStt, bool bFrwrd )
- : rText( rStr ),
- nChgPos( rStr.Len() ),
- nCurScript( i18n::ScriptType::WEAK ),
- bForward( bFrwrd )
+SwScriptIterator::SwScriptIterator(
+ const OUString& rStr, xub_StrLen nStt, bool const bFrwrd)
+ : m_rText(rStr)
+ , m_nChgPos(rStr.getLength())
+ , nCurScript(i18n::ScriptType::WEAK)
+ , bForward(bFrwrd)
{
if( g_pBreakIt->GetBreakIter().is() )
{
@@ -42,24 +43,27 @@ SwScriptIterator::SwScriptIterator( const String& rStr, xub_StrLen nStt, bool bF
--nStt;
xub_StrLen nPos = nStt;
- nCurScript = g_pBreakIt->GetBreakIter()->getScriptType( rText, nPos );
+ nCurScript = g_pBreakIt->GetBreakIter()->getScriptType(m_rText, nPos);
if( i18n::ScriptType::WEAK == nCurScript )
{
if( nPos )
{
nPos = (xub_StrLen)g_pBreakIt->GetBreakIter()->beginOfScript(
- rText, nPos, nCurScript );
- if( nPos && nPos < rText.Len() )
+ m_rText, nPos, nCurScript);
+ if (nPos && nPos < m_rText.getLength())
{
nStt = --nPos;
- nCurScript = g_pBreakIt->GetBreakIter()->getScriptType( rText,nPos);
+ nCurScript =
+ g_pBreakIt->GetBreakIter()->getScriptType(m_rText,nPos);
}
}
}
- nChgPos = bForward ?
- (xub_StrLen)g_pBreakIt->GetBreakIter()->endOfScript( rText, nStt, nCurScript ) :
- (xub_StrLen)g_pBreakIt->GetBreakIter()->beginOfScript( rText, nStt, nCurScript );
+ m_nChgPos = (bForward)
+ ? g_pBreakIt->GetBreakIter()->endOfScript(
+ m_rText, nStt, nCurScript)
+ : g_pBreakIt->GetBreakIter()->beginOfScript(
+ m_rText, nStt, nCurScript);
}
}
@@ -68,24 +72,26 @@ bool SwScriptIterator::Next()
bool bRet = false;
if( g_pBreakIt->GetBreakIter().is() )
{
- if ( bForward && nChgPos < rText.Len() )
+ if (bForward && (m_nChgPos != -1) && (m_nChgPos < m_rText.getLength()))
{
- nCurScript = g_pBreakIt->GetBreakIter()->getScriptType( rText, nChgPos );
- nChgPos = (xub_StrLen)g_pBreakIt->GetBreakIter()->endOfScript(
- rText, nChgPos, nCurScript );
+ nCurScript =
+ g_pBreakIt->GetBreakIter()->getScriptType(m_rText, m_nChgPos);
+ m_nChgPos = g_pBreakIt->GetBreakIter()->endOfScript(
+ m_rText, m_nChgPos, nCurScript);
bRet = true;
}
- else if ( ! bForward && nChgPos )
+ else if (!bForward && m_nChgPos > 0)
{
- --nChgPos;
- nCurScript = g_pBreakIt->GetBreakIter()->getScriptType( rText, nChgPos );
- nChgPos = (xub_StrLen)g_pBreakIt->GetBreakIter()->beginOfScript(
- rText, nChgPos, nCurScript );
+ --m_nChgPos;
+ nCurScript =
+ g_pBreakIt->GetBreakIter()->getScriptType(m_rText, m_nChgPos);
+ m_nChgPos = g_pBreakIt->GetBreakIter()->beginOfScript(
+ m_rText, m_nChgPos, nCurScript);
bRet = true;
}
}
else
- nChgPos = rText.Len();
+ m_nChgPos = m_rText.getLength();
return bRet;
}
@@ -104,7 +110,7 @@ SwTxtAttrIterator::SwTxtAttrIterator( const SwTxtNode& rTNd, sal_uInt16 nWhchId,
bool SwTxtAttrIterator::Next()
{
bool bRet = false;
- if( nChgPos < aSIter.GetText().Len() )
+ if (nChgPos < aSIter.GetText().getLength())
{
bRet = true;
if( !aStack.empty() )