LibreOffice Module sw (master)  1
iodetect.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_SW_INC_IODETECT_HXX
21 #define INCLUDED_SW_INC_IODETECT_HXX
22 
23 #include <memory>
24 #include <string_view>
25 #include <o3tl/string_view.hxx>
26 #include <rtl/ustring.hxx>
27 #include <tools/lineend.hxx>
28 #include <tools/solar.h>
29 #include "swdllapi.h"
30 
31 inline constexpr OUStringLiteral FILTER_RTF = u"RTF";
32 inline constexpr OUStringLiteral sRtfWH = u"WH_RTF";
33 inline constexpr OUStringLiteral FILTER_TEXT = u"TEXT";
34 inline constexpr OUStringLiteral FILTER_BAS = u"BAS";
35 inline constexpr OUStringLiteral FILTER_WW8 = u"CWW8";
36 inline constexpr OUStringLiteral FILTER_TEXT_DLG = u"TEXT_DLG";
37 inline constexpr OUStringLiteral FILTER_XML = u"CXML";
38 #define FILTER_XMLV "CXMLV"
39 #define FILTER_XMLVW "CXMLVWEB"
40 inline constexpr OUStringLiteral FILTER_DOCX = u"OXML";
41 inline constexpr OUStringLiteral sHTML = u"HTML";
42 inline constexpr OUStringLiteral sWW5 = u"WW6";
43 inline constexpr OUStringLiteral sWW6 = u"CWW6";
44 
45 inline constexpr OUStringLiteral sSWRITER = u"swriter";
46 inline constexpr OUStringLiteral sSWRITERWEB = u"swriter/web";
47 
48 class SfxFilter;
49 class SfxFilterContainer;
50 class SotStorage;
51 class SvStream;
52 namespace com::sun::star::embed { class XStorage; }
53 namespace com::sun::star::uno { template <typename> class Reference; }
54 
55 struct SwIoDetect
56 {
57  const OUString sName;
58 
59  SwIoDetect(const OUString &rN)
60  : sName(rN)
61  {
62  }
63 
64  bool IsFilter( std::u16string_view rNm ) const
65  {
66  return o3tl::starts_with(rNm, sName);
67  }
68 };
69 
83 };
84 
85 extern SwIoDetect aFilterDetect[];
86 
93 {
94 public:
96  SW_DLLPUBLIC static std::shared_ptr<const SfxFilter>
97  GetFilterOfFormat( std::u16string_view rFormat,
98  const SfxFilterContainer* pCnt = nullptr );
99 
103  static std::shared_ptr<const SfxFilter> GetFileFilter(const OUString& rFileName);
104 
105  static bool IsValidStgFilter( SotStorage& , const SfxFilter& );
106  static bool IsValidStgFilter( const css::uno::Reference < css::embed::XStorage >& rStg, const SfxFilter& rFilter);
107 
108  // tdf#106899 - wrapper around IsDetectableText to retrieve the text encoding for a given stream
109  SW_DLLPUBLIC static rtl_TextEncoding GetTextEncoding(SvStream&);
110  static bool IsDetectableText( const char* pBuf, sal_uLong &rLen,
111  rtl_TextEncoding *pCharSet, bool *pSwap, LineEnd *pLineEnd, bool *pBom);
112 
113  static OUString GetSubStorageName( const SfxFilter& rFltr );
114 };
115 
116 extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestImportFODT(SvStream &rStream);
117 
118 #endif
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool IsDetectableText(const char *pBuf, sal_uLong &rLen, rtl_TextEncoding *pCharSet, bool *pSwap, LineEnd *pLineEnd, bool *pBom)
Definition: iodetect.cxx:257
static SW_DLLPUBLIC rtl_TextEncoding GetTextEncoding(SvStream &)
Definition: iodetect.cxx:241
constexpr OUStringLiteral FILTER_TEXT_DLG
text filter with encoding dialog
Definition: iodetect.hxx:36
constexpr OUStringLiteral sWW6
Definition: iodetect.hxx:43
sal_uIntPtr sal_uLong
SwIoDetect(const OUString &rN)
Definition: iodetect.hxx:59
bool IsFilter(std::u16string_view rNm) const
Definition: iodetect.hxx:64
ReaderWriterEnum
Definition: iodetect.hxx:70
Reference
constexpr OUStringLiteral sWW5
Definition: iodetect.hxx:42
constexpr OUStringLiteral FILTER_RTF
RTF filter.
Definition: iodetect.hxx:31
const OUString sName
Definition: iodetect.hxx:57
constexpr OUStringLiteral FILTER_TEXT
text filter with default codeset
Definition: iodetect.hxx:33
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
static bool IsValidStgFilter(SotStorage &, const SfxFilter &)
Definition: iodetect.cxx:112
constexpr OUStringLiteral sHTML
Definition: iodetect.hxx:41
constexpr OUStringLiteral FILTER_WW8
WinWord 97 filter.
Definition: iodetect.hxx:35
SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestImportFODT(SvStream &rStream)
Definition: xmlimp.cxx:1713
constexpr OUStringLiteral FILTER_BAS
StarBasic (identical to ANSI)
Definition: iodetect.hxx:34
The following class is a wrapper for basic i/o functions of Writer 3.0.
Definition: iodetect.hxx:92
static SW_DLLPUBLIC std::shared_ptr< const SfxFilter > GetFilterOfFormat(std::u16string_view rFormat, const SfxFilterContainer *pCnt=nullptr)
find for an internal format name the corresponding filter entry
Definition: iodetect.cxx:68
float u
constexpr OUStringLiteral sRtfWH
Definition: iodetect.hxx:32
constexpr OUStringLiteral sSWRITERWEB
Definition: iodetect.hxx:46
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
LineEnd
static std::shared_ptr< const SfxFilter > GetFileFilter(const OUString &rFileName)
Detect for the given file which filter should be used.
Definition: iodetect.cxx:149
static OUString GetSubStorageName(const SfxFilter &rFltr)
Definition: iodetect.cxx:55
constexpr OUStringLiteral sSWRITER
Definition: iodetect.hxx:45
constexpr OUStringLiteral FILTER_XML
XML filter.
Definition: iodetect.hxx:37
SwIoDetect aFilterDetect[]
Definition: iodetect.cxx:40