LCOV - code coverage report
Current view: top level - sw/source/filter/ascii - parasc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 150 229 65.5 %
Date: 2012-08-25 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 113 298 37.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <boost/scoped_array.hpp>
      30                 :            : #include <tools/stream.hxx>
      31                 :            : #include <hintids.hxx>
      32                 :            : #include <rtl/tencinfo.h>
      33                 :            : #include <sfx2/printer.hxx>
      34                 :            : #include <editeng/fontitem.hxx>
      35                 :            : #include <editeng/langitem.hxx>
      36                 :            : #include <editeng/brkitem.hxx>
      37                 :            : #include <editeng/scripttypeitem.hxx>
      38                 :            : #include <shellio.hxx>
      39                 :            : #include <doc.hxx>
      40                 :            : #include <swtypes.hxx>
      41                 :            : #include <ndtxt.hxx>
      42                 :            : #include <pam.hxx>
      43                 :            : #include <frmatr.hxx>
      44                 :            : #include <fltini.hxx>
      45                 :            : #include <pagedesc.hxx>
      46                 :            : #include <breakit.hxx>
      47                 :            : #include <swerror.h>
      48                 :            : #include <statstr.hrc>          // ResId for the status bar
      49                 :            : #include <mdiexp.hxx>           // ...Percent()
      50                 :            : #include <poolfmt.hxx>
      51                 :            : 
      52                 :            : #include "vcl/metric.hxx"
      53                 :            : 
      54                 :            : #define ASC_BUFFLEN 4096
      55                 :            : 
      56                 :            : class SwASCIIParser
      57                 :            : {
      58                 :            :     SwDoc* pDoc;
      59                 :            :     SwPaM* pPam;
      60                 :            :     SvStream& rInput;
      61                 :            :     sal_Char* pArr;
      62                 :            :     const SwAsciiOptions& rOpt;
      63                 :            :     SfxItemSet* pItemSet;
      64                 :            :     long nFileSize;
      65                 :            :     sal_uInt16 nScript;
      66                 :            :     bool bNewDoc;
      67                 :            : 
      68                 :            :     sal_uLong ReadChars();
      69                 :            :     void InsertText( const String& rStr );
      70                 :            : 
      71                 :            : public:
      72                 :            :     SwASCIIParser( SwDoc* pD, const SwPaM& rCrsr, SvStream& rIn,
      73                 :            :                             int bReadNewDoc, const SwAsciiOptions& rOpts );
      74                 :            :     ~SwASCIIParser();
      75                 :            : 
      76                 :            :     sal_uLong CallParser();
      77                 :            : };
      78                 :            : 
      79                 :            : 
      80                 :            : // Call for the general reader interface
      81                 :          9 : sal_uLong AsciiReader::Read( SwDoc &rDoc, const String&, SwPaM &rPam, const String & )
      82                 :            : {
      83         [ -  + ]:          9 :     if( !pStrm )
      84                 :            :     {
      85                 :            :         OSL_ENSURE( !this, "ASCII read without a stream" );
      86                 :          0 :         return ERR_SWG_READ_ERROR;
      87                 :            :     }
      88                 :            : 
      89                 :            :     SwASCIIParser* pParser = new SwASCIIParser( &rDoc, rPam, *pStrm,
      90         [ +  - ]:          9 :                                         !bInsertMode, aOpt.GetASCIIOpts() );
      91                 :          9 :     sal_uLong nRet = pParser->CallParser();
      92                 :            : 
      93         [ +  - ]:          9 :     delete pParser;
      94                 :            :     // after Read reset the options
      95                 :          9 :     aOpt.ResetASCIIOpts();
      96                 :          9 :     return nRet;
      97                 :            : }
      98                 :            : 
      99                 :          9 : SwASCIIParser::SwASCIIParser(SwDoc* pD, const SwPaM& rCrsr, SvStream& rIn,
     100                 :            :     int bReadNewDoc, const SwAsciiOptions& rOpts)
     101                 :            :     : pDoc(pD), rInput(rIn), rOpt(rOpts), nFileSize(0), nScript(0)
     102                 :          9 :     , bNewDoc(bReadNewDoc)
     103                 :            : {
     104         [ +  - ]:          9 :     pPam = new SwPaM( *rCrsr.GetPoint() );
     105                 :          9 :     pArr = new sal_Char [ ASC_BUFFLEN + 2 ];
     106                 :            : 
     107                 :          9 :     pItemSet = new SfxItemSet( pDoc->GetAttrPool(),
     108                 :            :                 RES_CHRATR_FONT,        RES_CHRATR_LANGUAGE,
     109                 :            :                 RES_CHRATR_CJK_FONT,    RES_CHRATR_CJK_LANGUAGE,
     110                 :            :                 RES_CHRATR_CTL_FONT,    RES_CHRATR_CTL_LANGUAGE,
     111         [ +  - ]:          9 :                 0 );
     112                 :            : 
     113                 :            :     // set defaults from the options
     114         [ +  - ]:          9 :     if( rOpt.GetLanguage() )
     115                 :            :     {
     116                 :          9 :         SvxLanguageItem aLang( (LanguageType)rOpt.GetLanguage(),
     117         [ +  - ]:          9 :                                  RES_CHRATR_LANGUAGE );
     118         [ +  - ]:          9 :         pItemSet->Put( aLang );
     119         [ +  - ]:          9 :         pItemSet->Put( aLang, RES_CHRATR_CJK_LANGUAGE );
     120 [ +  - ][ +  - ]:          9 :         pItemSet->Put( aLang, RES_CHRATR_CTL_LANGUAGE );
     121                 :            :     }
     122         [ +  - ]:          9 :     if( rOpt.GetFontName().Len() )
     123                 :            :     {
     124         [ +  - ]:          9 :         Font aTextFont( rOpt.GetFontName(), Size( 0, 10 ) );
     125 [ +  - ][ -  + ]:          9 :         if( pDoc->getPrinter( false ) )
     126 [ #  # ][ #  # ]:          0 :             aTextFont = pDoc->getPrinter( false )->GetFontMetric( aTextFont );
         [ #  # ][ #  # ]
     127         [ +  - ]:          9 :         SvxFontItem aFont( aTextFont.GetFamily(), aTextFont.GetName(),
     128 [ +  - ][ +  - ]:         18 :                            aEmptyStr, aTextFont.GetPitch(), aTextFont.GetCharSet(), RES_CHRATR_FONT );
         [ +  - ][ +  - ]
     129         [ +  - ]:          9 :         pItemSet->Put( aFont );
     130         [ +  - ]:          9 :         pItemSet->Put( aFont, RES_CHRATR_CJK_FONT );
     131 [ +  - ][ +  - ]:          9 :         pItemSet->Put( aFont, RES_CHRATR_CTL_FONT );
                 [ +  - ]
     132                 :            :     }
     133                 :          9 : }
     134                 :            : 
     135                 :          9 : SwASCIIParser::~SwASCIIParser()
     136                 :            : {
     137         [ +  - ]:          9 :     delete pPam;
     138         [ +  - ]:          9 :     delete [] pArr;
     139         [ -  + ]:          9 :     delete pItemSet;
     140                 :          9 : }
     141                 :            : 
     142                 :            : 
     143                 :            : // Calling the parser
     144                 :          9 : sal_uLong SwASCIIParser::CallParser()
     145                 :            : {
     146                 :          9 :     rInput.Seek(STREAM_SEEK_TO_END);
     147                 :          9 :     rInput.ResetError();
     148                 :            : 
     149                 :          9 :     nFileSize = rInput.Tell();
     150                 :          9 :     rInput.Seek(STREAM_SEEK_TO_BEGIN);
     151                 :          9 :     rInput.ResetError();
     152                 :            : 
     153                 :          9 :     ::StartProgress( STR_STATSTR_W4WREAD, 0, nFileSize, pDoc->GetDocShell() );
     154                 :            : 
     155                 :          9 :     SwPaM* pInsPam = 0;
     156                 :          9 :     xub_StrLen nSttCntnt = 0;
     157         [ -  + ]:          9 :     if (!bNewDoc)
     158                 :            :     {
     159                 :          0 :         const SwNodeIndex& rTmp = pPam->GetPoint()->nNode;
     160         [ #  # ]:          0 :         pInsPam = new SwPaM( rTmp, rTmp, 0, -1 );
     161                 :          0 :         nSttCntnt = pPam->GetPoint()->nContent.GetIndex();
     162                 :            :     }
     163                 :            : 
     164                 :          9 :     SwTxtFmtColl *pColl = 0;
     165                 :            : 
     166         [ +  - ]:          9 :     if (bNewDoc)
     167                 :            :     {
     168                 :          9 :         pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_HTML_PRE, false);
     169         [ -  + ]:          9 :         if (!pColl)
     170                 :          0 :             pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD,false);
     171         [ +  - ]:          9 :         if (pColl)
     172                 :          9 :             pDoc->SetTxtFmtColl(*pPam, pColl);
     173                 :            :     }
     174                 :            : 
     175                 :          9 :     sal_uLong nError = ReadChars();
     176                 :            : 
     177         [ +  - ]:          9 :     if( pItemSet )
     178                 :            :     {
     179                 :            :         // set only the attribute, for scanned scripts.
     180         [ -  + ]:          9 :         if( !( SCRIPTTYPE_LATIN & nScript ))
     181                 :            :         {
     182                 :          0 :             pItemSet->ClearItem( RES_CHRATR_FONT );
     183                 :          0 :             pItemSet->ClearItem( RES_CHRATR_LANGUAGE );
     184                 :            :         }
     185         [ +  + ]:          9 :         if( !( SCRIPTTYPE_ASIAN & nScript ))
     186                 :            :         {
     187                 :          6 :             pItemSet->ClearItem( RES_CHRATR_CJK_FONT );
     188                 :          6 :             pItemSet->ClearItem( RES_CHRATR_CJK_LANGUAGE );
     189                 :            :         }
     190         [ +  + ]:          9 :         if( !( SCRIPTTYPE_COMPLEX & nScript ))
     191                 :            :         {
     192                 :          6 :             pItemSet->ClearItem( RES_CHRATR_CTL_FONT );
     193                 :          6 :             pItemSet->ClearItem( RES_CHRATR_CTL_LANGUAGE );
     194                 :            :         }
     195         [ +  - ]:          9 :         if( pItemSet->Count() )
     196                 :            :         {
     197         [ +  - ]:          9 :             if( bNewDoc )
     198                 :            :             {
     199         [ +  - ]:          9 :                 if (pColl)
     200                 :            :                 {
     201                 :            :                     // Using the pool defaults for the font causes significant
     202                 :            :                     // trouble for the HTML filter, because it is not able
     203                 :            :                     // to export the pool defaults (or to be more precise:
     204                 :            :                     // the HTML filter is not able to detect whether a pool
     205                 :            :                     // default has changed or not. Even a comparison with the
     206                 :            :                     // HTMLi template does not work, because the defaults are
     207                 :            :                     // not copied when a new doc is created. The result of
     208                 :            :                     // comparing pool defaults therefor would be that the
     209                 :            :                     // defaults are exported always if the have changed for
     210                 :            :                     // text documents in general. That's not sensible, as well
     211                 :            :                     // as it is not sensible to export them always.
     212                 :            :                     sal_uInt16 aWhichIds[4] =
     213                 :            :                     {
     214                 :            :                         RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
     215                 :            :                         RES_CHRATR_CTL_FONT, 0
     216                 :          9 :                     };
     217                 :          9 :                     sal_uInt16 *pWhichIds = aWhichIds;
     218         [ +  + ]:         36 :                     while (*pWhichIds)
     219                 :            :                     {
     220                 :            :                         const SfxPoolItem *pItem;
     221         [ +  + ]:         27 :                         if (SFX_ITEM_SET == pItemSet->GetItemState(*pWhichIds,
     222         [ +  - ]:         27 :                             false, &pItem))
     223                 :            :                         {
     224         [ +  - ]:         15 :                             pColl->SetFmtAttr( *pItem );
     225         [ +  - ]:         15 :                             pItemSet->ClearItem( *pWhichIds );
     226                 :            :                         }
     227                 :         27 :                         ++pWhichIds;
     228                 :            :                     }
     229                 :            :                 }
     230         [ +  - ]:          9 :                 if (pItemSet->Count())
     231                 :          9 :                     pDoc->SetDefault(*pItemSet);
     232                 :            :             }
     233         [ #  # ]:          0 :             else if( pInsPam )
     234                 :            :             {
     235                 :            :                 // then set over the insert range the defined attributes
     236                 :          0 :                 *pInsPam->GetMark() = *pPam->GetPoint();
     237                 :          0 :                 pInsPam->GetPoint()->nNode++;
     238                 :          0 :                 pInsPam->GetPoint()->nContent.Assign(
     239         [ #  # ]:          0 :                                     pInsPam->GetCntntNode(), nSttCntnt );
     240                 :            : 
     241                 :            :                 // !!!!!
     242                 :            :                 OSL_ENSURE( !this, "Have to change - hard attr. to para. style" );
     243                 :          0 :                 pDoc->InsertItemSet( *pInsPam, *pItemSet, 0 );
     244                 :            :             }
     245                 :            :         }
     246         [ +  - ]:          9 :         delete pItemSet, pItemSet = 0;
     247                 :            :     }
     248                 :            : 
     249         [ -  + ]:          9 :     delete pInsPam;
     250                 :            : 
     251                 :          9 :     ::EndProgress( pDoc->GetDocShell() );
     252                 :          9 :     return nError;
     253                 :            : }
     254                 :            : 
     255                 :          9 : sal_uLong SwASCIIParser::ReadChars()
     256                 :            : {
     257                 :          9 :     sal_Unicode *pStt = 0, *pEnd = 0, *pLastStt = 0;
     258                 :          9 :     long nReadCnt = 0, nLineLen = 0;
     259                 :          9 :     sal_Unicode cLastCR = 0;
     260                 :          9 :     bool bSwapUnicode = false;
     261                 :            : 
     262                 :          9 :     const SwAsciiOptions *pUseMe=&rOpt;
     263         [ +  - ]:          9 :     SwAsciiOptions aEmpty;
     264 [ +  - ][ -  +  :         18 :     if (nFileSize >= 2 &&
          #  #  #  #  #  
              # ][ -  + ]
     265         [ +  - ]:          9 :         aEmpty.GetFontName() == rOpt.GetFontName() &&
     266                 :          0 :         aEmpty.GetCharSet() == rOpt.GetCharSet() &&
     267                 :          0 :         aEmpty.GetLanguage() == rOpt.GetLanguage() &&
     268                 :          0 :         aEmpty.GetParaFlags() == rOpt.GetParaFlags())
     269                 :            :     {
     270                 :            :         sal_uLong nLen, nOrig;
     271         [ #  # ]:          0 :         nOrig = nLen = rInput.Read(pArr, ASC_BUFFLEN);
     272                 :            :         CharSet eCharSet;
     273         [ #  # ]:          0 :         bool bRet = SwIoSystem::IsDetectableText(pArr, nLen, &eCharSet, &bSwapUnicode);
     274                 :            :         OSL_ENSURE(bRet, "Autodetect of text import without nag dialog must "
     275                 :            :             "have failed");
     276 [ #  # ][ #  # ]:          0 :         if (bRet && eCharSet != RTL_TEXTENCODING_DONTKNOW)
     277                 :            :         {
     278                 :          0 :             aEmpty.SetCharSet(eCharSet);
     279         [ #  # ]:          0 :             rInput.SeekRel(-(long(nLen)));
     280                 :            :         }
     281                 :            :         else
     282         [ #  # ]:          0 :             rInput.SeekRel(-(long(nOrig)));
     283                 :          0 :         pUseMe=&aEmpty;
     284                 :            :     }
     285                 :            : 
     286                 :          9 :     rtl_TextToUnicodeConverter hConverter=0;
     287                 :          9 :     rtl_TextToUnicodeContext hContext=0;
     288                 :          9 :     CharSet currentCharSet = pUseMe->GetCharSet();
     289         [ +  - ]:          9 :     if (RTL_TEXTENCODING_UCS2 != currentCharSet)
     290                 :            :     {
     291         [ -  + ]:          9 :         if( currentCharSet == RTL_TEXTENCODING_DONTKNOW )
     292                 :          0 :                 currentCharSet = RTL_TEXTENCODING_ASCII_US;
     293         [ +  - ]:          9 :         hConverter = rtl_createTextToUnicodeConverter( currentCharSet );
     294                 :            :         OSL_ENSURE( hConverter, "no string convert available" );
     295         [ -  + ]:          9 :         if (!hConverter)
     296                 :          0 :             return ERROR_SW_READ_BASE;
     297                 :          9 :         bSwapUnicode = false;
     298         [ +  - ]:          9 :         hContext = rtl_createTextToUnicodeContext( hConverter );
     299                 :            :     }
     300         [ #  # ]:          0 :     else if (pUseMe != &aEmpty)  //Already successfully figured out type
     301                 :            :     {
     302         [ #  # ]:          0 :         rInput.StartReadingUnicodeText( currentCharSet );
     303                 :          0 :         bSwapUnicode = rInput.IsEndianSwap();
     304                 :            :     }
     305                 :            : 
     306                 :          9 :     boost::scoped_array<sal_Unicode> aWork;
     307                 :          9 :     sal_uLong nArrOffset = 0;
     308                 :            : 
     309                 :      60540 :     do {
     310         [ +  + ]:      60549 :         if( pStt >= pEnd )
     311                 :            :         {
     312         [ +  + ]:         30 :             if( pLastStt != pStt )
     313 [ +  - ][ +  - ]:         21 :                 InsertText( rtl::OUString( pLastStt ));
                 [ +  - ]
     314                 :            : 
     315                 :            :             // Read a new block
     316                 :            :             sal_uLong lGCount;
     317 [ +  - ][ +  - ]:         30 :             if( SVSTREAM_OK != rInput.GetError() || 0 == (lGCount =
         [ +  + ][ +  + ]
     318                 :         30 :                         rInput.Read( pArr + nArrOffset,
     319                 :         60 :                                      ASC_BUFFLEN - nArrOffset )))
     320                 :          9 :                 break;      // break from the while loop
     321                 :            : 
     322                 :            :             /*
     323                 :            :             If there was some unconverted bytes on the last cycle then they
     324                 :            :             were put at the beginning of the array, so total bytes available
     325                 :            :             to convert this cycle includes them. If we found 0 following bytes
     326                 :            :             then we ignore the previous partial character.
     327                 :            :             */
     328                 :         21 :             lGCount+=nArrOffset;
     329                 :            : 
     330         [ +  - ]:         21 :             if( hConverter )
     331                 :            :             {
     332                 :            :                 sal_uInt32 nInfo;
     333                 :         21 :                 sal_Size nNewLen = lGCount, nCntBytes;
     334 [ +  - ][ +  - ]:         21 :                 aWork.reset(new sal_Unicode[nNewLen + 1]); // add 1 for '\0'
     335                 :         21 :                 sal_Unicode* pBuf = aWork.get();
     336                 :            : 
     337                 :            :                 nNewLen = rtl_convertTextToUnicode( hConverter, hContext,
     338                 :            :                                 pArr, lGCount, pBuf, nNewLen,
     339                 :            :                                 (
     340                 :            :                                 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT |
     341                 :            :                                 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT |
     342                 :            :                                 RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT |
     343                 :            :                                 RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE
     344                 :            :                                 ),
     345                 :            :                                 &nInfo,
     346         [ +  - ]:         21 :                                 &nCntBytes );
     347         [ -  + ]:         21 :                 if( 0 != ( nArrOffset = lGCount - nCntBytes ) )
     348                 :          0 :                     memmove( pArr, pArr + nCntBytes, nArrOffset );
     349                 :            : 
     350                 :         21 :                 pStt = pLastStt = aWork.get();
     351                 :         21 :                 pEnd = pStt + nNewLen;
     352                 :            :             }
     353                 :            :             else
     354                 :            :             {
     355                 :          0 :                 pStt = pLastStt = (sal_Unicode*)pArr;
     356                 :          0 :                 pEnd = (sal_Unicode*)(pArr + lGCount);
     357                 :            : 
     358         [ #  # ]:          0 :                 if( bSwapUnicode )
     359                 :            :                 {
     360                 :          0 :                     sal_Char* pF = pArr, *pN = pArr + 1;
     361         [ #  # ]:          0 :                     for( sal_uLong n = 0; n < lGCount; n += 2, pF += 2, pN += 2 )
     362                 :            :                     {
     363                 :          0 :                         sal_Char c = *pF;
     364                 :          0 :                         *pF = *pN;
     365                 :          0 :                         *pN = c;
     366                 :            :                     }
     367                 :            :                 }
     368                 :            :             }
     369                 :            : 
     370                 :         21 :             *pEnd = 0;
     371                 :         21 :             nReadCnt += lGCount;
     372                 :            : 
     373         [ +  - ]:         21 :             ::SetProgressState( nReadCnt, pDoc->GetDocShell() );
     374                 :            : 
     375         [ -  + ]:         21 :             if( cLastCR )
     376                 :            :             {
     377 [ #  # ][ #  # ]:          0 :                 if( 0x0a == *pStt && 0x0d == cLastCR )
     378                 :          0 :                     pLastStt = ++pStt;
     379                 :          0 :                 cLastCR = 0;
     380                 :          0 :                 nLineLen = 0;
     381                 :            :                 // We skip the last one at the end
     382 [ #  # ][ #  # ]:          0 :                 if( !rInput.IsEof() || !(pEnd == pStt ||
                 [ #  # ]
     383 [ #  # ][ #  # ]:          0 :                     ( !*pEnd && pEnd == pStt+1 ) ) )
     384         [ #  # ]:          0 :                     pDoc->SplitNode( *pPam->GetPoint(), false );
     385                 :            :             }
     386                 :            :         }
     387                 :            : 
     388                 :      60540 :         bool bIns = true, bSplitNode = false;
     389   [ +  +  -  -  :      60540 :         switch( *pStt )
                   -  + ]
     390                 :            :         {
     391                 :            : 
     392         [ +  - ]:        819 :         case 0x0a:  if( LINEEND_LF == pUseMe->GetParaFlags() )
     393                 :            :                     {
     394                 :        819 :                         bIns = false;
     395                 :        819 :                         *pStt = 0;
     396                 :        819 :                         ++pStt;
     397                 :            : 
     398                 :            :                         // We skip the last one at the end
     399 [ +  + ][ +  + ]:        819 :                         if( !rInput.IsEof() || pEnd != pStt )
                 [ +  + ]
     400                 :        810 :                             bSplitNode = true;
     401                 :            :                     }
     402                 :        819 :                     break;
     403                 :            : 
     404         [ -  + ]:          6 :         case 0x0d:  if( LINEEND_LF != pUseMe->GetParaFlags() )
     405                 :            :                     {
     406                 :          0 :                         bIns = false;
     407                 :          0 :                         *pStt = 0;
     408                 :          0 :                         ++pStt;
     409                 :            : 
     410                 :          0 :                         bool bChkSplit = false;
     411         [ #  # ]:          0 :                         if( LINEEND_CRLF == pUseMe->GetParaFlags() )
     412                 :            :                         {
     413         [ #  # ]:          0 :                             if( pStt == pEnd )
     414                 :          0 :                                 cLastCR = 0x0d;
     415         [ #  # ]:          0 :                             else if( 0x0a == *pStt )
     416                 :            :                             {
     417                 :          0 :                                 ++pStt;
     418                 :          0 :                                 bChkSplit = true;
     419                 :            :                             }
     420                 :            :                         }
     421                 :            :                         else
     422                 :          0 :                             bChkSplit = true;
     423                 :            : 
     424                 :            :                         // We skip the last one at the end
     425 [ #  # ][ #  # ]:          0 :                         if( bChkSplit && ( !rInput.IsEof() || pEnd != pStt ))
         [ #  # ][ #  # ]
     426                 :          0 :                             bSplitNode = true;
     427                 :            :                     }
     428                 :          6 :                     break;
     429                 :            : 
     430                 :            :         case 0x0c:
     431                 :            :                     {
     432                 :            :                         // Insert a hard page break
     433                 :          0 :                         *pStt++ = 0;
     434         [ #  # ]:          0 :                         if( nLineLen )
     435                 :            :                         {
     436 [ #  # ][ #  # ]:          0 :                             InsertText( rtl::OUString( pLastStt ));
                 [ #  # ]
     437                 :            :                         }
     438         [ #  # ]:          0 :                         pDoc->SplitNode( *pPam->GetPoint(), false );
     439                 :            :                         pDoc->InsertPoolItem( *pPam, SvxFmtBreakItem(
     440 [ #  # ][ #  # ]:          0 :                                     SVX_BREAK_PAGE_BEFORE, RES_BREAK ), 0);
                 [ #  # ]
     441                 :          0 :                         pLastStt = pStt;
     442                 :          0 :                         nLineLen = 0;
     443                 :          0 :                         bIns = false;
     444                 :            :                     }
     445                 :          0 :                     break;
     446                 :            : 
     447                 :            :         case 0x1a:
     448 [ #  # ][ #  # ]:          0 :                     if( nReadCnt == nFileSize && pStt+1 == pEnd )
     449                 :          0 :                         *pStt = 0;
     450                 :            :                     else
     451                 :          0 :                         *pStt = '#';        // Replacement visualisation
     452                 :          0 :                     break;
     453                 :            : 
     454                 :          0 :         case '\t':  break;
     455                 :            : 
     456                 :            :         default:
     457         [ +  + ]:      59715 :             if( ' ' > *pStt )
     458                 :            :             // Found control char, replace with '#'
     459                 :         21 :                 *pStt = '#';
     460                 :      59715 :             break;
     461                 :            :         }
     462                 :            : 
     463         [ +  + ]:      60540 :         if( bIns )
     464                 :            :         {
     465 [ -  + ][ #  # ]:      59721 :             if( ( nLineLen >= MAX_ASCII_PARA - 100 ) &&
                 [ #  # ]
     466                 :            :                 ( ( *pStt == ' ' ) || ( nLineLen >= MAX_ASCII_PARA - 1 ) ) )
     467                 :            :             {
     468                 :          0 :                 sal_Unicode c = *pStt;
     469                 :          0 :                 *pStt = 0;
     470 [ #  # ][ #  # ]:          0 :                 InsertText( rtl::OUString( pLastStt ));
                 [ #  # ]
     471         [ #  # ]:          0 :                 pDoc->SplitNode( *pPam->GetPoint(), false );
     472                 :          0 :                 pLastStt = pStt;
     473                 :          0 :                 nLineLen = 0;
     474                 :          0 :                 *pStt = c;
     475                 :            :             }
     476                 :      59721 :             ++pStt;
     477                 :      59721 :             ++nLineLen;
     478                 :            :         }
     479         [ +  + ]:        819 :         else if( bSplitNode )
     480                 :            :         {
     481                 :            :             // We found a CR/LF, thus save the text
     482 [ +  - ][ +  - ]:        810 :             InsertText( rtl::OUString( pLastStt ));
                 [ +  - ]
     483         [ +  - ]:        810 :             pDoc->SplitNode( *pPam->GetPoint(), false );
     484                 :        810 :             pLastStt = pStt;
     485                 :        810 :             nLineLen = 0;
     486                 :            :         }
     487                 :            :     } while(true);
     488                 :            : 
     489         [ +  - ]:          9 :     if( hConverter )
     490                 :            :     {
     491         [ +  - ]:          9 :         rtl_destroyTextToUnicodeContext( hConverter, hContext );
     492         [ +  - ]:          9 :         rtl_destroyTextToUnicodeConverter( hConverter );
     493                 :            :     }
     494 [ +  - ][ +  - ]:          9 :     return 0;
     495                 :            : }
     496                 :            : 
     497                 :        831 : void SwASCIIParser::InsertText( const String& rStr )
     498                 :            : {
     499                 :        831 :     pDoc->InsertString( *pPam, rStr );
     500                 :        831 :     pDoc->UpdateRsid( *pPam, rStr.Len() );
     501                 :        831 :     pDoc->UpdateParRsid( pPam->GetPoint()->nNode.GetNode().GetTxtNode() );
     502                 :            : 
     503 [ +  - ][ +  + ]:        831 :     if( pItemSet && pBreakIt && nScript != ( SCRIPTTYPE_LATIN |
                 [ +  - ]
     504                 :            :                                              SCRIPTTYPE_ASIAN |
     505                 :            :                                              SCRIPTTYPE_COMPLEX ) )
     506         [ +  - ]:        192 :         nScript |= pBreakIt->GetAllScriptsOfText( rStr );
     507                 :        831 : }
     508                 :            : 
     509                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10