LibreOffice Module xmloff (master)  1
xmluconv.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_XMLOFF_XMLUCONV_HXX
21 #define INCLUDED_XMLOFF_XMLUCONV_HXX
22 
23 #include <sal/config.h>
24 #include <xmloff/dllapi.h>
25 #include <sal/types.h>
26 
27 #include <memory>
28 
29 #include <rtl/ustring.hxx>
30 #include <rtl/ustrbuf.hxx>
31 #include <xmloff/xmltoken.hxx>
32 
33 #include <tools/fldunit.hxx>
34 
35 namespace com::sun::star {
36  namespace text { class XNumberingTypeInfo; }
37 }
38 
39 namespace basegfx
40 {
41  class B3DVector;
42 }
43 
44 namespace com::sun::star::beans { class XPropertySet; }
45 namespace com::sun::star::beans { struct PropertyValue; }
46 namespace com::sun::star::drawing { struct Position3D; }
47 namespace com::sun::star::frame { class XModel; }
48 namespace com::sun::star::uno { class XComponentContext; }
49 namespace com::sun::star::uno { template <class E> class Sequence; }
50 namespace com::sun::star::util { struct Date; }
51 template <typename EnumT> struct SvXMLEnumMapEntry;
52 template <typename EnumT> struct SvXMLEnumStringMapEntry;
53 
55 {
56 private:
57  std::u16string_view maTokenString;
60 
61 public:
62  SvXMLTokenEnumerator( std::u16string_view rString, sal_Unicode cSeparator = u' ' );
65  SvXMLTokenEnumerator( OUString&& , sal_Unicode cSeparator = u' ' ) = delete;
66 
67  bool getNextToken( std::u16string_view& rToken );
68 };
69 
81 {
82 private:
83  SvXMLUnitConverter(const SvXMLUnitConverter&) = delete;
84  SvXMLUnitConverter& operator=(const SvXMLUnitConverter&) = delete;
85 
86  struct SAL_DLLPRIVATE Impl;
87  ::std::unique_ptr<Impl> m_pImpl;
88 
89 public:
94  const css::uno::Reference< css::uno::XComponentContext >& xContext,
95  sal_Int16 eCoreMeasureUnit /*css::util::MeasureUnit*/,
96  sal_Int16 eXMLMeasureUnit /*css::util::MeasureUnit*/);
97 
99 
100  static sal_Int16 GetMeasureUnit(FieldUnit const nFieldUnit);
101 
103  void SetCoreMeasureUnit( sal_Int16 const eCoreMeasureUnit /*css::util::MeasureUnit*/);
104 
106  void SetXMLMeasureUnit( sal_Int16 const eXMLMeasureUnit /*css::util::MeasureUnit*/);
107 
109  sal_Int16 GetXMLMeasureUnit() const;
110 
112  const css::uno::Reference< css::text::XNumberingTypeInfo >& getNumTypeInfo() const;
113 
116  bool convertMeasureToCore( sal_Int32& rValue,
117  std::u16string_view rString,
118  sal_Int32 nMin = SAL_MIN_INT32,
119  sal_Int32 nMax = SAL_MAX_INT32) const;
120 
123  bool convertMeasureToCore( sal_Int32& rValue,
124  std::string_view rString,
125  sal_Int32 nMin = SAL_MIN_INT32,
126  sal_Int32 nMax = SAL_MAX_INT32) const;
127 
129  void convertMeasureToXML( OUStringBuffer& rBuffer,
130  sal_Int32 nMeasure ) const;
131 
133  OUString convertMeasureToXML( sal_Int32 nMeasure ) const;
134 
137  template<typename EnumT>
138  static bool convertEnum( EnumT& rEnum,
139  std::u16string_view rValue,
140  const SvXMLEnumMapEntry<EnumT> *pMap )
141  {
142  sal_uInt16 nTmp;
143  bool bRet = convertEnumImpl(nTmp, rValue,
144  reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(pMap));
145  if (bRet)
146  rEnum = static_cast<EnumT>(nTmp);
147  return bRet;
148  }
149 
152  template<typename EnumT>
153  static bool convertEnum( EnumT& rEnum,
154  std::string_view rValue,
155  const SvXMLEnumMapEntry<EnumT> *pMap )
156  {
157  sal_uInt16 nTmp;
158  bool bRet = convertEnumImpl(nTmp, rValue,
159  reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(pMap));
160  if (bRet)
161  rEnum = static_cast<EnumT>(nTmp);
162  return bRet;
163  }
164 
167  template<typename EnumT>
168  static bool convertEnum( EnumT& rEnum,
169  std::u16string_view rValue,
170  const SvXMLEnumStringMapEntry<EnumT> *pMap )
171  {
172  sal_uInt16 nTmp;
173  bool bRet = convertEnumImpl(nTmp, rValue,
174  reinterpret_cast<const SvXMLEnumStringMapEntry<sal_uInt16>*>(pMap));
175  if (bRet)
176  rEnum = static_cast<EnumT>(nTmp);
177  return bRet;
178  }
179 
182  template<typename EnumT>
183  static bool convertEnum( EnumT& rEnum,
184  std::string_view rValue,
185  const SvXMLEnumStringMapEntry<EnumT> *pMap )
186  {
187  sal_uInt16 nTmp;
188  bool bRet = convertEnumImpl(nTmp, rValue,
189  reinterpret_cast<const SvXMLEnumStringMapEntry<sal_uInt16>*>(pMap));
190  if (bRet)
191  rEnum = static_cast<EnumT>(nTmp);
192  return bRet;
193  }
194 
199  template<typename EnumT>
200  static bool convertEnum( OUStringBuffer& rBuffer,
201  EnumT nValue,
202  const SvXMLEnumMapEntry<EnumT> *pMap,
205  {
206  return convertEnumImpl(rBuffer, static_cast<sal_uInt16>(nValue),
207  reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(pMap), eDefault);
208  }
209 
212  void convertDouble(OUStringBuffer& rBuffer,
213  double fNumber) const;
214 
216  bool convertDouble(double& rValue, std::u16string_view rString) const;
217 
219  bool setNullDate (
220  const css::uno::Reference <css::frame::XModel>& xModel);
221 
223  void convertDateTime( OUStringBuffer& rBuffer,
224  const double& fDateTime,
225  bool const bAddTimeIf0AM = false);
226 
228  bool convertDateTime(double& fDateTime,
229  std::u16string_view rString);
230 
232  bool convertDateTime(double& fDateTime,
233  std::string_view rString);
234 
236 
238  static void convertDateTime( OUStringBuffer& rBuffer,
239  const double& fDateTime,
240  const css::util::Date& aNullDate,
241  bool bAddTimeIf0AM = false);
243  static bool convertDateTime( double& fDateTime,
244  std::u16string_view rString,
245  const css::util::Date& aNullDate);
247  static bool convertDateTime( double& fDateTime,
248  std::string_view rString,
249  const css::util::Date& aNullDate);
250 
251 
253  static bool convertB3DVector( ::basegfx::B3DVector& rVector,
254  std::u16string_view rValue );
255 
257  static bool convertB3DVector( ::basegfx::B3DVector& rVector,
258  std::string_view rValue );
259 
261  static void convertB3DVector( OUStringBuffer &rBuffer,
262  const ::basegfx::B3DVector& rVector );
263 
265  bool convertPosition3D( css::drawing::Position3D& rPosition,
266  std::string_view rValue );
267 
269  void convertPosition3D( OUStringBuffer &rBuffer,
270  const css::drawing::Position3D& rVector );
271 
272 
274  bool convertNumFormat( sal_Int16& rType,
275  const OUString& rNumFormat,
276  std::u16string_view rNumLetterSync,
277  bool bNumberNone = false ) const;
278 
280  void convertNumFormat( OUStringBuffer& rBuffer,
281  sal_Int16 nType ) const;
282  static void convertNumLetterSync( OUStringBuffer& rBuffer,
283  sal_Int16 nType );
284 
285  static void convertPropertySet(css::uno::Sequence<css::beans::PropertyValue>& rProps,
286  const css::uno::Reference<css::beans::XPropertySet>& aProperties);
287  static void convertPropertySet(css::uno::Reference<css::beans::XPropertySet> const & rProperties,
288  const css::uno::Sequence<css::beans::PropertyValue>& aProps);
289 
290  OUString encodeStyleName( const OUString& rName,
291  bool *pEncoded=nullptr ) const;
293  static bool convertHex( sal_uInt32& nVal,
294  std::u16string_view rValue );
295 
297  static void convertHex( OUStringBuffer& rBuffer,
298  sal_uInt32 nVal );
299 
300 private:
301  static bool convertEnumImpl( sal_uInt16& rEnum,
302  std::u16string_view rValue,
303  const SvXMLEnumMapEntry<sal_uInt16> *pMap );
304 
305  static bool convertEnumImpl( sal_uInt16& rEnum,
306  std::u16string_view rValue,
308 
309  static bool convertEnumImpl( sal_uInt16& rEnum,
310  std::string_view rValue,
311  const SvXMLEnumMapEntry<sal_uInt16> *pMap );
312 
313  static bool convertEnumImpl( sal_uInt16& rEnum,
314  std::string_view rValue,
316 
317  static bool convertEnumImpl( OUStringBuffer& rBuffer,
318  sal_uInt16 nValue,
319  const SvXMLEnumMapEntry<sal_uInt16> *pMap,
321 };
322 
323 #endif // INCLUDED_XMLOFF_XMLUCONV_HXX
324 
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumStringMapEntry< EnumT > *pMap)
convert string to enum using given token map, if the enum is not found in the map, this method will return false
Definition: xmluconv.hxx:168
FieldUnit
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:80
std::u16string_view maTokenString
Definition: xmluconv.hxx:57
sal_Unicode mcSeparator
Definition: xmluconv.hxx:59
static bool convertEnum(EnumT &rEnum, std::string_view rValue, const SvXMLEnumStringMapEntry< EnumT > *pMap)
convert string to enum using given token map, if the enum is not found in the map, this method will return false
Definition: xmluconv.hxx:183
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
sal_uInt16 sal_Unicode
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
exports com.sun.star. text
Map a const char* (with length) to a sal_uInt16 value.
Definition: xmlement.hxx:70
class SAL_NO_VTABLE XPropertySet
static bool convertEnum(OUStringBuffer &rBuffer, EnumT nValue, const SvXMLEnumMapEntry< EnumT > *pMap, enum::xmloff::token::XMLTokenEnum eDefault=::xmloff::token::XML_TOKEN_INVALID)
convert enum to string using given enum map with an optional default token.
Definition: xmluconv.hxx:200
static bool convertEnum(EnumT &rEnum, std::string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:153
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:40
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:138
#define XMLOFF_DLLPUBLIC
Definition: dllapi.h:29
::std::unique_ptr< Impl > m_pImpl
Definition: xmluconv.hxx:87