LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sc / source / filter / inc / dif.hxx
blob1cda09a2b281631bcc4c416314154731e36ccf70
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 <vector>
26 #include <rtl/ustring.hxx>
27 #include <rtl/ustrbuf.hxx>
29 #include <types.hxx>
31 class SvStream;
32 class SvNumberFormatter;
33 class ScDocument;
35 extern const sal_Unicode pKeyTABLE[];
36 extern const sal_Unicode pKeyVECTORS[];
37 extern const sal_Unicode pKeyTUPLES[];
38 extern const sal_Unicode pKeyDATA[];
39 extern const sal_Unicode pKeyBOT[];
40 extern const sal_Unicode pKeyEOD[];
41 extern const sal_Unicode pKeyTRUE[];
42 extern const sal_Unicode pKeyFALSE[];
43 extern const sal_Unicode pKeyNA[];
44 extern const sal_Unicode pKeyV[];
45 extern const sal_Unicode pKey1_0[];
47 enum TOPIC
49 T_UNKNOWN,
50 T_TABLE, T_VECTORS, T_TUPLES, T_DATA, T_LABEL, T_COMMENT, T_SIZE,
51 T_PERIODICITY, T_MAJORSTART, T_MINORSTART, T_TRUELENGTH, T_UINITS,
52 T_DISPLAYUNITS,
53 T_END
56 enum DATASET { D_BOT, D_EOD, D_NUMERIC, D_STRING, D_UNKNOWN, D_SYNT_ERROR };
58 class DifParser
60 public:
61 OUStringBuffer m_aData;
62 double fVal;
63 sal_uInt32 nVector;
64 sal_uInt32 nVal;
65 sal_uInt32 nNumFormat;
66 private:
67 SvNumberFormatter* pNumFormatter;
68 SvStream& rIn;
69 OUString aLookAheadLine;
71 bool ReadNextLine( OUString& rStr );
72 bool LookAhead();
73 DATASET GetNumberDataset( const sal_Unicode* pPossibleNumericData );
74 static inline bool IsBOT( const sal_Unicode* pRef );
75 static inline bool IsEOD( const sal_Unicode* pRef );
76 static inline bool Is1_0( const sal_Unicode* pRef );
77 public:
78 DifParser( SvStream&, const ScDocument&, rtl_TextEncoding );
80 TOPIC GetNextTopic();
82 DATASET GetNextDataset();
84 static const sal_Unicode* ScanIntVal( const sal_Unicode* pStart, sal_uInt32& rRet );
86 static inline bool IsNumber( const sal_Unicode cChar );
88 static inline bool IsV( const sal_Unicode* pRef );
91 inline bool DifParser::IsBOT( const sal_Unicode* pRef )
93 return ( pRef[ 0 ] == pKeyBOT[0] &&
94 pRef[ 1 ] == pKeyBOT[1] &&
95 pRef[ 2 ] == pKeyBOT[2] &&
96 pRef[ 3 ] == pKeyBOT[3] );
99 inline bool DifParser::IsEOD( const sal_Unicode* pRef )
101 return ( pRef[ 0 ] == pKeyEOD[0] &&
102 pRef[ 1 ] == pKeyEOD[1] &&
103 pRef[ 2 ] == pKeyEOD[2] &&
104 pRef[ 3 ] == pKeyEOD[3] );
107 inline bool DifParser::Is1_0( const sal_Unicode* pRef )
109 return ( pRef[ 0 ] == pKey1_0[0] &&
110 pRef[ 1 ] == pKey1_0[1] &&
111 pRef[ 2 ] == pKey1_0[2] &&
112 pRef[ 3 ] == pKey1_0[3] );
115 inline bool DifParser::IsV( const sal_Unicode* pRef )
117 return ( pRef[ 0 ] == pKeyV[0] &&
118 pRef[ 1 ] == pKeyV[1] );
121 inline bool DifParser::IsNumber( const sal_Unicode cChar )
123 return ( cChar >= '0' && cChar <= '9' );
126 class DifColumn
128 friend class DifAttrCache;
130 struct ENTRY
132 sal_uInt32 nNumFormat;
133 SCROW nStart;
134 SCROW nEnd;
137 ENTRY *mpCurrent;
138 std::vector<ENTRY> maEntries;
140 DifColumn();
142 void SetNumFormat( const ScDocument* pDoc, SCROW nRow, const sal_uInt32 nNumFormat );
144 void NewEntry( const SCROW nPos, const sal_uInt32 nNumFormat );
146 void Apply( ScDocument &rDoc, const SCCOL nCol, const SCTAB nTab );
149 class DifAttrCache
151 public:
153 DifAttrCache();
155 ~DifAttrCache();
157 void SetNumFormat( const ScDocument* pDoc, const SCCOL nCol, const SCROW nRow, const sal_uInt32 nNumFormat );
159 void Apply( ScDocument&, SCTAB nTab );
161 private:
163 std::map<SCCOL, std::unique_ptr<DifColumn>> maColMap;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */