1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lngmisc.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <lngmisc.hxx>
34 #include <tools/solar.h>
35 #include <tools/string.hxx>
36 #include <tools/debug.hxx>
37 #include <rtl/ustrbuf.hxx>
38 #include <rtl/ustring.hxx>
46 ///////////////////////////////////////////////////////////////////////////
48 INT32
GetNumControlChars( const OUString
&rTxt
)
51 INT32 nLen
= rTxt
.getLength();
52 for (INT32 i
= 0; i
< nLen
; ++i
)
54 if (IsControlChar( rTxt
[i
] ))
61 BOOL
RemoveHyphens( OUString
&rTxt
)
63 BOOL bModified
= FALSE
;
64 if (HasHyphens( rTxt
))
67 aTmp
.EraseAllChars( SVT_SOFT_HYPHEN
);
68 aTmp
.EraseAllChars( SVT_HARD_HYPHEN
);
76 BOOL
RemoveControlChars( OUString
&rTxt
)
78 BOOL bModified
= FALSE
;
79 INT32 nCtrlChars
= GetNumControlChars( rTxt
);
82 INT32 nLen
= rTxt
.getLength();
83 INT32 nSize
= nLen
- nCtrlChars
;
84 OUStringBuffer
aBuf( nSize
);
85 aBuf
.setLength( nSize
);
87 for (INT32 i
= 0; i
< nLen
; ++i
)
89 sal_Unicode cChar
= rTxt
[i
];
90 if (!IsControlChar( cChar
))
92 DBG_ASSERT( nCnt
< nSize
, "index out of range" );
93 aBuf
.setCharAt( nCnt
++, cChar
);
96 DBG_ASSERT( nCnt
== nSize
, "wrong size" );
97 rTxt
= aBuf
.makeStringAndClear();
104 // non breaking field character
105 #define CH_TXTATR_INWORD ((sal_Char) 0x02)
107 BOOL
ReplaceControlChars( rtl::OUString
&rTxt
, sal_Char
/*aRplcChar*/ )
109 // the resulting string looks like this:
110 // 1. non breaking field characters get removed
111 // 2. remaining control characters will be replaced by ' '
113 BOOL bModified
= FALSE
;
114 INT32 nCtrlChars
= GetNumControlChars( rTxt
);
117 INT32 nLen
= rTxt
.getLength();
118 OUStringBuffer
aBuf( nLen
);
120 for (INT32 i
= 0; i
< nLen
; ++i
)
122 sal_Unicode cChar
= rTxt
[i
];
123 if (CH_TXTATR_INWORD
!= cChar
)
125 if (IsControlChar( cChar
))
127 DBG_ASSERT( nCnt
< nLen
, "index out of range" );
128 aBuf
.setCharAt( nCnt
++, cChar
);
131 aBuf
.setLength( nCnt
);
132 rTxt
= aBuf
.makeStringAndClear();
138 ///////////////////////////////////////////////////////////////////////////
140 } // namespace linguistic