merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / misc / filterutils.cxx
blob91a6ca48f69586a7d387f8143ca87a9ef6c3b644
1 // MARKER(update_precomp.py): autogen include statement, do not remove
2 #include "precompiled_svtools.hxx"
3 #include "filterutils.hxx"
4 #include <rtl/ustrbuf.hxx>
6 namespace svt
8 //........................................................................
10 using namespace ::com::sun::star;
12 rtl::OUString lcl_createStringFromArray( const char* pcCharArr, sal_uInt32 nBufSize, bool bIsCompressed )
14 rtl::OUStringBuffer aBuffer;
15 if( bIsCompressed )
17 // buffer contains compressed Unicode, not encoded bytestring
18 sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize );
19 aBuffer.setLength( nStrLen );
20 const char* pcCurrChar = pcCharArr;
21 for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar, ++pcCurrChar )
22 /* *pcCurrChar may contain negative values and therefore MUST be
23 casted to unsigned char, before assigned to a sal_Unicode. */
24 aBuffer.setCharAt( nChar, static_cast< unsigned char >( *pcCurrChar ) );
26 else
28 // buffer contains Little-Endian Unicode
29 sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize ) / 2;
30 aBuffer.setLength( nStrLen );
31 const char* pcCurrChar = pcCharArr;
32 for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar )
34 /* *pcCurrChar may contain negative values and therefore MUST be
35 casted to unsigned char, before assigned to a sal_Unicode. */
36 sal_Unicode cChar = static_cast< unsigned char >( *pcCurrChar++ );
37 cChar |= (static_cast< unsigned char >( *pcCurrChar++ ) << 8);
38 aBuffer.setCharAt( nChar, cChar );
41 return aBuffer.makeStringAndClear();
44 rtl::OUString BinFilterUtils::CreateOUStringFromUniStringArray( const char* pcCharArr, sal_uInt32 nBufSize )
46 return lcl_createStringFromArray( pcCharArr, nBufSize, false );
49 rtl::OUString BinFilterUtils::CreateOUStringFromStringArray( const char* pcCharArr, sal_uInt32 nBufSize )
51 return lcl_createStringFromArray( pcCharArr, nBufSize, true );
53 //........................................................................
54 } // namespace svt
55 //........................................................................