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 "imoptdlg.hxx"
30 : : #include "scresid.hxx"
31 : : #include "imoptdlg.hrc"
32 : : #include <comphelper/string.hxx>
33 : : #include <rtl/tencinfo.h>
34 : :
35 : : static const sal_Char pStrFix[] = "FIX";
36 : :
37 : : //------------------------------------------------------------------------
38 : : // Der Options-String darf kein Semikolon mehr enthalten (wegen Pickliste)
39 : : // darum ab Version 336 Komma stattdessen
40 : :
41 : :
42 : 0 : ScImportOptions::ScImportOptions( const String& rStr )
43 : : {
44 : : // Use the same string format as ScAsciiOptions,
45 : : // because the import options string is passed here when a CSV file is loaded and saved again.
46 : : // The old format is still supported because it might be used in macros.
47 : :
48 : 0 : bFixedWidth = false;
49 : 0 : nFieldSepCode = 0;
50 : 0 : nTextSepCode = 0;
51 : 0 : eCharSet = RTL_TEXTENCODING_DONTKNOW;
52 : 0 : bSaveAsShown = sal_True; // "true" if not in string (after CSV import)
53 : 0 : bQuoteAllText = false;
54 : 0 : bSaveFormulas = false;
55 [ # # ][ # # ]: 0 : xub_StrLen nTokenCount = comphelper::string::getTokenCount(rStr, ',');
56 [ # # ]: 0 : if ( nTokenCount >= 3 )
57 : : {
58 : : // first 3 tokens: common
59 [ # # ]: 0 : String aToken( rStr.GetToken( 0, ',' ) );
60 [ # # ][ # # ]: 0 : if( aToken.EqualsIgnoreCaseAscii( pStrFix ) )
61 : 0 : bFixedWidth = sal_True;
62 : : else
63 [ # # ]: 0 : nFieldSepCode = (sal_Unicode) aToken.ToInt32();
64 [ # # ][ # # ]: 0 : nTextSepCode = (sal_Unicode) rStr.GetToken(1,',').ToInt32();
[ # # ]
65 [ # # ][ # # ]: 0 : aStrFont = rStr.GetToken(2,',');
[ # # ]
66 [ # # ]: 0 : eCharSet = ScGlobal::GetCharsetValue(aStrFont);
67 : :
68 [ # # ]: 0 : if ( nTokenCount == 4 )
69 : : {
70 : : // compatibility with old options string: "Save as shown" as 4th token, numeric
71 [ # # ][ # # ]: 0 : bSaveAsShown = (rStr.GetToken( 3, ',' ).ToInt32() ? sal_True : false);
[ # # ][ # # ]
72 : 0 : bQuoteAllText = sal_True; // use old default then
73 : : }
74 : : else
75 : : {
76 : : // look at the same positions as in ScAsciiOptions
77 [ # # ]: 0 : if ( nTokenCount >= 7 )
78 [ # # ][ # # ]: 0 : bQuoteAllText = rStr.GetToken(6, ',').EqualsAscii("true");
[ # # ]
79 [ # # ]: 0 : if ( nTokenCount >= 9 )
80 [ # # ][ # # ]: 0 : bSaveAsShown = rStr.GetToken(8, ',').EqualsAscii("true");
[ # # ]
81 [ # # ]: 0 : if ( nTokenCount >= 10 )
82 [ # # ][ # # ]: 0 : bSaveFormulas = rStr.GetToken(9, ',').EqualsAscii("true");
[ # # ]
83 [ # # ]: 0 : }
84 : : }
85 : 0 : }
86 : :
87 : : //------------------------------------------------------------------------
88 : :
89 : 0 : String ScImportOptions::BuildString() const
90 : : {
91 : 0 : String aResult;
92 : :
93 [ # # ]: 0 : if( bFixedWidth )
94 [ # # ]: 0 : aResult.AppendAscii( pStrFix );
95 : : else
96 [ # # ][ # # ]: 0 : aResult += String::CreateFromInt32(nFieldSepCode);
[ # # ]
97 [ # # ]: 0 : aResult += ',';
98 [ # # ][ # # ]: 0 : aResult += String::CreateFromInt32(nTextSepCode);
[ # # ]
99 [ # # ]: 0 : aResult += ',';
100 [ # # ]: 0 : aResult += aStrFont;
101 : : // use the same string format as ScAsciiOptions:
102 [ # # ]: 0 : aResult.AppendAscii( ",1,,0," ); // first row, no column info, default language
103 [ # # ][ # # ]: 0 : aResult.AppendAscii(bQuoteAllText ? "true" : "false"); // same as "quoted field as text" in ScAsciiOptions
104 [ # # ]: 0 : aResult.AppendAscii( ",true," ); // "detect special numbers"
105 [ # # ][ # # ]: 0 : aResult.AppendAscii(bSaveAsShown ? "true" : "false"); // "save as shown": not in ScAsciiOptions
106 [ # # ]: 0 : aResult.AppendAscii( "," );
107 [ # # ][ # # ]: 0 : aResult.AppendAscii(bSaveFormulas ? "true" : "false"); // "save formulas": not in ScAsciiOptions
108 : :
109 : 0 : return aResult;
110 : : }
111 : :
112 : : //------------------------------------------------------------------------
113 : :
114 : 0 : void ScImportOptions::SetTextEncoding( rtl_TextEncoding nEnc )
115 : : {
116 : : eCharSet = (nEnc == RTL_TEXTENCODING_DONTKNOW ?
117 [ # # ]: 0 : osl_getThreadTextEncoding() : nEnc);
118 [ # # ]: 0 : aStrFont = ScGlobal::GetCharsetString( nEnc );
119 : 0 : }
120 : :
121 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|