LCOV - code coverage report
Current view: top level - libreoffice/sw/source/filter/basflt - iodetect.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 115 271 42.4 %
Date: 2012-12-27 Functions: 9 16 56.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <iodetect.hxx>
      22             : #include <boost/scoped_array.hpp>
      23             : #include <osl/endian.h>
      24             : #include <sot/storage.hxx>
      25             : #include <svtools/parhtml.hxx>
      26             : #include <tools/urlobj.hxx>
      27             : 
      28             : bool IsDocShellRegistered();
      29             : 
      30             : SwIoDetect aFilterDetect[] =
      31             : {
      32             :     SwIoDetect( FILTER_RTF,      STRING_LEN ),
      33             :     SwIoDetect( FILTER_BAS,      STRING_LEN ),
      34             :     SwIoDetect( sWW6,            STRING_LEN ),
      35             :     SwIoDetect( FILTER_WW8,      STRING_LEN ),
      36             :     SwIoDetect( sRtfWH,          STRING_LEN ),
      37             :     SwIoDetect( sHTML,           4 ),
      38             :     SwIoDetect( sWW1,            STRING_LEN ),
      39             :     SwIoDetect( sWW5,            STRING_LEN ),
      40             :     SwIoDetect( FILTER_XML,      4 ),
      41             :     SwIoDetect( FILTER_TEXT_DLG, 8 ),
      42             :     SwIoDetect( FILTER_TEXT,     4 )
      43          10 : };
      44             : 
      45         118 : const sal_Char* SwIoDetect::IsReader(const sal_Char* pHeader, sal_uLong nLen_,
      46             :     const String & /*rFileName*/, const String& /*rUserData*/) const
      47             : {
      48             :     // Filter erkennung
      49             :     struct W1_FIB
      50             :     {
      51             :         SVBT16 wIdent;      // 0x0 int magic number
      52             :         SVBT16 nFib;        // 0x2 FIB version written
      53             :         SVBT16 nProduct;    // 0x4 product version written by
      54             :         SVBT16 nlocale;     // 0x6 language stamp---localized version;
      55             :         SVBT16 pnNext;      // 0x8
      56             :         SVBT16 fFlags;
      57             : 
      58           0 :         sal_uInt16 nFibGet()    { return SVBT16ToShort(nFib); }
      59           0 :         sal_uInt16 wIdentGet()  { return SVBT16ToShort(wIdent); }
      60           0 :         sal_uInt16 fFlagsGet()  { return SVBT16ToShort(fFlags); }
      61             :         // SVBT16 fComplex :1;// 0004 when 1, file is in complex, fast-saved format.
      62           0 :         sal_Bool fComplexGet()  { return static_cast< sal_Bool >((fFlagsGet() >> 2) & 1); }
      63             :     };
      64             : 
      65         118 :     int bRet = sal_False;
      66         118 :     rtl::OString aName( pName );
      67         118 :     if ( sHTML == aName )
      68           0 :         bRet = HTMLParser::IsHTMLFormat( pHeader, sal_True, RTL_TEXTENCODING_DONTKNOW );
      69         118 :     else if ( FILTER_RTF == aName )
      70         118 :         bRet = 0 == strncmp( "{\\rtf", pHeader, 5 );
      71           0 :     else if ( sWW5 == aName )
      72             :     {
      73           0 :         W1_FIB *pW1Header = (W1_FIB*)pHeader;
      74           0 :         if (pW1Header->wIdentGet() == 0xA5DC && pW1Header->nFibGet() == 0x65)
      75           0 :             bRet = true; /*WW5*/
      76           0 :         else if (pW1Header->wIdentGet() == 0xA5DB && pW1Header->nFibGet() == 0x2D)
      77           0 :             bRet = true; /*WW2*/
      78             :     }
      79           0 :     else if ( sWW1 == aName )
      80             :     {
      81           0 :         bRet = (( ((W1_FIB*)pHeader)->wIdentGet() == 0xA59C
      82           0 :                     && ((W1_FIB*)pHeader)->nFibGet() == 0x21)
      83           0 :                 && ((W1_FIB*)pHeader)->fComplexGet() == 0);
      84             :     }
      85           0 :     else if ( FILTER_TEXT == aName )
      86           0 :         bRet = SwIoSystem::IsDetectableText(pHeader, nLen_);
      87           0 :     else if ( FILTER_TEXT_DLG == aName)
      88           0 :         bRet = SwIoSystem::IsDetectableText( pHeader, nLen_, 0, 0, 0, true);
      89         118 :     return bRet ? pName : 0;
      90             : }
      91             : 
      92           8 : const String SwIoSystem::GetSubStorageName( const SfxFilter& rFltr )
      93             : {
      94             :     /* bei den StorageFiltern noch den SubStorageNamen setzen */
      95           8 :     const rtl::OUString& rUserData = rFltr.GetUserData();
      96          24 :     if (rUserData == FILTER_XML ||
      97           8 :         rUserData == FILTER_XMLV ||
      98           8 :         rUserData == FILTER_XMLVW)
      99           0 :         return rtl::OUString("content.xml");
     100           8 :     if (rUserData == sWW6 || rUserData == FILTER_WW8)
     101           8 :         return rtl::OUString("WordDocument");
     102           0 :     return rtl::OUString();
     103             : }
     104             : 
     105          29 : const SfxFilter* SwIoSystem::GetFilterOfFormat(const String& rFmtNm,
     106             :     const SfxFilterContainer* pCnt)
     107             : {
     108          29 :     SfxFilterContainer aCntSw( rtl::OUString(sSWRITER) );
     109          29 :     SfxFilterContainer aCntSwWeb( rtl::OUString(sSWRITERWEB) );
     110          29 :     const SfxFilterContainer* pFltCnt = pCnt ? pCnt : ( IsDocShellRegistered() ? &aCntSw : &aCntSwWeb );
     111             : 
     112           0 :     do {
     113          29 :         if( pFltCnt )
     114             :         {
     115          29 :             SfxFilterMatcher aMatcher( pFltCnt->GetName() );
     116          29 :             SfxFilterMatcherIter aIter( aMatcher );
     117          29 :             const SfxFilter* pFilter = aIter.First();
     118          58 :             while ( pFilter )
     119             :             {
     120          29 :                 if( pFilter->GetUserData().equals(rFmtNm) )
     121          29 :                     return pFilter;
     122           0 :                 pFilter = aIter.Next();
     123          29 :             }
     124             :         }
     125           0 :         if( pCnt || pFltCnt == &aCntSwWeb )
     126           0 :             break;
     127           0 :         pFltCnt = &aCntSwWeb;
     128             :     } while( true );
     129           0 :     return 0;
     130             : }
     131             : 
     132           0 : sal_Bool SwIoSystem::IsValidStgFilter( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rStg, const SfxFilter& rFilter)
     133             : {
     134           0 :     sal_Bool bRet = sal_False;
     135             :     try
     136             :     {
     137           0 :         sal_uLong nStgFmtId = SotStorage::GetFormatID( rStg );
     138           0 :         bRet = rStg->isStreamElement( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml")) );
     139           0 :         if ( bRet )
     140           0 :             bRet = ( nStgFmtId && ( rFilter.GetFormat() == nStgFmtId ) );
     141             :     }
     142           0 :     catch ( com::sun::star::uno::Exception& )
     143             :     {
     144             :     }
     145             : 
     146           0 :     return bRet;
     147             : }
     148             : 
     149           8 : sal_Bool SwIoSystem::IsValidStgFilter(SotStorage& rStg, const SfxFilter& rFilter)
     150             : {
     151           8 :     sal_uLong nStgFmtId = rStg.GetFormat();
     152             :     /*#i8409# We cannot trust the clipboard id anymore :-(*/
     153           8 :     if (rFilter.GetUserData() == FILTER_WW8 || rFilter.GetUserData() == sWW6)
     154           8 :         nStgFmtId = 0;
     155             : 
     156           8 :     sal_Bool bRet = SVSTREAM_OK == rStg.GetError() &&
     157           0 :         ( !nStgFmtId || rFilter.GetFormat() == nStgFmtId ) &&
     158          16 :         ( rStg.IsContained( SwIoSystem::GetSubStorageName( rFilter )) );
     159           8 :     if( bRet )
     160             :     {
     161             :         /* Bug 53445 - es gibt Excel Docs ohne ClipBoardId! */
     162             :         /* Bug 62703 - und auch WinWord Docs ohne ClipBoardId! */
     163           8 :         if (rFilter.GetUserData() == FILTER_WW8 || rFilter.GetUserData() == sWW6)
     164             :         {
     165          24 :             bRet = !((rStg.IsContained( rtl::OUString("0Table")) ||
     166          24 :                         rStg.IsContained( rtl::OUString("1Table"))) ^
     167          40 :                     (rFilter.GetUserData() == FILTER_WW8));
     168           8 :             if (bRet && !rFilter.IsAllowedAsTemplate())
     169             :             {
     170             :                 SotStorageStreamRef xRef =
     171             :                     rStg.OpenSotStream(rtl::OUString("WordDocument"),
     172           8 :                             STREAM_STD_READ | STREAM_NOCREATE );
     173           8 :                 xRef->Seek(10);
     174             :                 sal_uInt8 nByte;
     175           8 :                 *xRef >> nByte;
     176           8 :                 bRet = !(nByte & 1);
     177             :             }
     178             :         }
     179             :     }
     180           8 :     return bRet;
     181             : }
     182             : 
     183         118 : void TerminateBuffer(sal_Char *pBuffer, sal_uLong nBytesRead, sal_uLong nBufferLen)
     184             : {
     185             :     OSL_ENSURE(nBytesRead <= nBufferLen - 2,
     186             :             "what you read must be less than the max + null termination");
     187             :     OSL_ENSURE(!(nBufferLen & 0x00000001), "nMaxReadBuf must be an even number");
     188         118 :     if (nBytesRead <= nBufferLen - 2)
     189             :     {
     190         118 :         pBuffer[nBytesRead] = '\0';
     191         118 :         pBuffer[nBytesRead+1] = '\0';
     192         118 :         if (nBytesRead & 0x00000001)
     193          45 :             pBuffer[nBytesRead+2] = '\0';
     194             :     }
     195         118 : }
     196             : 
     197             : /* Feststellen ob das File in dem entsprechenden Format vorliegt. */
     198             : /* Z.z werden nur unsere eigene Filter unterstuetzt               */
     199          97 : sal_Bool SwIoSystem::IsFileFilter(SfxMedium& rMedium, const String& rFmtName)
     200             : {
     201          97 :     sal_Bool bRet = sal_False;
     202             : 
     203          97 :     SfxFilterContainer aCntSw( rtl::OUString(sSWRITER) );
     204          97 :     SfxFilterContainer aCntSwWeb( rtl::OUString(sSWRITERWEB) );
     205          97 :     const SfxFilterContainer& rFltContainer = IsDocShellRegistered() ? aCntSw : aCntSwWeb;
     206             : 
     207          97 :     com::sun::star::uno::Reference < com::sun::star::embed::XStorage > xStor;
     208          97 :     SotStorageRef xStg;
     209          97 :     if (rMedium.IsStorage())
     210           0 :         xStor = rMedium.GetStorage();
     211             :     else
     212             :     {
     213          97 :         SvStream* pStream = rMedium.GetInStream();
     214          97 :         if ( pStream && SotStorage::IsStorageFile(pStream) )
     215           8 :             xStg = new SotStorage( pStream, sal_False );
     216             :     }
     217             : 
     218          97 :     SfxFilterMatcher aMatcher( rFltContainer.GetName() );
     219          97 :     SfxFilterMatcherIter aIter( aMatcher );
     220          97 :     const SfxFilter* pFltr = aIter.First();
     221         194 :     while ( pFltr )
     222             :     {
     223          97 :         const rtl::OUString& rUserData = pFltr->GetUserData();
     224          97 :         if (rUserData.equals(rFmtName))
     225             :         {
     226          97 :             if( 'C' == rUserData[0] )
     227             :             {
     228           8 :                 if ( xStor.is() )
     229           0 :                     bRet = IsValidStgFilter( xStor, *pFltr );
     230           8 :                 else if ( xStg.Is() )
     231           8 :                     bRet = IsValidStgFilter( *xStg, *pFltr );
     232             :             }
     233          89 :             else if( !xStg.Is() && !xStor.is() )
     234             :             {
     235          89 :                 SvStream* pStrm = rMedium.GetInStream();
     236          89 :                 if( pStrm && !pStrm->GetError() )
     237             :                 {
     238             :                     sal_Char aBuffer[4098];
     239          89 :                     const sal_uLong nMaxRead = sizeof(aBuffer) - 2;
     240          89 :                     sal_uLong nBytesRead = pStrm->Read(aBuffer, nMaxRead);
     241          89 :                     pStrm->Seek(STREAM_SEEK_TO_BEGIN);
     242          89 :                     TerminateBuffer(aBuffer, nBytesRead, sizeof(aBuffer));
     243          89 :                     for (sal_uInt16 i = 0; i < MAXFILTER; ++i)
     244             :                     {
     245          89 :                         if (aFilterDetect[i].IsFilter(rFmtName))
     246             :                         {
     247          89 :                             bRet = 0 != aFilterDetect[i].IsReader( aBuffer, nBytesRead,
     248         178 :                                     rMedium.GetPhysicalName(), rUserData );
     249          89 :                             break;
     250             :                         }
     251             :                     }
     252             :                 }
     253             :             }
     254             :             //The same underlying filter can appear multiple times in the
     255             :             //filter list, e.g. CWW8 filter twice, once for .doc and once for
     256             :             //.dot.  We just care here if its either, not enforce that it's
     257             :             //both which would be a bit of an odd requirement
     258          97 :             if (bRet)
     259          97 :                 break;
     260             :         }
     261             : 
     262           0 :         pFltr = aIter.Next();
     263             :     }
     264             : 
     265          97 :     return bRet;
     266             : }
     267             : 
     268             : /* die Methode stellt fest, von welchem Typ der stream (File) ist.        */
     269             : /* Es wird versucht, eine dem Filter entsprechende Byte-Folge zu finden.  */
     270             : /* Wird kein entsprechender gefunden, wird zur Zeit der ASCII-Reader      */
     271             : /* returnt !! Der Returnwert ist der interne Filtername!                  */
     272             : /* rPrefFltName ist der interne Name des Filters, den der Benutzer im     */
     273             : /* Open-Dialog eingestellt hat.                                           */
     274          29 : const SfxFilter* SwIoSystem::GetFileFilter(const String& rFileName,
     275             :     const String& rPrefFltName, SfxMedium* pMedium)
     276             : {
     277          29 :     SfxFilterContainer aCntSw( rtl::OUString(sSWRITER) );
     278          29 :     SfxFilterContainer aCntSwWeb( rtl::OUString(sSWRITERWEB) );
     279          29 :     const SfxFilterContainer* pFCntnr = IsDocShellRegistered() ? &aCntSw : &aCntSwWeb;
     280             : 
     281          29 :     if( !pFCntnr )
     282           0 :         return 0;
     283             : 
     284          29 :     SfxFilterMatcher aMatcher( pFCntnr->GetName() );
     285          29 :     SfxFilterMatcherIter aIter( aMatcher );
     286          29 :     const SfxFilter* pFilter = aIter.First();
     287          29 :     if ( !pFilter )
     288           0 :         return 0;
     289             : 
     290          29 :     if( pMedium ? ( pMedium->IsStorage() || SotStorage::IsStorageFile( pMedium->GetInStream() ) ) : SotStorage::IsStorageFile( rFileName ) )
     291             :     {
     292             :         // package storage or OLEStorage based format
     293           0 :         SotStorageRef xStg;
     294           0 :         if (!pMedium )
     295             :         {
     296           0 :             INetURLObject aObj;
     297           0 :             aObj.SetSmartProtocol( INET_PROT_FILE );
     298           0 :             aObj.SetSmartURL( rFileName );
     299           0 :             pMedium = new SfxMedium( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
     300             :         }
     301             : 
     302             :         // templates should not get precedence over "normal" filters (#i35508, #i33168)
     303           0 :         const SfxFilter* pTemplateFilter = 0;
     304           0 :         const SfxFilter* pOldFilter = pFCntnr->GetFilter4FilterName( rPrefFltName );
     305           0 :         bool bLookForTemplate = pOldFilter && pOldFilter->IsOwnTemplateFormat();
     306           0 :         if ( pMedium->IsStorage() )
     307             :         {
     308           0 :             com::sun::star::uno::Reference < com::sun::star::embed::XStorage > xStor = pMedium->GetStorage();
     309           0 :             if ( xStor.is() )
     310             :             {
     311           0 :                 while ( pFilter )
     312             :                 {
     313           0 :                     if( 'C' == pFilter->GetUserData()[0] && IsValidStgFilter( xStor, *pFilter ) )
     314             :                     {
     315           0 :                         if ( pFilter->IsOwnTemplateFormat() && !bLookForTemplate )
     316             :                             // found template filter; maybe there's a "normal" one also
     317           0 :                             pTemplateFilter = pFilter;
     318             :                         else
     319           0 :                             return pFilter;
     320             :                     }
     321             : 
     322           0 :                     pFilter = aIter.Next();
     323             :                 }
     324             : 
     325             :                 // there's only a template filter that could be found
     326           0 :                 if ( pTemplateFilter )
     327           0 :                     pFilter = pTemplateFilter;
     328           0 :             }
     329             :         }
     330             :         else
     331             :         {
     332           0 :             SvStream* pStream = pMedium->GetInStream();
     333           0 :             if ( pStream && SotStorage::IsStorageFile(pStream) )
     334           0 :                 xStg = new SotStorage( pStream, sal_False );
     335             : 
     336           0 :             if( xStg.Is() && ( xStg->GetError() == SVSTREAM_OK ) )
     337             :             {
     338           0 :                 while ( pFilter )
     339             :                 {
     340           0 :                     if( 'C' == pFilter->GetUserData()[0] && IsValidStgFilter( *xStg, *pFilter ) )
     341             :                     {
     342           0 :                         if ( pFilter->IsOwnTemplateFormat() && !bLookForTemplate )
     343             :                             // found template filter; maybe there's a "normal" one also
     344           0 :                             pTemplateFilter = pFilter;
     345             :                         else
     346           0 :                             return pFilter;
     347             :                     }
     348             : 
     349           0 :                     pFilter = aIter.Next();
     350             :                 }
     351             : 
     352             :                 // there's only a template filter that could be found
     353           0 :                 if ( pTemplateFilter )
     354           0 :                     pFilter = pTemplateFilter;
     355             : 
     356             :             }
     357             :         }
     358             : 
     359           0 :         return pFilter;
     360             :     }
     361             : 
     362             :     sal_Char aBuffer[4098];
     363          29 :     const sal_uLong nMaxRead = sizeof(aBuffer) - 2;
     364          29 :     sal_uLong nBytesRead = 0;
     365          29 :     if (pMedium)
     366             :     {
     367          29 :         SvStream* pIStrm = pMedium->GetInStream();
     368          29 :         if( !pIStrm || SVSTREAM_OK != pIStrm->GetError() )
     369           0 :             return 0;
     370          29 :         sal_uLong nCurrPos = pIStrm->Tell();
     371          29 :         nBytesRead = pIStrm->Read(aBuffer, nMaxRead);
     372          29 :         pIStrm->Seek( nCurrPos );
     373             :     }
     374             : 
     375          29 :     TerminateBuffer(aBuffer, nBytesRead, sizeof(aBuffer));
     376             : 
     377             : 
     378             :     /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
     379             :     /* suche nach dem bestimmten Filter, falls kein entsprechender        */
     380             :     /* gefunden wird, so wird der ASCII-Filter returnt.                   */
     381             :     /* Gibt es Filter ohne einen Identifizierungs-String, so werden diese */
     382             :     /* nie erkannt und es wird auch der ASCII-Filter returnt.             */
     383             :     /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
     384             :     {
     385          29 :         const SfxFilter* pFilterTmp = 0;
     386             :         const sal_Char* pNm;
     387          29 :         for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
     388             :         {
     389          29 :             String sEmptyUserData;
     390          29 :             pNm = aFilterDetect[n].IsReader(aBuffer, nBytesRead, rFileName, sEmptyUserData);
     391          29 :             pFilterTmp = pNm ? SwIoSystem::GetFilterOfFormat(rtl::OUString::createFromAscii(pNm), pFCntnr) : 0;
     392          29 :             if (pNm && pFilterTmp)
     393             :             {
     394          29 :                 return pFilterTmp;
     395             :             }
     396          29 :         }
     397             :     }
     398             : 
     399             :     /* Ok, bis jetzt kein Filter gefunden, also befrage mal die */
     400             :     /* "WORD 4 WORD" Filter                                     */
     401           0 :     if( rFileName.Len() )
     402             :     {
     403           0 :         if( pMedium )
     404           0 :             pMedium->CloseInStream();
     405             : 
     406             :     }
     407           0 :     return SwIoSystem::GetTextFilter( aBuffer, nBytesRead);
     408             : }
     409             : 
     410           0 : bool SwIoSystem::IsDetectableText(const sal_Char* pBuf, sal_uLong &rLen,
     411             :     CharSet *pCharSet, bool *pSwap, LineEnd *pLineEnd, bool bEncodedFilter)
     412             : {
     413           0 :     bool bSwap = false;
     414           0 :     CharSet eCharSet = RTL_TEXTENCODING_DONTKNOW;
     415           0 :     bool bLE = true;
     416             :     /*See if its a known unicode type*/
     417           0 :     if (rLen >= 2)
     418             :     {
     419           0 :         sal_uLong nHead=0;
     420           0 :         if (rLen > 2 && sal_uInt8(pBuf[0]) == 0xEF && sal_uInt8(pBuf[1]) == 0xBB &&
     421           0 :             sal_uInt8(pBuf[2]) == 0xBF)
     422             :         {
     423           0 :             eCharSet = RTL_TEXTENCODING_UTF8;
     424           0 :             nHead = 3;
     425             :         }
     426           0 :         else if (sal_uInt8(pBuf[0]) == 0xFE && sal_uInt8(pBuf[1]) == 0xFF)
     427             :         {
     428           0 :             eCharSet = RTL_TEXTENCODING_UCS2;
     429           0 :             bLE = false;
     430           0 :             nHead = 2;
     431             :         }
     432           0 :         else if (sal_uInt8(pBuf[1]) == 0xFE && sal_uInt8(pBuf[0]) == 0xFF)
     433             :         {
     434           0 :             eCharSet = RTL_TEXTENCODING_UCS2;
     435           0 :             nHead = 2;
     436             :         }
     437           0 :         pBuf+=nHead;
     438           0 :         rLen-=nHead;
     439             :     }
     440             : 
     441           0 :     bool bCR = false, bLF = false, bIsBareUnicode = false;
     442             : 
     443           0 :     if (eCharSet != RTL_TEXTENCODING_DONTKNOW)
     444             :     {
     445           0 :         boost::scoped_array<sal_Unicode> aWork(new sal_Unicode[rLen+1]);
     446           0 :         sal_Unicode *pNewBuf = aWork.get();
     447             :         sal_Size nNewLen;
     448           0 :         if (eCharSet != RTL_TEXTENCODING_UCS2)
     449             :         {
     450           0 :             nNewLen = rLen;
     451             :             rtl_TextToUnicodeConverter hConverter =
     452           0 :                 rtl_createTextToUnicodeConverter(eCharSet);
     453             :             rtl_TextToUnicodeContext hContext =
     454           0 :                 rtl_createTextToUnicodeContext(hConverter);
     455             : 
     456             :             sal_Size nCntBytes;
     457             :             sal_uInt32 nInfo;
     458             :             nNewLen = rtl_convertTextToUnicode( hConverter, hContext, pBuf,
     459             :                 rLen, pNewBuf, nNewLen,
     460             :                 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT |
     461             :                   RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT |
     462           0 :                   RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT), &nInfo, &nCntBytes);
     463             : 
     464           0 :             rtl_destroyTextToUnicodeContext(hConverter, hContext);
     465           0 :             rtl_destroyTextToUnicodeConverter(hConverter);
     466             :         }
     467             :         else
     468             :         {
     469           0 :             nNewLen = rLen/2;
     470           0 :             memcpy(pNewBuf, pBuf, rLen);
     471             : #ifdef OSL_LITENDIAN
     472           0 :             bool bNativeLE = true;
     473             : #else
     474             :             bool bNativeLE = false;
     475             : #endif
     476           0 :             if (bLE != bNativeLE)
     477             :             {
     478           0 :                 bSwap = true;
     479           0 :                 sal_Char* pF = (sal_Char*)pNewBuf;
     480           0 :                 sal_Char* pN = pF+1;
     481           0 :                 for(xub_StrLen n = 0; n < nNewLen; ++n, pF+=2, pN+=2)
     482             :                 {
     483           0 :                     sal_Char c = *pF;
     484           0 :                     *pF = *pN;
     485           0 :                     *pN = c;
     486             :                 }
     487             :             }
     488             :         }
     489             : 
     490           0 :         for (sal_uLong nCnt = 0; nCnt < nNewLen; ++nCnt, ++pNewBuf)
     491             :         {
     492           0 :             switch (*pNewBuf)
     493             :             {
     494             :                 case 0xA:
     495           0 :                     bLF = true;
     496           0 :                     break;
     497             :                 case 0xD:
     498           0 :                     bCR = true;
     499           0 :                     break;
     500             :                 default:
     501           0 :                     break;
     502             :             }
     503           0 :         }
     504             :     }
     505             :     else
     506             :     {
     507           0 :         for( sal_uLong nCnt = 0; nCnt < rLen; ++nCnt, ++pBuf )
     508             :         {
     509           0 :             switch (*pBuf)
     510             :             {
     511             :                 case 0x0:
     512           0 :                     if( nCnt + 1 < rLen && !*(pBuf+1) )
     513           0 :                         return 0;
     514           0 :                     bIsBareUnicode = true;
     515           0 :                     break;
     516             :                 case 0xA:
     517           0 :                     bLF = true;
     518           0 :                     break;
     519             :                 case 0xD:
     520           0 :                     bCR = true;
     521           0 :                     break;
     522             :                 case 0xC:
     523             :                 case 0x1A:
     524             :                 case 0x9:
     525           0 :                     break;
     526             :                 default:
     527           0 :                     break;
     528             :             }
     529             :         }
     530             :     }
     531             : 
     532           0 :     LineEnd eSysLE = GetSystemLineEnd();
     533             :     LineEnd eLineEnd;
     534           0 :     if (!bCR && !bLF)
     535           0 :         eLineEnd = eSysLE;
     536             :     else
     537           0 :         eLineEnd = bCR ? ( bLF ? LINEEND_CRLF : LINEEND_CR ) : LINEEND_LF;
     538             : 
     539           0 :     if (pCharSet)
     540           0 :         *pCharSet = eCharSet;
     541           0 :     if (pSwap)
     542           0 :         *pSwap = bSwap;
     543           0 :     if (pLineEnd)
     544           0 :         *pLineEnd = eLineEnd;
     545             : 
     546           0 :     return bEncodedFilter || (!bIsBareUnicode && eSysLE == eLineEnd);
     547             : }
     548             : 
     549           0 : const SfxFilter* SwIoSystem::GetTextFilter( const sal_Char* pBuf, sal_uLong nLen)
     550             : {
     551           0 :     bool bAuto = IsDetectableText(pBuf, nLen);
     552           0 :     const sal_Char* pNm = bAuto ? FILTER_TEXT : FILTER_TEXT_DLG;
     553           0 :     return SwIoSystem::GetFilterOfFormat( rtl::OUString::createFromAscii(pNm), 0 );
     554          30 : }
     555             : 
     556             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10