Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / inc / dif.hxx
blob594327058a7a603ffc2ec15efed828683a2a4295
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 #pragma once
22 #include <map>
23 #include <memory>
24 #include <string_view>
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 std::u16string_view pKeyTABLE;
37 extern const std::u16string_view pKeyVECTORS;
38 extern const std::u16string_view pKeyTUPLES;
39 extern const std::u16string_view pKeyDATA;
40 extern const std::u16string_view pKeyBOT;
41 extern const std::u16string_view pKeyEOD;
43 enum TOPIC
45 T_UNKNOWN,
46 T_TABLE, T_VECTORS, T_TUPLES, T_DATA, T_LABEL, T_COMMENT, T_SIZE,
47 T_PERIODICITY, T_MAJORSTART, T_MINORSTART, T_TRUELENGTH, T_UINITS,
48 T_DISPLAYUNITS,
49 T_END
52 enum DATASET { D_BOT, D_EOD, D_NUMERIC, D_STRING, D_UNKNOWN, D_SYNT_ERROR };
54 class DifParser
56 public:
57 OUStringBuffer m_aData;
58 double fVal;
59 sal_uInt32 nVector;
60 sal_uInt32 nVal;
61 sal_uInt32 nNumFormat;
62 private:
63 SvNumberFormatter* pNumFormatter;
64 SvStream& rIn;
65 OUString aLookAheadLine;
67 bool ReadNextLine( OUString& rStr );
68 bool LookAhead();
69 DATASET GetNumberDataset( const sal_Unicode* pPossibleNumericData );
70 static inline bool IsBOT( const sal_Unicode* pRef );
71 static inline bool IsEOD( const sal_Unicode* pRef );
72 static inline bool Is1_0( const sal_Unicode* pRef );
73 public:
74 DifParser( SvStream&, const ScDocument&, rtl_TextEncoding );
76 TOPIC GetNextTopic();
78 DATASET GetNextDataset();
80 static const sal_Unicode* ScanIntVal( const sal_Unicode* pStart, sal_uInt32& rRet );
82 static inline bool IsNumber( const sal_Unicode cChar );
84 static inline bool IsV( const sal_Unicode* pRef );
87 inline bool DifParser::IsBOT( const sal_Unicode* pRef )
89 return pRef == pKeyBOT;
92 inline bool DifParser::IsEOD( const sal_Unicode* pRef )
94 return pRef == pKeyEOD;
97 inline bool DifParser::Is1_0( const sal_Unicode* pRef )
99 return pRef == std::u16string_view(u"1,0");
102 inline bool DifParser::IsV( const sal_Unicode* pRef )
104 return pRef == std::u16string_view(u"V");
107 inline bool DifParser::IsNumber( const sal_Unicode cChar )
109 return ( cChar >= '0' && cChar <= '9' );
112 class DifColumn
114 friend class DifAttrCache;
116 struct ENTRY
118 sal_uInt32 nNumFormat;
119 SCROW nStart;
120 SCROW nEnd;
123 ENTRY *mpCurrent;
124 std::vector<ENTRY> maEntries;
126 DifColumn();
128 void SetNumFormat( const ScDocument* pDoc, SCROW nRow, const sal_uInt32 nNumFormat );
130 void NewEntry( const SCROW nPos, const sal_uInt32 nNumFormat );
132 void Apply( ScDocument &rDoc, const SCCOL nCol, const SCTAB nTab );
135 class DifAttrCache
137 public:
139 DifAttrCache();
141 ~DifAttrCache();
143 void SetNumFormat( const ScDocument* pDoc, const SCCOL nCol, const SCROW nRow, const sal_uInt32 nNumFormat );
145 void Apply( ScDocument&, SCTAB nTab );
147 private:
149 std::map<SCCOL, std::unique_ptr<DifColumn>> maColMap;
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */