/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include "global.hxx" #include "scresid.hxx" #include "impex.hxx" #include "asciiopt.hxx" #include "asciiopt.hrc" #include #include #include #include #include "editutil.hxx" static const sal_Char pStrFix[] = "FIX"; static const sal_Char pStrMrg[] = "MRG"; ScAsciiOptions::ScAsciiOptions() : bFixedLen ( false ), aFieldSeps ( OUString(';') ), bMergeFieldSeps ( false ), bQuotedFieldAsText(false), bDetectSpecialNumber(false), cTextSep ( cDefaultTextSep ), eCharSet ( osl_getThreadTextEncoding() ), eLang ( LANGUAGE_SYSTEM ), bCharSetSystem ( false ), nStartRow ( 1 ), nInfoCount ( 0 ), pColStart ( NULL ), pColFormat ( NULL ) { } ScAsciiOptions::ScAsciiOptions(const ScAsciiOptions& rOpt) : bFixedLen ( rOpt.bFixedLen ), aFieldSeps ( rOpt.aFieldSeps ), bMergeFieldSeps ( rOpt.bMergeFieldSeps ), bQuotedFieldAsText(rOpt.bQuotedFieldAsText), bDetectSpecialNumber(rOpt.bDetectSpecialNumber), cTextSep ( rOpt.cTextSep ), eCharSet ( rOpt.eCharSet ), eLang ( rOpt.eLang ), bCharSetSystem ( rOpt.bCharSetSystem ), nStartRow ( rOpt.nStartRow ), nInfoCount ( rOpt.nInfoCount ) { if (nInfoCount) { pColStart = new sal_Int32[nInfoCount]; pColFormat = new sal_uInt8[nInfoCount]; for (sal_uInt16 i=0; i( rDataVec.size() ); if( nInfoCount ) { pColStart = new sal_Int32[ nInfoCount ]; pColFormat = new sal_uInt8[ nInfoCount ]; for( sal_uInt16 nIx = 0; nIx < nInfoCount; ++nIx ) { pColStart[ nIx ] = rDataVec[ nIx ].mnIndex; pColFormat[ nIx ] = rDataVec[ nIx ].mnType; } } } ScAsciiOptions& ScAsciiOptions::operator=( const ScAsciiOptions& rCpy ) { SetColInfo( rCpy.nInfoCount, rCpy.pColStart, rCpy.pColFormat ); bFixedLen = rCpy.bFixedLen; aFieldSeps = rCpy.aFieldSeps; bMergeFieldSeps = rCpy.bMergeFieldSeps; bQuotedFieldAsText = rCpy.bQuotedFieldAsText; cTextSep = rCpy.cTextSep; eCharSet = rCpy.eCharSet; bCharSetSystem = rCpy.bCharSetSystem; nStartRow = rCpy.nStartRow; return *this; } bool ScAsciiOptions::operator==( const ScAsciiOptions& rCmp ) const { if ( bFixedLen == rCmp.bFixedLen && aFieldSeps == rCmp.aFieldSeps && bMergeFieldSeps == rCmp.bMergeFieldSeps && bQuotedFieldAsText == rCmp.bQuotedFieldAsText && cTextSep == rCmp.cTextSep && eCharSet == rCmp.eCharSet && bCharSetSystem == rCmp.bCharSetSystem && nStartRow == rCmp.nStartRow && nInfoCount == rCmp.nInfoCount ) { OSL_ENSURE( !nInfoCount || (pColStart && pColFormat && rCmp.pColStart && rCmp.pColFormat), "NULL pointer in ScAsciiOptions::operator==() column info" ); for (sal_uInt16 i=0; i= 1 ) { bFixedLen = bMergeFieldSeps = false; aToken = rString.getToken(0,','); if ( aToken.equalsAscii(pStrFix) ) bFixedLen = true; aFieldSeps = lcl_decodeSepString( aToken, bMergeFieldSeps); } // Text separator. if ( nCount >= 2 ) { aToken = rString.getToken(1,','); sal_Int32 nVal = aToken.toInt32(); cTextSep = (sal_Unicode) nVal; } // Text encoding. if ( nCount >= 3 ) { aToken = rString.getToken(2,','); eCharSet = ScGlobal::GetCharsetValue( aToken ); } // Number of start row. if ( nCount >= 4 ) { aToken = rString.getToken(3,','); nStartRow = aToken.toInt32(); } // Column info. if ( nCount >= 5 ) { delete[] pColStart; delete[] pColFormat; aToken = rString.getToken(4,','); sal_Int32 nSub = comphelper::string::getTokenCount(aToken, '/'); nInfoCount = nSub / 2; if (nInfoCount) { pColStart = new sal_Int32[nInfoCount]; pColFormat = new sal_uInt8[nInfoCount]; for (sal_uInt16 nInfo=0; nInfo= 6) { aToken = rString.getToken(5, ','); eLang = static_cast(aToken.toInt32()); } // Import quoted field as text. if (nCount >= 7) { aToken = rString.getToken(6, ','); bQuotedFieldAsText = aToken.equalsAscii("true"); } // Detect special numbers. if (nCount >= 8) { aToken = rString.getToken(7, ','); bDetectSpecialNumber = aToken.equalsAscii("true"); } else bDetectSpecialNumber = true; // default of versions that didn't add the parameter // 9th token is used for "Save as shown" in export options // 10th token is used for "Save cell formulas" in export options } OUString ScAsciiOptions::WriteToString() const { OUString aOutStr; // Field separator. if ( bFixedLen ) aOutStr += pStrFix; else if ( aFieldSeps.isEmpty() ) aOutStr += "0"; else { sal_Int32 nLen = aFieldSeps.getLength(); for (sal_Int32 i=0; i