LibreOffice Module sax (master) 1
converter.hxx
Go to the documentation of this file.
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#ifndef INCLUDED_SAX_TOOLS_CONVERTER_HXX
21#define INCLUDED_SAX_TOOLS_CONVERTER_HXX
22
23#include <sal/config.h>
24
25#include <optional>
26#include <type_traits>
27
28#include <sax/saxdllapi.h>
29
30#include <rtl/strbuf.hxx>
31#include <sal/types.h>
32#include <rtl/ustrbuf.hxx>
33#include <com/sun/star/util/MeasureUnit.hpp>
34#include <tools/color.hxx>
35#include <unotools/saveopt.hxx>
36
37namespace com::sun::star {
38 namespace uno {
39 class Any;
40 }
41 namespace util {
42 struct Date;
43 struct DateTime;
44 struct Duration;
45 }
46}
47
48namespace sax {
49
59{
60public:
62 static bool convertMeasure( sal_Int32& rValue,
63 std::u16string_view rString,
64 sal_Int16 nTargetUnit = css::util::MeasureUnit::MM_100TH,
65 sal_Int32 nMin = SAL_MIN_INT32,
66 sal_Int32 nMax = SAL_MAX_INT32 );
67
69 static bool convertMeasure( sal_Int32& rValue,
70 std::string_view rString,
71 sal_Int16 nTargetUnit = css::util::MeasureUnit::MM_100TH,
72 sal_Int32 nMin = SAL_MIN_INT32,
73 sal_Int32 nMax = SAL_MAX_INT32 );
74
76 static void convertMeasure( OUStringBuffer& rBuffer,
77 sal_Int32 nMeasure,
78 sal_Int16 SourceUnit,
79 sal_Int16 nTargetUnit );
80
82 static bool convertBool( bool& rBool,
83 std::u16string_view rString );
84
86 static bool convertBool( bool& rBool,
87 std::string_view rString );
88
90 static void convertBool( OUStringBuffer& rBuffer,
91 bool bValue );
92
94 static bool convertPercent( sal_Int32& rValue,
95 std::u16string_view rString );
96
98 static bool convertPercent( sal_Int32& rValue,
99 std::string_view rString );
100
102 static void convertPercent( OUStringBuffer& rBuffer,
103 sal_Int32 nValue );
104
106 static bool convertMeasurePx( sal_Int32& rValue,
107 std::u16string_view rString );
108
110 static bool convertMeasurePx( sal_Int32& rValue,
111 std::string_view rString );
112
114 static void convertMeasurePx( OUStringBuffer& rBuffer,
115 sal_Int32 nValue );
116
118 static bool convertColor( sal_Int32& rColor,
119 std::u16string_view rValue );
120 static bool convertColor( sal_Int32& rColor,
121 std::string_view rValue );
122 static bool convertColor( ::Color& rColor,
123 std::u16string_view rValue )
124 {
125 sal_Int32 n(rColor);
126 bool b = convertColor( n, rValue );
127 if (b) rColor = Color(ColorTransparency, n);
128 return b;
129 }
130 static bool convertColor( ::Color& rColor,
131 std::string_view rValue )
132 {
133 sal_Int32 n(rColor);
134 bool b = convertColor( n, rValue );
135 if (b) rColor = Color(ColorTransparency, n);
136 return b;
137 }
138
140 static void convertColor( OUStringBuffer &rBuffer,
141 sal_Int32 nColor );
142 static void convertColor( OUStringBuffer &rBuffer,
143 ::Color nColor )
144 { convertColor( rBuffer, sal_Int32(nColor) ); }
145
147 static bool convertNumber( sal_Int32& rValue,
148 std::u16string_view aString,
149 sal_Int32 nMin = SAL_MIN_INT32,
150 sal_Int32 nMax = SAL_MAX_INT32 );
151
153 static bool convertNumber( sal_Int32& rValue,
154 std::string_view aString,
155 sal_Int32 nMin = SAL_MIN_INT32,
156 sal_Int32 nMax = SAL_MAX_INT32 );
157
159 static bool convertNumber64(sal_Int64& rValue,
160 std::u16string_view aString,
161 sal_Int64 nMin = SAL_MIN_INT64,
162 sal_Int64 nMax = SAL_MAX_INT64);
163
165 static bool convertNumber64(sal_Int64& rValue,
166 std::string_view aString,
167 sal_Int64 nMin = SAL_MIN_INT64,
168 sal_Int64 nMax = SAL_MAX_INT64);
169
172 static void convertDouble( OUStringBuffer& rBuffer,
173 double fNumber,
174 bool bWriteUnits,
175 sal_Int16 nSourceUnit,
176 sal_Int16 nTargetUnit );
177
179 static void convertDouble( OUStringBuffer& rBuffer, double fNumber);
180
183 static bool convertDouble( double& rValue,
184 std::u16string_view rString,
185 sal_Int16 nSourceUnit,
186 sal_Int16 nTargetUnit );
187
190 static bool convertDouble( double& rValue,
191 std::string_view rString,
192 sal_Int16 nSourceUnit,
193 sal_Int16 nTargetUnit );
194
196 static bool convertDouble(double& rValue, std::u16string_view rString);
197
199 static bool convertDouble(double& rValue, std::string_view rString);
200
202 static void convertAngle(OUStringBuffer& rBuffer, sal_Int16 nAngle,
204
206 static bool convertAngle(sal_Int16& rAngle, std::u16string_view rString,
207 bool isWrongOOo10thDegAngle);
208
210 static bool convertAngle(sal_Int16& rAngle, std::string_view rString,
211 bool isWrongOOo10thDegAngle);
212
214 static void convertDuration(OUStringBuffer& rBuffer,
215 const double fTime);
216
218 static void convertDuration(OUStringBuffer& rBuffer,
219 const css::util::Duration& rDuration);
220
222 static bool convertDuration(double & rfTime,
223 std::string_view rString);
224
226 static bool convertDuration(css::util::Duration& rDuration,
227 std::u16string_view rString);
228
230 static bool convertDuration(css::util::Duration& rDuration,
231 std::string_view rString);
232
234 static void convertDate( OUStringBuffer& rBuffer,
235 const css::util::Date& rDate,
236 sal_Int16 const* pTimeZoneOffset);
237
239 static void convertDateTime( OUStringBuffer& rBuffer,
240 const css::util::DateTime& rDateTime,
241 sal_Int16 const* pTimeZoneOffset,
242 bool bAddTimeIf0AM = false );
243
245 static void convertTimeOrDateTime(OUStringBuffer& rBuffer,
246 const css::util::DateTime& rDateTime);
247
249 static bool parseDateTime( css::util::DateTime& rDateTime,
250 std::u16string_view rString );
251
253 static bool parseDateTime( css::util::DateTime& rDateTime,
254 std::string_view rString );
255
257 static bool parseTimeOrDateTime(css::util::DateTime& rDateTime,
258 std::u16string_view rString);
259
261 static bool parseTimeOrDateTime(css::util::DateTime& rDateTime,
262 std::string_view rString);
263
267 css::util::Date * pDate,
268 css::util::DateTime & rDateTime,
269 bool & rbDateTime,
270 std::optional<sal_Int16> * pTimeZoneOffset,
271 std::u16string_view rString );
272
276 css::util::Date * pDate,
277 css::util::DateTime & rDateTime,
278 bool & rbDateTime,
279 std::optional<sal_Int16> * pTimeZoneOffset,
280 std::string_view rString );
281
284 static sal_Int32 indexOfComma( std::u16string_view rStr,
285 sal_Int32 nPos );
286
287 static double GetConversionFactor(OUStringBuffer& rUnit, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit);
288 static double GetConversionFactor(OStringBuffer& rUnit, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit);
289 static sal_Int16 GetUnitFromString(std::u16string_view rString, sal_Int16 nDefaultUnit);
290 static sal_Int16 GetUnitFromString(std::string_view rString, sal_Int16 nDefaultUnit);
291
293 static bool convertAny(OUStringBuffer& rsValue,
294 OUStringBuffer& rsType ,
295 const css::uno::Any& rValue);
296
298 static void convertBytesToHexBinary(OUStringBuffer& rBuffer, const void* pBytes,
299 sal_Int32 nBytes);
300
301 template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, int> = 0>
302 static void convertNumberToHexBinary(OUStringBuffer& rBuffer, T n)
303 {
304 convertBytesToHexBinary(rBuffer, &n, sizeof(n));
305 }
306
307};
308
309}
310
311#endif // INCLUDED_SAX_TOOLS_CONVERTER_HXX
312
313/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
the Converter converts values of various types from their internal representation to the textual form...
Definition: converter.hxx:59
static bool parseTimeOrDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
convert XMLSchema-2 "time" or "dateTime" string to util::DateTime
static void convertColor(OUStringBuffer &rBuffer, ::Color nColor)
Definition: converter.hxx:142
static bool parseTimeOrDateTime(css::util::DateTime &rDateTime, std::string_view rString)
convert XMLSchema-2 "time" or "dateTime" string to util::DateTime
static void convertDuration(OUStringBuffer &rBuffer, const css::util::Duration &rDuration)
convert util::Duration to XMLSchema-2 "duration" string
static bool parseDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
convert XMLSchema-2 "date" or "dateTime" string to util::DateTime
static bool convertColor(::Color &rColor, std::string_view rValue)
Definition: converter.hxx:130
static bool parseDateOrDateTime(css::util::Date *pDate, css::util::DateTime &rDateTime, bool &rbDateTime, std::optional< sal_Int16 > *pTimeZoneOffset, std::u16string_view rString)
convert XMLSchema-2 "date" or "dateTime" string to util::DateTime or util::Date
static bool convertDuration(css::util::Duration &rDuration, std::string_view rString)
convert XMLSchema-2 "duration" string to util::Duration
static void convertNumberToHexBinary(OUStringBuffer &rBuffer, T n)
Definition: converter.hxx:302
static bool parseDateTime(css::util::DateTime &rDateTime, std::string_view rString)
convert XMLSchema-2 "date" or "dateTime" string to util::DateTime
static bool convertDuration(css::util::Duration &rDuration, std::u16string_view rString)
convert XMLSchema-2 "duration" string to util::Duration
static bool convertColor(::Color &rColor, std::u16string_view rValue)
Definition: converter.hxx:122
static bool parseDateOrDateTime(css::util::Date *pDate, css::util::DateTime &rDateTime, bool &rbDateTime, std::optional< sal_Int16 > *pTimeZoneOffset, std::string_view rString)
convert XMLSchema-2 "date" or "dateTime" string to util::DateTime or util::Date
ColorTransparency
sal_Int16 nValue
sal_Int64 n
bool convertMeasure(OUString &rString)
#define SAX_DLLPUBLIC
Definition: saxdllapi.h:28
#define SAL_MAX_INT32
#define SAL_MIN_INT32