Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / dif.hxx
blob33524d1a4067c8678e9c55a623ebd2353cb8f742
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_DIF_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_DIF_HXX
23 #include <map>
24 #include <memory>
25 #include <vector>
27 #include <rtl/ustring.hxx>
28 #include <rtl/ustrbuf.hxx>
30 #include <types.hxx>
32 class SvStream;
33 class SvNumberFormatter;
34 class ScDocument;
36 extern const sal_Unicode pKeyTABLE[];
37 extern const sal_Unicode pKeyVECTORS[];
38 extern const sal_Unicode pKeyTUPLES[];
39 extern const sal_Unicode pKeyDATA[];
40 extern const sal_Unicode pKeyBOT[];
41 extern const sal_Unicode pKeyEOD[];
42 extern const sal_Unicode pKeyTRUE[];
43 extern const sal_Unicode pKeyFALSE[];
44 extern const sal_Unicode pKeyNA[];
45 extern const sal_Unicode pKeyV[];
46 extern const sal_Unicode pKey1_0[];
48 enum TOPIC
50 T_UNKNOWN,
51 T_TABLE, T_VECTORS, T_TUPLES, T_DATA, T_LABEL, T_COMMENT, T_SIZE,
52 T_PERIODICITY, T_MAJORSTART, T_MINORSTART, T_TRUELENGTH, T_UINITS,
53 T_DISPLAYUNITS,
54 T_END
57 enum DATASET { D_BOT, D_EOD, D_NUMERIC, D_STRING, D_UNKNOWN, D_SYNT_ERROR };
59 class DifParser
61 public:
62 OUStringBuffer m_aData;
63 double fVal;
64 sal_uInt32 nVector;
65 sal_uInt32 nVal;
66 sal_uInt32 nNumFormat;
67 private:
68 SvNumberFormatter* pNumFormatter;
69 SvStream& rIn;
70 OUString aLookAheadLine;
72 bool ReadNextLine( OUString& rStr );
73 bool LookAhead();
74 DATASET GetNumberDataset( const sal_Unicode* pPossibleNumericData );
75 static inline bool IsBOT( const sal_Unicode* pRef );
76 static inline bool IsEOD( const sal_Unicode* pRef );
77 static inline bool Is1_0( const sal_Unicode* pRef );
78 public:
79 DifParser( SvStream&, const ScDocument&, rtl_TextEncoding );
81 TOPIC GetNextTopic();
83 DATASET GetNextDataset();
85 static const sal_Unicode* ScanIntVal( const sal_Unicode* pStart, sal_uInt32& rRet );
87 static inline bool IsNumber( const sal_Unicode cChar );
89 static inline bool IsV( const sal_Unicode* pRef );
92 inline bool DifParser::IsBOT( const sal_Unicode* pRef )
94 return ( pRef[ 0 ] == pKeyBOT[0] &&
95 pRef[ 1 ] == pKeyBOT[1] &&
96 pRef[ 2 ] == pKeyBOT[2] &&
97 pRef[ 3 ] == pKeyBOT[3] );
100 inline bool DifParser::IsEOD( const sal_Unicode* pRef )
102 return ( pRef[ 0 ] == pKeyEOD[0] &&
103 pRef[ 1 ] == pKeyEOD[1] &&
104 pRef[ 2 ] == pKeyEOD[2] &&
105 pRef[ 3 ] == pKeyEOD[3] );
108 inline bool DifParser::Is1_0( const sal_Unicode* pRef )
110 return ( pRef[ 0 ] == pKey1_0[0] &&
111 pRef[ 1 ] == pKey1_0[1] &&
112 pRef[ 2 ] == pKey1_0[2] &&
113 pRef[ 3 ] == pKey1_0[3] );
116 inline bool DifParser::IsV( const sal_Unicode* pRef )
118 return ( pRef[ 0 ] == pKeyV[0] &&
119 pRef[ 1 ] == pKeyV[1] );
122 inline bool DifParser::IsNumber( const sal_Unicode cChar )
124 return ( cChar >= '0' && cChar <= '9' );
127 class DifColumn
129 friend class DifAttrCache;
131 struct ENTRY
133 sal_uInt32 nNumFormat;
134 SCROW nStart;
135 SCROW nEnd;
138 ENTRY *mpCurrent;
139 std::vector<ENTRY> maEntries;
141 DifColumn();
143 void SetNumFormat( SCROW nRow, const sal_uInt32 nNumFormat );
145 void NewEntry( const SCROW nPos, const sal_uInt32 nNumFormat );
147 void Apply( ScDocument &rDoc, const SCCOL nCol, const SCTAB nTab );
150 class DifAttrCache
152 public:
154 DifAttrCache();
156 ~DifAttrCache();
158 void SetNumFormat( const SCCOL nCol, const SCROW nRow, const sal_uInt32 nNumFormat );
160 void Apply( ScDocument&, SCTAB nTab );
162 private:
164 std::map<SCCOL, std::unique_ptr<DifColumn>> maColMap;
167 #endif
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */