summaryrefslogtreecommitdiff
path: root/linguistic/source/misc.cxx
diff options
context:
space:
mode:
authorThomas Lange <tl@openoffice.org>2000-12-21 08:57:08 +0000
committerThomas Lange <tl@openoffice.org>2000-12-21 08:57:08 +0000
commit65e2cc1dd328bda800144cd2ab0e764184ad2d14 (patch)
treef66afe47056a14401f1ddfdcc55aa18a56029513 /linguistic/source/misc.cxx
parentf22f3967e0f8cd0691648f4a23914bd98f011d10 (diff)
Functions to remove hyphens and control characters added
Diffstat (limited to 'linguistic/source/misc.cxx')
-rw-r--r--linguistic/source/misc.cxx112
1 files changed, 110 insertions, 2 deletions
diff --git a/linguistic/source/misc.cxx b/linguistic/source/misc.cxx
index d7caae39b197..d9f08643b2ed 100644
--- a/linguistic/source/misc.cxx
+++ b/linguistic/source/misc.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: misc.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: tl $ $Date: 2000-12-15 10:21:30 $
+ * last change: $Author: tl $ $Date: 2000-12-21 09:57:08 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -68,6 +68,9 @@
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
+#ifndef _RTL_USTRBUF_HXX_
+#include <rtl/ustrbuf.hxx>
+#endif
#ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
#include <svtools/pathoptions.hxx>
#endif
@@ -150,6 +153,32 @@ BOOL IsUseDicList( const PropertyValues &rProperties,
}
+BOOL IsIgnoreControlChars( const PropertyValues &rProperties,
+ const Reference< XPropertySet > &rxProp )
+{
+ BOOL bRes = TRUE;
+
+ INT32 nLen = rProperties.getLength();
+ const PropertyValue *pVal = rProperties.getConstArray();
+ for (INT32 i = 0; i < nLen; ++i)
+ {
+ if (UPH_IS_IGNORE_CONTROL_CHARACTERS == pVal[i].Handle)
+ {
+ pVal[i].Value >>= bRes;
+ break;
+ }
+ }
+ if (i >= nLen) // no temporary value found in 'rProperties'
+ {
+ Reference< XFastPropertySet > xFast( rxProp, UNO_QUERY );
+ if (xFast.is())
+ xFast->getFastPropertyValue( UPH_IS_IGNORE_CONTROL_CHARACTERS ) >>= bRes;
+ }
+
+ return bRes;
+}
+
+
static BOOL lcl_HasHyphInfo( const Reference<XDictionaryEntry> &xEntry )
{
BOOL bRes = FALSE;
@@ -281,6 +310,85 @@ uno::Sequence< INT16 >
///////////////////////////////////////////////////////////////////////////
+#define SOFT_HYPHEN ((sal_Unicode) 0x00AD)
+#define HARD_HYPHEN ((sal_Unicode) 0x2011)
+
+
+inline BOOL IsHyphen( sal_Unicode cChar )
+{
+ return cChar == SOFT_HYPHEN || cChar == HARD_HYPHEN;
+}
+
+
+inline BOOL IsControlChar( sal_Unicode cChar )
+{
+ return cChar < (sal_Unicode) ' ';
+}
+
+
+inline BOOL HasHyphens( const OUString &rTxt )
+{
+ return rTxt.indexOf( SOFT_HYPHEN ) != -1 ||
+ rTxt.indexOf( HARD_HYPHEN ) != -1;
+}
+
+
+INT32 GetNumControlChars( const OUString &rTxt )
+{
+ INT32 nCnt = 0;
+ INT32 nLen = rTxt.getLength();
+ for (INT32 i = 0; i < nLen; ++i)
+ {
+ if (IsControlChar( rTxt[i] ))
+ ++nCnt;
+ }
+ return nCnt;
+}
+
+
+BOOL RemoveHyphens( OUString &rTxt )
+{
+ BOOL bModified = FALSE;
+ if (HasHyphens( rTxt ))
+ {
+ String aTmp( rTxt );
+ aTmp.EraseAllChars( SOFT_HYPHEN );
+ aTmp.EraseAllChars( HARD_HYPHEN );
+ rTxt = aTmp;
+ bModified = TRUE;
+ }
+ return bModified;
+}
+
+
+BOOL RemoveControlChars( OUString &rTxt )
+{
+ BOOL bModified = FALSE;
+ INT32 nCtrlChars = GetNumControlChars( rTxt );
+ if (nCtrlChars)
+ {
+ INT32 nLen = rTxt.getLength();
+ INT32 nSize = nLen - nCtrlChars;
+ OUStringBuffer aBuf( nSize );
+ INT32 nCnt = 0;
+ for (INT32 i = 0; i < nLen; ++i)
+ {
+ sal_Unicode cChar = rTxt[i];
+ if (!IsControlChar( cChar ))
+ {
+ DBG_ASSERT( nCnt < nSize, "index out of range" );
+ aBuf.setCharAt( nCnt++, cChar );
+ }
+ }
+ DBG_ASSERT( nCnt == nSize, "wrong size" );
+ rTxt = aBuf.makeStringAndClear();
+ bModified = TRUE;
+ }
+ return bModified;
+}
+
+///////////////////////////////////////////////////////////////////////////
+
// TL_TODO:
// replace this non performant implementations with better ones
//