LCOV - code coverage report
Current view: top level - sc/source/ui/dbgui - asciiopt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 14 154 9.1 %
Date: 2012-08-25 Functions: 3 9 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 312 1.6 %

           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 "global.hxx"
      30                 :            : #include "scresid.hxx"
      31                 :            : #include "impex.hxx"
      32                 :            : #include "asciiopt.hxx"
      33                 :            : #include "asciiopt.hrc"
      34                 :            : #include <comphelper/string.hxx>
      35                 :            : #include <rtl/tencinfo.h>
      36                 :            : #include <unotools/transliterationwrapper.hxx>
      37                 :            : // ause
      38                 :            : #include "editutil.hxx"
      39                 :            : 
      40                 :            : // ============================================================================
      41                 :            : 
      42                 :            : static const sal_Char pStrFix[] = "FIX";
      43                 :            : static const sal_Char pStrMrg[] = "MRG";
      44                 :            : 
      45                 :            : 
      46                 :            : // ============================================================================
      47                 :            : 
      48                 :          6 : ScAsciiOptions::ScAsciiOptions() :
      49                 :            :     bFixedLen       ( false ),
      50                 :            :     aFieldSeps      ( rtl::OUString(';') ),
      51                 :            :     bMergeFieldSeps ( false ),
      52                 :            :     bQuotedFieldAsText(false),
      53                 :            :     bDetectSpecialNumber(false),
      54                 :            :     cTextSep        ( cDefaultTextSep ),
      55         [ +  - ]:          6 :     eCharSet        ( osl_getThreadTextEncoding() ),
      56                 :            :     eLang           ( LANGUAGE_SYSTEM ),
      57                 :            :     bCharSetSystem  ( false ),
      58                 :            :     nStartRow       ( 1 ),
      59                 :            :     nInfoCount      ( 0 ),
      60                 :            :     pColStart       ( NULL ),
      61         [ +  - ]:          6 :     pColFormat      ( NULL )
      62                 :            : {
      63                 :          6 : }
      64                 :            : 
      65                 :            : 
      66                 :          6 : ScAsciiOptions::ScAsciiOptions(const ScAsciiOptions& rOpt) :
      67                 :            :     bFixedLen       ( rOpt.bFixedLen ),
      68                 :            :     aFieldSeps      ( rOpt.aFieldSeps ),
      69                 :            :     bMergeFieldSeps ( rOpt.bMergeFieldSeps ),
      70                 :            :     bQuotedFieldAsText(rOpt.bQuotedFieldAsText),
      71                 :            :     bDetectSpecialNumber(rOpt.bDetectSpecialNumber),
      72                 :            :     cTextSep        ( rOpt.cTextSep ),
      73                 :            :     eCharSet        ( rOpt.eCharSet ),
      74                 :            :     eLang           ( rOpt.eLang ),
      75                 :            :     bCharSetSystem  ( rOpt.bCharSetSystem ),
      76                 :            :     nStartRow       ( rOpt.nStartRow ),
      77                 :          6 :     nInfoCount      ( rOpt.nInfoCount )
      78                 :            : {
      79         [ -  + ]:          6 :     if (nInfoCount)
      80                 :            :     {
      81         [ #  # ]:          0 :         pColStart = new sal_Int32[nInfoCount];
      82         [ #  # ]:          0 :         pColFormat = new sal_uInt8[nInfoCount];
      83         [ #  # ]:          0 :         for (sal_uInt16 i=0; i<nInfoCount; i++)
      84                 :            :         {
      85                 :          0 :             pColStart[i] = rOpt.pColStart[i];
      86                 :          0 :             pColFormat[i] = rOpt.pColFormat[i];
      87                 :            :         }
      88                 :            :     }
      89                 :            :     else
      90                 :            :     {
      91                 :          6 :         pColStart = NULL;
      92                 :          6 :         pColFormat = NULL;
      93                 :            :     }
      94                 :          6 : }
      95                 :            : 
      96                 :            : 
      97                 :         12 : ScAsciiOptions::~ScAsciiOptions()
      98                 :            : {
      99         [ -  + ]:         12 :     delete[] pColStart;
     100         [ -  + ]:         12 :     delete[] pColFormat;
     101                 :         12 : }
     102                 :            : 
     103                 :            : 
     104                 :          0 : void ScAsciiOptions::SetColInfo( sal_uInt16 nCount, const sal_Int32* pStart, const sal_uInt8* pFormat )
     105                 :            : {
     106         [ #  # ]:          0 :     delete[] pColStart;
     107         [ #  # ]:          0 :     delete[] pColFormat;
     108                 :            : 
     109                 :          0 :     nInfoCount = nCount;
     110                 :            : 
     111         [ #  # ]:          0 :     if (nInfoCount)
     112                 :            :     {
     113                 :          0 :         pColStart = new sal_Int32[nInfoCount];
     114                 :          0 :         pColFormat = new sal_uInt8[nInfoCount];
     115         [ #  # ]:          0 :         for (sal_uInt16 i=0; i<nInfoCount; i++)
     116                 :            :         {
     117                 :          0 :             pColStart[i] = pStart[i];
     118                 :          0 :             pColFormat[i] = pFormat[i];
     119                 :            :         }
     120                 :            :     }
     121                 :            :     else
     122                 :            :     {
     123                 :          0 :         pColStart = NULL;
     124                 :          0 :         pColFormat = NULL;
     125                 :            :     }
     126                 :          0 : }
     127                 :            : 
     128                 :            : 
     129                 :          0 : void ScAsciiOptions::SetColumnInfo( const ScCsvExpDataVec& rDataVec )
     130                 :            : {
     131         [ #  # ]:          0 :     delete[] pColStart;
     132                 :          0 :     pColStart = NULL;
     133         [ #  # ]:          0 :     delete[] pColFormat;
     134                 :          0 :     pColFormat = NULL;
     135                 :            : 
     136                 :          0 :     nInfoCount = static_cast< sal_uInt16 >( rDataVec.size() );
     137         [ #  # ]:          0 :     if( nInfoCount )
     138                 :            :     {
     139                 :          0 :         pColStart = new sal_Int32[ nInfoCount ];
     140                 :          0 :         pColFormat = new sal_uInt8[ nInfoCount ];
     141         [ #  # ]:          0 :         for( sal_uInt16 nIx = 0; nIx < nInfoCount; ++nIx )
     142                 :            :         {
     143                 :          0 :             pColStart[ nIx ] = rDataVec[ nIx ].mnIndex;
     144                 :          0 :             pColFormat[ nIx ] = rDataVec[ nIx ].mnType;
     145                 :            :         }
     146                 :            :     }
     147                 :          0 : }
     148                 :            : 
     149                 :            : 
     150                 :          0 : ScAsciiOptions& ScAsciiOptions::operator=( const ScAsciiOptions& rCpy )
     151                 :            : {
     152                 :          0 :     SetColInfo( rCpy.nInfoCount, rCpy.pColStart, rCpy.pColFormat );
     153                 :            : 
     154                 :          0 :     bFixedLen       = rCpy.bFixedLen;
     155                 :          0 :     aFieldSeps      = rCpy.aFieldSeps;
     156                 :          0 :     bMergeFieldSeps = rCpy.bMergeFieldSeps;
     157                 :          0 :     bQuotedFieldAsText = rCpy.bQuotedFieldAsText;
     158                 :          0 :     cTextSep        = rCpy.cTextSep;
     159                 :          0 :     eCharSet        = rCpy.eCharSet;
     160                 :          0 :     bCharSetSystem  = rCpy.bCharSetSystem;
     161                 :          0 :     nStartRow       = rCpy.nStartRow;
     162                 :            : 
     163                 :          0 :     return *this;
     164                 :            : }
     165                 :            : 
     166                 :            : 
     167                 :          0 : sal_Bool ScAsciiOptions::operator==( const ScAsciiOptions& rCmp ) const
     168                 :            : {
     169   [ #  #  #  # ]:          0 :     if ( bFixedLen       == rCmp.bFixedLen &&
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     170                 :          0 :          aFieldSeps      == rCmp.aFieldSeps &&
     171                 :            :          bMergeFieldSeps == rCmp.bMergeFieldSeps &&
     172                 :            :          bQuotedFieldAsText == rCmp.bQuotedFieldAsText &&
     173                 :            :          cTextSep        == rCmp.cTextSep &&
     174                 :            :          eCharSet        == rCmp.eCharSet &&
     175                 :            :          bCharSetSystem  == rCmp.bCharSetSystem &&
     176                 :            :          nStartRow       == rCmp.nStartRow &&
     177                 :            :          nInfoCount      == rCmp.nInfoCount )
     178                 :            :     {
     179                 :            :         OSL_ENSURE( !nInfoCount || (pColStart && pColFormat && rCmp.pColStart && rCmp.pColFormat),
     180                 :            :                      "0-Zeiger in ScAsciiOptions" );
     181         [ #  # ]:          0 :         for (sal_uInt16 i=0; i<nInfoCount; i++)
     182 [ #  # ][ #  # ]:          0 :             if ( pColStart[i] != rCmp.pColStart[i] ||
     183                 :          0 :                  pColFormat[i] != rCmp.pColFormat[i] )
     184                 :          0 :                 return false;
     185                 :            : 
     186                 :          0 :         return sal_True;
     187                 :            :     }
     188                 :          0 :     return false;
     189                 :            : }
     190                 :            : 
     191                 :            : //
     192                 :            : //  Der Options-String darf kein Semikolon mehr enthalten (wegen Pickliste)
     193                 :            : //  darum ab Version 336 Komma stattdessen
     194                 :            : //
     195                 :            : 
     196                 :            : 
     197                 :          0 : void ScAsciiOptions::ReadFromString( const String& rString )
     198                 :            : {
     199 [ #  # ][ #  # ]:          0 :     xub_StrLen nCount = comphelper::string::getTokenCount(rString, ',');
     200         [ #  # ]:          0 :     String aToken;
     201                 :            :     xub_StrLen nSub;
     202                 :            :     xub_StrLen i;
     203                 :            : 
     204                 :            :         //
     205                 :            :         //  Feld-Trenner
     206                 :            :         //
     207                 :            : 
     208         [ #  # ]:          0 :     if ( nCount >= 1 )
     209                 :            :     {
     210                 :          0 :         bFixedLen = bMergeFieldSeps = false;
     211         [ #  # ]:          0 :         aFieldSeps.Erase();
     212                 :            : 
     213 [ #  # ][ #  # ]:          0 :         aToken = rString.GetToken(0,',');
                 [ #  # ]
     214 [ #  # ][ #  # ]:          0 :         if ( aToken.EqualsAscii(pStrFix) )
     215                 :          0 :             bFixedLen = sal_True;
     216 [ #  # ][ #  # ]:          0 :         nSub = comphelper::string::getTokenCount(aToken, '/');
     217         [ #  # ]:          0 :         for ( i=0; i<nSub; i++ )
     218                 :            :         {
     219         [ #  # ]:          0 :             String aCode = aToken.GetToken( i, '/' );
     220 [ #  # ][ #  # ]:          0 :             if ( aCode.EqualsAscii(pStrMrg) )
     221                 :          0 :                 bMergeFieldSeps = sal_True;
     222                 :            :             else
     223                 :            :             {
     224         [ #  # ]:          0 :                 sal_Int32 nVal = aCode.ToInt32();
     225         [ #  # ]:          0 :                 if ( nVal )
     226         [ #  # ]:          0 :                     aFieldSeps += (sal_Unicode) nVal;
     227                 :            :             }
     228         [ #  # ]:          0 :         }
     229                 :            :     }
     230                 :            : 
     231                 :            :         //
     232                 :            :         //  Text-Trenner
     233                 :            :         //
     234                 :            : 
     235         [ #  # ]:          0 :     if ( nCount >= 2 )
     236                 :            :     {
     237 [ #  # ][ #  # ]:          0 :         aToken = rString.GetToken(1,',');
                 [ #  # ]
     238         [ #  # ]:          0 :         sal_Int32 nVal = aToken.ToInt32();
     239                 :          0 :         cTextSep = (sal_Unicode) nVal;
     240                 :            :     }
     241                 :            : 
     242                 :            :         //
     243                 :            :         //  Zeichensatz
     244                 :            :         //
     245                 :            : 
     246         [ #  # ]:          0 :     if ( nCount >= 3 )
     247                 :            :     {
     248 [ #  # ][ #  # ]:          0 :         aToken = rString.GetToken(2,',');
                 [ #  # ]
     249         [ #  # ]:          0 :         eCharSet = ScGlobal::GetCharsetValue( aToken );
     250                 :            :     }
     251                 :            : 
     252                 :            :         //
     253                 :            :         //  Startzeile
     254                 :            :         //
     255                 :            : 
     256         [ #  # ]:          0 :     if ( nCount >= 4 )
     257                 :            :     {
     258 [ #  # ][ #  # ]:          0 :         aToken = rString.GetToken(3,',');
                 [ #  # ]
     259         [ #  # ]:          0 :         nStartRow = aToken.ToInt32();
     260                 :            :     }
     261                 :            : 
     262                 :            :         //
     263                 :            :         //  Spalten-Infos
     264                 :            :         //
     265                 :            : 
     266         [ #  # ]:          0 :     if ( nCount >= 5 )
     267                 :            :     {
     268         [ #  # ]:          0 :         delete[] pColStart;
     269         [ #  # ]:          0 :         delete[] pColFormat;
     270                 :            : 
     271 [ #  # ][ #  # ]:          0 :         aToken = rString.GetToken(4,',');
                 [ #  # ]
     272 [ #  # ][ #  # ]:          0 :         nSub = comphelper::string::getTokenCount(aToken, '/');
     273                 :          0 :         nInfoCount = nSub / 2;
     274         [ #  # ]:          0 :         if (nInfoCount)
     275                 :            :         {
     276         [ #  # ]:          0 :             pColStart = new sal_Int32[nInfoCount];
     277         [ #  # ]:          0 :             pColFormat = new sal_uInt8[nInfoCount];
     278         [ #  # ]:          0 :             for (sal_uInt16 nInfo=0; nInfo<nInfoCount; nInfo++)
     279                 :            :             {
     280 [ #  # ][ #  # ]:          0 :                 pColStart[nInfo]  = (sal_Int32) aToken.GetToken( 2*nInfo, '/' ).ToInt32();
                 [ #  # ]
     281 [ #  # ][ #  # ]:          0 :                 pColFormat[nInfo] = (sal_uInt8) aToken.GetToken( 2*nInfo+1, '/' ).ToInt32();
                 [ #  # ]
     282                 :            :             }
     283                 :            :         }
     284                 :            :         else
     285                 :            :         {
     286                 :          0 :             pColStart = NULL;
     287                 :          0 :             pColFormat = NULL;
     288                 :            :         }
     289                 :            :     }
     290                 :            : 
     291                 :            :     // Language
     292         [ #  # ]:          0 :     if (nCount >= 6)
     293                 :            :     {
     294 [ #  # ][ #  # ]:          0 :         aToken = rString.GetToken(5, ',');
                 [ #  # ]
     295         [ #  # ]:          0 :         eLang = static_cast<LanguageType>(aToken.ToInt32());
     296                 :            :     }
     297                 :            : 
     298                 :            :     // Import quoted field as text.
     299         [ #  # ]:          0 :     if (nCount >= 7)
     300                 :            :     {
     301 [ #  # ][ #  # ]:          0 :         aToken = rString.GetToken(6, ',');
                 [ #  # ]
     302         [ #  # ]:          0 :         bQuotedFieldAsText = aToken.EqualsAscii("true") ? true : false;
     303                 :            :     }
     304                 :            : 
     305                 :            :     // Detect special nubmers.
     306         [ #  # ]:          0 :     if (nCount >= 8)
     307                 :            :     {
     308 [ #  # ][ #  # ]:          0 :         aToken = rString.GetToken(7, ',');
                 [ #  # ]
     309         [ #  # ]:          0 :         bDetectSpecialNumber = aToken.EqualsAscii("true") ? true : false;
     310                 :            :     }
     311                 :            :     else
     312         [ #  # ]:          0 :         bDetectSpecialNumber = sal_True;    // default of versions that didn't add the parameter
     313                 :            : 
     314                 :            :     // 9th token is used for "Save as shown" in export options
     315                 :            :     // 10th token is used for "Save cell formulas" in export options
     316                 :          0 : }
     317                 :            : 
     318                 :            : 
     319                 :          0 : String ScAsciiOptions::WriteToString() const
     320                 :            : {
     321                 :          0 :     String aOutStr;
     322                 :            : 
     323                 :            :         //
     324                 :            :         //  Feld-Trenner
     325                 :            :         //
     326                 :            : 
     327         [ #  # ]:          0 :     if ( bFixedLen )
     328         [ #  # ]:          0 :         aOutStr.AppendAscii(pStrFix);
     329         [ #  # ]:          0 :     else if ( !aFieldSeps.Len() )
     330         [ #  # ]:          0 :         aOutStr += '0';
     331                 :            :     else
     332                 :            :     {
     333                 :          0 :         xub_StrLen nLen = aFieldSeps.Len();
     334         [ #  # ]:          0 :         for (xub_StrLen i=0; i<nLen; i++)
     335                 :            :         {
     336         [ #  # ]:          0 :             if (i)
     337         [ #  # ]:          0 :                 aOutStr += '/';
     338 [ #  # ][ #  # ]:          0 :             aOutStr += String::CreateFromInt32(aFieldSeps.GetChar(i));
                 [ #  # ]
     339                 :            :         }
     340         [ #  # ]:          0 :         if ( bMergeFieldSeps )
     341                 :            :         {
     342         [ #  # ]:          0 :             aOutStr += '/';
     343         [ #  # ]:          0 :             aOutStr.AppendAscii(pStrMrg);
     344                 :            :         }
     345                 :            :     }
     346                 :            : 
     347         [ #  # ]:          0 :     aOutStr += ',';                 // Token-Ende
     348                 :            : 
     349                 :            :         //
     350                 :            :         //  Text-Trenner
     351                 :            :         //
     352                 :            : 
     353 [ #  # ][ #  # ]:          0 :     aOutStr += String::CreateFromInt32(cTextSep);
                 [ #  # ]
     354         [ #  # ]:          0 :     aOutStr += ',';                 // Token-Ende
     355                 :            : 
     356                 :            :         //
     357                 :            :         //  Zeichensatz
     358                 :            :         //
     359                 :            : 
     360         [ #  # ]:          0 :     if ( bCharSetSystem )           // force "SYSTEM"
     361 [ #  # ][ #  # ]:          0 :         aOutStr += ScGlobal::GetCharsetString( RTL_TEXTENCODING_DONTKNOW );
                 [ #  # ]
     362                 :            :     else
     363 [ #  # ][ #  # ]:          0 :         aOutStr += ScGlobal::GetCharsetString( eCharSet );
                 [ #  # ]
     364         [ #  # ]:          0 :     aOutStr += ',';                 // Token-Ende
     365                 :            : 
     366                 :            :         //
     367                 :            :         //  Startzeile
     368                 :            :         //
     369                 :            : 
     370 [ #  # ][ #  # ]:          0 :     aOutStr += String::CreateFromInt32(nStartRow);
                 [ #  # ]
     371         [ #  # ]:          0 :     aOutStr += ',';                 // Token-Ende
     372                 :            : 
     373                 :            :         //
     374                 :            :         //  Spalten-Infos
     375                 :            :         //
     376                 :            : 
     377                 :            :     OSL_ENSURE( !nInfoCount || (pColStart && pColFormat), "0-Zeiger in ScAsciiOptions" );
     378         [ #  # ]:          0 :     for (sal_uInt16 nInfo=0; nInfo<nInfoCount; nInfo++)
     379                 :            :     {
     380         [ #  # ]:          0 :         if (nInfo)
     381         [ #  # ]:          0 :             aOutStr += '/';
     382 [ #  # ][ #  # ]:          0 :         aOutStr += String::CreateFromInt32(pColStart[nInfo]);
                 [ #  # ]
     383         [ #  # ]:          0 :         aOutStr += '/';
     384 [ #  # ][ #  # ]:          0 :         aOutStr += String::CreateFromInt32(pColFormat[nInfo]);
                 [ #  # ]
     385                 :            :     }
     386                 :            : 
     387                 :            :     // #i112025# the options string is used in macros and linked sheets,
     388                 :            :     // so new options must be added at the end, to remain compatible
     389                 :            : 
     390         [ #  # ]:          0 :     aOutStr += ',';
     391                 :            : 
     392                 :            :     // Language
     393 [ #  # ][ #  # ]:          0 :     aOutStr += String::CreateFromInt32(eLang);
                 [ #  # ]
     394         [ #  # ]:          0 :     aOutStr += ',';
     395                 :            : 
     396                 :            :     // Import quoted field as text.
     397 [ #  # ][ #  # ]:          0 :     aOutStr += bQuotedFieldAsText ? rtl::OUString("true") : rtl::OUString("false");
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     398         [ #  # ]:          0 :     aOutStr += ',';
     399                 :            : 
     400                 :            :     // Detect special nubmers.
     401 [ #  # ][ #  # ]:          0 :     aOutStr += bDetectSpecialNumber ? rtl::OUString("true") : rtl::OUString("false");
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     402                 :            : 
     403                 :            :     // 9th token is used for "Save as shown" in export options
     404                 :            :     // 10th token is used for "Save cell formulas" in export options
     405                 :            : 
     406                 :          0 :     return aOutStr;
     407                 :            : }
     408                 :            : 
     409                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10