diff options
Diffstat (limited to 'svl/source/misc/lngmisc.cxx')
-rw-r--r-- | svl/source/misc/lngmisc.cxx | 78 |
1 files changed, 55 insertions, 23 deletions
diff --git a/svl/source/misc/lngmisc.cxx b/svl/source/misc/lngmisc.cxx index c655a8dd86a3..2eba00efd565 100644 --- a/svl/source/misc/lngmisc.cxx +++ b/svl/source/misc/lngmisc.cxx @@ -28,7 +28,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_svl.hxx" -#include <lngmisc.hxx> +#include <svl/lngmisc.hxx> #include <tools/solar.h> #include <tools/string.hxx> #include <tools/debug.hxx> @@ -43,11 +43,11 @@ namespace linguistic /////////////////////////////////////////////////////////////////////////// -INT32 GetNumControlChars( const OUString &rTxt ) +sal_Int32 GetNumControlChars( const OUString &rTxt ) { - INT32 nCnt = 0; - INT32 nLen = rTxt.getLength(); - for (INT32 i = 0; i < nLen; ++i) + sal_Int32 nCnt = 0; + sal_Int32 nLen = rTxt.getLength(); + for (sal_Int32 i = 0; i < nLen; ++i) { if (IsControlChar( rTxt[i] )) ++nCnt; @@ -56,33 +56,33 @@ INT32 GetNumControlChars( const OUString &rTxt ) } -BOOL RemoveHyphens( OUString &rTxt ) +sal_Bool RemoveHyphens( OUString &rTxt ) { - BOOL bModified = FALSE; + sal_Bool bModified = sal_False; if (HasHyphens( rTxt )) { String aTmp( rTxt ); aTmp.EraseAllChars( SVT_SOFT_HYPHEN ); aTmp.EraseAllChars( SVT_HARD_HYPHEN ); rTxt = aTmp; - bModified = TRUE; + bModified = sal_True; } return bModified; } -BOOL RemoveControlChars( OUString &rTxt ) +sal_Bool RemoveControlChars( OUString &rTxt ) { - BOOL bModified = FALSE; - INT32 nCtrlChars = GetNumControlChars( rTxt ); + sal_Bool bModified = sal_False; + sal_Int32 nCtrlChars = GetNumControlChars( rTxt ); if (nCtrlChars) { - INT32 nLen = rTxt.getLength(); - INT32 nSize = nLen - nCtrlChars; + sal_Int32 nLen = rTxt.getLength(); + sal_Int32 nSize = nLen - nCtrlChars; OUStringBuffer aBuf( nSize ); aBuf.setLength( nSize ); - INT32 nCnt = 0; - for (INT32 i = 0; i < nLen; ++i) + sal_Int32 nCnt = 0; + for (sal_Int32 i = 0; i < nLen; ++i) { sal_Unicode cChar = rTxt[i]; if (!IsControlChar( cChar )) @@ -93,7 +93,7 @@ BOOL RemoveControlChars( OUString &rTxt ) } DBG_ASSERT( nCnt == nSize, "wrong size" ); rTxt = aBuf.makeStringAndClear(); - bModified = TRUE; + bModified = sal_True; } return bModified; } @@ -102,20 +102,20 @@ BOOL RemoveControlChars( OUString &rTxt ) // non breaking field character #define CH_TXTATR_INWORD ((sal_Char) 0x02) -BOOL ReplaceControlChars( rtl::OUString &rTxt, sal_Char /*aRplcChar*/ ) +sal_Bool ReplaceControlChars( rtl::OUString &rTxt, sal_Char /*aRplcChar*/ ) { // the resulting string looks like this: // 1. non breaking field characters get removed // 2. remaining control characters will be replaced by ' ' - BOOL bModified = FALSE; - INT32 nCtrlChars = GetNumControlChars( rTxt ); + sal_Bool bModified = sal_False; + sal_Int32 nCtrlChars = GetNumControlChars( rTxt ); if (nCtrlChars) { - INT32 nLen = rTxt.getLength(); + sal_Int32 nLen = rTxt.getLength(); OUStringBuffer aBuf( nLen ); - INT32 nCnt = 0; - for (INT32 i = 0; i < nLen; ++i) + sal_Int32 nCnt = 0; + for (sal_Int32 i = 0; i < nLen; ++i) { sal_Unicode cChar = rTxt[i]; if (CH_TXTATR_INWORD != cChar) @@ -128,11 +128,43 @@ BOOL ReplaceControlChars( rtl::OUString &rTxt, sal_Char /*aRplcChar*/ ) } aBuf.setLength( nCnt ); rTxt = aBuf.makeStringAndClear(); - bModified = TRUE; + bModified = sal_True; } return bModified; } + +String GetThesaurusReplaceText( const String &rText ) +{ + // The strings for synonyms returned by the thesaurus sometimes have some + // explanation text put in between '(' and ')' or a trailing '*'. + // These parts should not be put in the ReplaceEdit Text that may get + // inserted into the document. Thus we strip them from the text. + + String aText( rText ); + + xub_StrLen nPos = aText.Search( sal_Unicode('(') ); + while (STRING_NOTFOUND != nPos) + { + xub_StrLen nEnd = aText.Search( sal_Unicode(')'), nPos ); + if (STRING_NOTFOUND != nEnd) + aText.Erase( nPos, nEnd-nPos+1 ); + else + break; + nPos = aText.Search( sal_Unicode('(') ); + } + + nPos = aText.Search( sal_Unicode('*') ); + if (STRING_NOTFOUND != nPos) + aText.Erase( nPos ); + + // remove any possible remaining ' ' that may confuse the thesaurus + // when it gets called with the text + aText.EraseLeadingAndTrailingChars( sal_Unicode(' ') ); + + return aText; +} + /////////////////////////////////////////////////////////////////////////// } // namespace linguistic |