Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/inc/rangeutl.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#pragma once
21
22
#include "address.hxx"
23
#include "rangenam.hxx"
24
#include "dbdata.hxx"
25
#include "scdllapi.h"
26
27
namespace com::sun::star::table { struct CellAddress; }
28
namespace com::sun::star::table { struct CellRangeAddress; }
29
namespace com::sun::star::uno { template <typename > class Sequence; }
30
31
class ScArea;
32
class ScDocument;
33
class ScRangeList;
34
35
enum RutlNameScope
36
{
37
    RUTL_NONE = 0,
38
    RUTL_NAMES,
39
    RUTL_NAMES_LOCAL,
40
    RUTL_NAMES_GLOBAL,
41
    RUTL_DBASE
42
};
43
44
class SAL_DLLPUBLIC_RTTI ScRangeUtil
45
{
46
public:
47
    ScRangeUtil() = delete;
48
49
    static bool MakeArea        ( const OUString&   rAreaStr,
50
                                  ScArea&           rArea,
51
                                  const ScDocument& rDoc,
52
                                  SCTAB         nTab,
53
                                  ScAddress::Details const & rDetails );
54
55
    static void CutPosString    ( const OUString&     theAreaStr,
56
                                  OUString&           thePosStr );
57
58
    static bool IsAbsTabArea    ( const OUString&   rAreaStr,
59
                                  const ScDocument* pDoc,
60
                                  std::unique_ptr<ScArea[]>* ppAreas,
61
                                  sal_uInt16*       pAreaCount,
62
                                  bool              bAcceptCellRef = false,
63
                                  ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 );
64
65
    SC_DLLPUBLIC static bool IsAbsArea       ( const OUString& rAreaStr,
66
                                  const ScDocument& rDoc,
67
                                  SCTAB     nTab,
68
                                  OUString*     pCompleteStr,
69
                                  ScRefAddress* pStartPos    = nullptr,
70
                                  ScRefAddress* pEndPos      = nullptr,
71
                                  ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 );
72
73
    SC_DLLPUBLIC static bool IsAbsPos        ( const OUString& rPosStr,
74
                                  const ScDocument& rDoc,
75
                                  SCTAB     nTab,
76
                                  OUString*       pCompleteStr,
77
                                  ScRefAddress* pPosTripel   = nullptr,
78
                                  ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 );
79
80
    static bool MakeRangeFromName( const OUString& rName,
81
                                   const ScDocument& rDoc,
82
                                    SCTAB           nCurTab,
83
                                    ScRange&        rRange,
84
                                  RutlNameScope eScope=RUTL_NAMES,
85
                                  ScAddress::Details const & rDetails = ScAddress::detailsOOOa1,
86
                                  bool bUseDetailsPos = false );
87
};
88
89
class SAL_DLLPUBLIC_RTTI ScRangeStringConverter
90
{
91
public:
92
93
/// helper methods
94
    static void         AssignString(
95
                            OUString& rString,
96
                            const OUString& rNewStr,
97
                            bool bAppendStr,
98
                            sal_Unicode cSeparator = ' ');
99
100
    static sal_Int32    IndexOf(
101
                            std::u16string_view rString,
102
                            sal_Unicode cSearchChar,
103
                            sal_Int32 nOffset,
104
                            sal_Unicode cQuote = '\'');
105
106
    static sal_Int32    IndexOfDifferent(
107
                            std::u16string_view rString,
108
                            sal_Unicode cSearchChar,
109
                            sal_Int32 nOffset );
110
111
    static sal_Int32    GetTokenCount(
112
                            std::u16string_view rString,
113
                            sal_Unicode cSeparator = ' ');
114
115
    static void         GetTokenByOffset(
116
                            OUString& rToken,
117
                            std::u16string_view rString,
118
                            sal_Int32& nOffset,
119
                            sal_Unicode cSeparator = ' ',
120
                            sal_Unicode cQuote = '\'');
121
122
    static void         AppendTableName(
123
                            OUStringBuffer& rBuf,
124
                            const OUString& rTabName);
125
126
/// String to Range core
127
    SC_DLLPUBLIC static bool GetAddressFromString(
128
                            ScAddress& rAddress,
129
                            std::u16string_view rAddressStr,
130
                            const ScDocument& rDocument,
131
                            formula::FormulaGrammar::AddressConvention eConv,
132
                            sal_Int32& nOffset,
133
                            sal_Unicode cSeparator = ' ',
134
                            sal_Unicode cQuote = '\'');
135
    SC_DLLPUBLIC static bool GetRangeFromString(
136
                            ScRange& rRange,
137
                            std::u16string_view rRangeStr,
138
                            const ScDocument& rDocument,
139
                            formula::FormulaGrammar::AddressConvention eConv,
140
                            sal_Int32& nOffset,
141
                            sal_Unicode cSeparator = ' ',
142
                            sal_Unicode cQuote = '\'');
143
    SC_DLLPUBLIC static bool GetRangeListFromString(
144
                            ScRangeList& rRangeList,
145
                            std::u16string_view rRangeListStr,
146
                            const ScDocument& rDocument,
147
                            formula::FormulaGrammar::AddressConvention eConv,
148
                            sal_Unicode cSeparator = ' ',
149
                            sal_Unicode cQuote = '\'');
150
151
    static bool     GetAreaFromString(
152
                            ScArea& rArea,
153
                            std::u16string_view rRangeStr,
154
                            const ScDocument& rDocument,
155
                            formula::FormulaGrammar::AddressConvention eConv,
156
                            sal_Int32& nOffset,
157
                            sal_Unicode cSeparator = ' ');
158
159
/// String to Range API
160
    static bool     GetRangeFromString(
161
                            css::table::CellRangeAddress& rRange,
162
                            std::u16string_view rRangeStr,
163
                            const ScDocument& rDocument,
164
                            formula::FormulaGrammar::AddressConvention eConv,
165
                            sal_Int32& nOffset,
166
                            sal_Unicode cSeparator = ' ');
167
168
/// Range to String core
169
    static void         GetStringFromAddress(
170
                            OUString& rString,
171
                            const ScAddress& rAddress,
172
                            const ScDocument* pDocument,
173
                            formula::FormulaGrammar::AddressConvention eConv,
174
                            sal_Unicode cSeparator = ' ',
175
                            bool bAppendStr = false,
176
                            ScRefFlags nFormatFlags = ScRefFlags::VALID | ScRefFlags::TAB_3D );
177
    static void         GetStringFromRange(
178
                            OUString& rString,
179
                            const ScRange& rRange,
180
                            const ScDocument* pDocument,
181
                            formula::FormulaGrammar::AddressConvention eConv,
182
                            sal_Unicode cSeparator = ' ',
183
                            bool bAppendStr = false,
184
                            ScRefFlags nFormatFlags = ScRefFlags::VALID | ScRefFlags::TAB_3D );
185
    SC_DLLPUBLIC static void GetStringFromRangeList(
186
                            OUString& rString,
187
                            const ScRangeList* pRangeList,
188
                            const ScDocument* pDocument,
189
                            formula::FormulaGrammar::AddressConvention eConv,
190
                            sal_Unicode cSeparator = ' ');
191
192
    static void         GetStringFromArea(
193
                            OUString& rString,
194
                            const ScArea& rArea,
195
                            const ScDocument* pDocument,
196
                            formula::FormulaGrammar::AddressConvention eConv,
197
                            sal_Unicode cSeparator,
198
                            bool bAppendStr = false,
199
                            ScRefFlags nFormatFlags = ScRefFlags::VALID | ScRefFlags::TAB_3D );
200
201
/// Range to String API
202
    static void         GetStringFromAddress(
203
                            OUString& rString,
204
                            const css::table::CellAddress& rAddress,
205
                            const ScDocument* pDocument,
206
                            formula::FormulaGrammar::AddressConvention eConv,
207
                            sal_Unicode cSeparator = ' ',
208
                            bool bAppendStr = false );
209
    static void         GetStringFromRange(
210
                            OUString& rString,
211
                            const css::table::CellRangeAddress& rRange,
212
                            const ScDocument* pDocument,
213
                            formula::FormulaGrammar::AddressConvention eConv,
214
                            sal_Unicode cSeparator = ' ',
215
                            bool bAppendStr = false,
216
                            ScRefFlags nFormatFlags = ScRefFlags::VALID | ScRefFlags::TAB_3D );
217
    static void         GetStringFromRangeList(
218
                            OUString& rString,
219
                            const css::uno::Sequence< css::table::CellRangeAddress >& rRangeSeq,
220
                            const ScDocument* pDocument,
221
                            formula::FormulaGrammar::AddressConvention eConv,
222
                            sal_Unicode cSeparator = ' ' );
223
224
/// XML Range to Calc Range
225
    static void         GetStringFromXMLRangeString(
226
                            OUString& rString,
227
                            std::u16string_view rXMLRange,
228
                            const ScDocument& rDoc );
229
230
/// String to RangeData core
231
    static ScRangeData* GetRangeDataFromString( const OUString& rString, const SCTAB nTab,
232
                            const ScDocument& rDoc, formula::FormulaGrammar::AddressConvention eConv );
233
};
234
235
class ScArea
236
{
237
public:
238
            ScArea( SCTAB tab      = 0,
239
                    SCCOL colStart = 0,
240
                    SCROW rowStart = 0,
241
                    SCCOL colEnd   = 0,
242
                    SCROW rowEnd   = 0 );
243
244
    bool    operator==  ( const ScArea& r ) const;
245
246
public:
247
    SCTAB nTab;
248
    SCCOL nColStart;
249
    SCROW nRowStart;
250
    SCCOL nColEnd;
251
    SCROW nRowEnd;
252
};
253
254
///  @return areas with reference and all db-areas
255
256
class SC_DLLPUBLIC ScAreaNameIterator
257
{
258
private:
259
    ScRangeName*    pRangeName;
260
    ScDBCollection* pDBCollection;
261
    ScRangeName::const_iterator maRNPos;
262
    ScRangeName::const_iterator maRNEnd;
263
    ScDBCollection::NamedDBs::const_iterator maDBPos;
264
    ScDBCollection::NamedDBs::const_iterator maDBEnd;
265
    bool            bFirstPass;
266
267
public:
268
    ScAreaNameIterator( const ScDocument& rDoc );
269
270
    bool Next( OUString& rName, ScRange& rRange );
271
0
    bool WasDBName() const { return !bFirstPass; }
272
};
273
274
struct SC_DLLPUBLIC ScRangeUpdater
275
{
276
    ScRangeUpdater() = delete;
277
278
    static void UpdateInsertTab(ScAddress& rAddr, const sc::RefUpdateInsertTabContext& rCxt);
279
280
    /** This is for the base-cell-address of a defined name or conditional
281
        format, not for references. A sheet position on or after the start of
282
        the deleted range is moved towards the beginning by the amount of
283
        deleted sheets, within the deleted range to the front of that or set to
284
        0 (as there is always at least one sheet in a document) if the position
285
        would result in a negative value, e.g. if position was 0 and (only)
286
        sheet 0 is deleted it would had become -1.
287
     */
288
    static void UpdateDeleteTab(ScAddress& rAddr, const sc::RefUpdateDeleteTabContext& rCxt);
289
};
290
291
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */