Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / l10ntools / inc / export.hxx
blobc2d43b75a60ca39a443e0e745b1eb0d3bd8b1576
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 #ifndef INCLUDED_L10NTOOLS_INC_EXPORT_HXX
21 #define INCLUDED_L10NTOOLS_INC_EXPORT_HXX
23 #include <sal/config.h>
24 #include "po.hxx"
26 #include <cstddef>
27 #include <fstream>
29 #include <osl/file.hxx>
30 #include <osl/file.h>
32 #include <iterator>
33 #include <set>
34 #include <unordered_map>
35 #include <memory>
36 #include <vector>
37 #include <queue>
38 #include <string>
40 #ifdef _WIN32
41 #include <direct.h>
42 #else
43 #include <unistd.h>
44 #endif
46 #define NO_TRANSLATE_ISO "x-no-translate"
48 class MergeEntrys;
50 typedef std::unordered_map<OString, OString>
51 OStringHashMap;
53 typedef std::unordered_map<OString, bool>
54 OStringBoolHashMap;
56 #define SOURCE_LANGUAGE "en-US"
57 #define X_COMMENT "x-comment"
60 // class ResData
63 enum class IdLevel { Null=0, Text=2, Identifier=5 };
65 /// Purpose: holds mandatory data to export a single res
66 class ResData
68 public:
69 ResData( const OString &rGId );
70 ResData( const OString &rGId , const OString &rFilename );
72 OString sResTyp;
73 OString sId;
74 OString sGId;
75 OString sFilename;
77 OStringHashMap sText;
81 // class Export
84 enum class ExportListType {
85 NONE, String, Filter, Item, Paired
88 enum class StringType {
89 Text, QuickHelpText, Title
93 class ParserQueue;
95 // class MergeEntrys
98 /// Purpose: holds information of data to merge
99 class MergeEntrys
101 friend class MergeDataFile;
102 private:
103 OStringHashMap sText;
104 OStringBoolHashMap bTextFirst;
105 OStringHashMap sQuickHelpText;
106 OStringBoolHashMap bQuickHelpTextFirst;
107 OStringHashMap sTitle;
108 OStringBoolHashMap bTitleFirst;
110 public:
111 MergeEntrys(){};
112 void InsertEntry(const OString &rId, const OString &rText,
113 const OString &rQuickHelpText, const OString &rTitle)
116 sText[ rId ] = rText;
117 bTextFirst[ rId ] = true;
118 sQuickHelpText[ rId ] = rQuickHelpText;
119 bQuickHelpTextFirst[ rId ] = true;
120 sTitle[ rId ] = rTitle;
121 bTitleFirst[ rId ] = true;
123 bool GetText( OString &rReturn, const OString &nLangIndex, bool bDel = false );
126 Generate QTZ string with ResData
127 For executable which works one language and without PO files.
129 static OString GetQTZText(const ResData& rResData, const OString& rOrigText);
134 // class MergeDataHashMap
137 class MergeData;
139 /** Container for MergeData
141 This class is an HashMap with a hidden insertion
142 order. The class can used just like a simple
143 HashMap, but good to know that it's use is
144 more effective if the accessing(find) order
145 match with the insertion order.
147 In the most case, this match is good.
148 (e.g. reading PO files of different languages,
149 executables merging)
151 class MergeDataHashMap
153 private:
154 typedef std::unordered_map<OString, std::unique_ptr<MergeData>> HashMap_t;
156 public:
157 MergeDataHashMap()
158 : bFirstSearch(true)
159 , aLastInsertion(m_aHashMap.end())
160 , aLastFound(m_aHashMap.end())
161 , aFirstInOrder(m_aHashMap.end())
165 typedef HashMap_t::iterator iterator;
166 typedef HashMap_t::const_iterator const_iterator;
168 std::pair<iterator,bool> insert(const OString& rKey, std::unique_ptr<MergeData> pMergeData);
169 iterator const & find(const OString& rKey);
171 iterator end() {return m_aHashMap.end();}
173 private:
174 bool bFirstSearch;
175 HashMap_t m_aHashMap;
176 iterator aLastInsertion;
177 iterator aLastFound;
178 iterator aFirstInOrder;
182 // class MergeData
185 /// Purpose: holds information of data to merge (one resource)
186 class MergeData
188 friend class MergeDataHashMap;
190 public:
191 std::unique_ptr<MergeEntrys> pMergeEntrys;
192 private:
193 MergeDataHashMap::iterator m_aNextData;
194 public:
195 MergeData();
196 ~MergeData();
197 MergeEntrys* GetMergeEntries() { return pMergeEntrys.get();}
202 // class MergeDataFile
205 /// Purpose: holds information of data to merge, read from PO file
206 class MergeDataFile
208 private:
209 MergeDataHashMap aMap;
210 std::set<OString> aLanguageSet;
212 MergeData *GetMergeData( ResData *pResData , bool bCaseSensitive = false );
213 void InsertEntry(const OString &rTYP, const OString &rGID,
214 const OString &rLID, const OString &nLang,
215 const OString &rTEXT, const OString &rQHTEXT,
216 const OString &rTITLE, const OString &sFilename,
217 bool bFirstLang, bool bCaseSensitive);
218 public:
219 explicit MergeDataFile(
220 const OString &rFileName, const OString& rFile,
221 bool bCaseSensitive, bool bWithQtz = true );
222 ~MergeDataFile();
225 std::vector<OString> GetLanguages() const;
227 MergeEntrys *GetMergeEntrys( ResData *pResData );
228 MergeEntrys *GetMergeEntrysCaseSensitive( ResData *pResData );
230 static OString CreateKey(const OString& rTYP, const OString& rGID,
231 const OString& rLID, const OString& rFilename, bool bCaseSensitive);
235 #endif // INCLUDED_L10NTOOLS_INC_EXPORT_HXX
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */