summaryrefslogtreecommitdiff
path: root/svtools/source/misc/filterutils.cxx
blob: 5a31070150fb15b39303c1835521ab2c59793a8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svtools.hxx"
#include "filterutils.hxx"
#include <rtl/ustrbuf.hxx>

namespace svt
{
//........................................................................

    using namespace ::com::sun::star;

    rtl::OUString lcl_createStringFromArray( const char* pcCharArr, sal_uInt32 nBufSize, bool bIsCompressed )
    {
        rtl::OUStringBuffer aBuffer;
        if( bIsCompressed )
        {
            // buffer contains compressed Unicode, not encoded bytestring
            sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize );
            aBuffer.setLength( nStrLen );
            const char* pcCurrChar = pcCharArr;
            for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar, ++pcCurrChar )
                /*  *pcCurrChar may contain negative values and therefore MUST be
                    casted to unsigned char, before assigned to a sal_Unicode. */
                aBuffer.setCharAt( nChar, static_cast< unsigned char >( *pcCurrChar ) );
        }
        else
        {
            // buffer contains Little-Endian Unicode
            sal_Int32 nStrLen = static_cast< sal_Int32 >( nBufSize ) / 2;
            aBuffer.setLength( nStrLen );
            const char* pcCurrChar = pcCharArr;
            for( sal_Int32 nChar = 0; nChar < nStrLen; ++nChar )
            {
                /*  *pcCurrChar may contain negative values and therefore MUST be
                    casted to unsigned char, before assigned to a sal_Unicode. */
                sal_Unicode cChar = static_cast< unsigned char >( *pcCurrChar++ );
                cChar |= (static_cast< unsigned char >( *pcCurrChar++ ) << 8);
                aBuffer.setCharAt( nChar, cChar );
            }
        }
        return aBuffer.makeStringAndClear();
    }

    rtl::OUString BinFilterUtils::CreateOUStringFromUniStringArray( const char* pcCharArr, sal_uInt32 nBufSize )
    {
        return lcl_createStringFromArray( pcCharArr, nBufSize, false );
    }

    rtl::OUString BinFilterUtils::CreateOUStringFromStringArray( const char* pcCharArr, sal_uInt32 nBufSize )
    {
        return lcl_createStringFromArray( pcCharArr, nBufSize, true );
    }
//........................................................................
} // namespace svt
//........................................................................