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

Generated by: LCOV version 1.10