/************************************************************** * * 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 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sc.hxx" #include "global.hxx" #include "scresid.hxx" #include "impex.hxx" #include "asciiopt.hxx" #include "asciiopt.hrc" #include #include #include // ause #include "editutil.hxx" // ============================================================================ static const sal_Char __FAR_DATA pStrFix[] = "FIX"; static const sal_Char __FAR_DATA pStrMrg[] = "MRG"; // ============================================================================ ScAsciiOptions::ScAsciiOptions() : bFixedLen ( sal_False ), aFieldSeps ( ';' ), bMergeFieldSeps ( sal_False ), bQuotedFieldAsText(false), bDetectSpecialNumber(false), cTextSep ( cDefaultTextSep ), eCharSet ( gsl_getSystemTextEncoding() ), eLang ( LANGUAGE_SYSTEM ), bCharSetSystem ( sal_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 xub_StrLen[nInfoCount]; pColFormat = new sal_uInt8[nInfoCount]; for (sal_uInt16 i=0; i( rDataVec.size() ); if( nInfoCount ) { pColStart = new xub_StrLen[ 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; } sal_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 ) { DBG_ASSERT( !nInfoCount || (pColStart && pColFormat && rCmp.pColStart && rCmp.pColFormat), "0-Zeiger in ScAsciiOptions" ); for (sal_uInt16 i=0; i= 1 ) { bFixedLen = bMergeFieldSeps = sal_False; aFieldSeps.Erase(); aToken = rString.GetToken(0,','); if ( aToken.EqualsAscii(pStrFix) ) bFixedLen = sal_True; nSub = aToken.GetTokenCount('/'); for ( i=0; i= 2 ) { aToken = rString.GetToken(1,','); sal_Int32 nVal = aToken.ToInt32(); cTextSep = (sal_Unicode) nVal; } // // Zeichensatz // if ( nCount >= 3 ) { aToken = rString.GetToken(2,','); eCharSet = ScGlobal::GetCharsetValue( aToken ); } // // Startzeile // if ( nCount >= 4 ) { aToken = rString.GetToken(3,','); nStartRow = aToken.ToInt32(); } // // Spalten-Infos // if ( nCount >= 5 ) { delete[] pColStart; delete[] pColFormat; aToken = rString.GetToken(4,','); nSub = aToken.GetTokenCount('/'); nInfoCount = nSub / 2; if (nInfoCount) { pColStart = new xub_StrLen[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") ? true : false; } // Detect special nubmers. if (nCount >= 8) { aToken = rString.GetToken(7, ','); bDetectSpecialNumber = aToken.EqualsAscii("true") ? true : false; } else bDetectSpecialNumber = sal_True; // default of versions that didn't add the parameter // 9th token is used for "Save as shown" in export options } String ScAsciiOptions::WriteToString() const { String aOutStr; // // Feld-Trenner // if ( bFixedLen ) aOutStr.AppendAscii(pStrFix); else if ( !aFieldSeps.Len() ) aOutStr += '0'; else { xub_StrLen nLen = aFieldSeps.Len(); for (xub_StrLen i=0; i