1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
29 #include <osl/file.hxx>
34 #include <unordered_map>
45 #define NO_TRANSLATE_ISO "x-no-translate"
49 typedef std::unordered_map
<OString
, OString
, OStringHash
>
52 typedef std::unordered_map
<OString
, bool, OStringHash
>
55 #define SOURCE_LANGUAGE "en-US"
56 #define X_COMMENT "x-comment"
62 #define ID_LEVEL_NULL 0x0000
63 #define ID_LEVEL_TEXT 0x0002
64 #define ID_LEVEL_IDENTIFIER 0x0005
66 typedef std::vector
< OString
> ExportList
;
68 /// Purpose: holds mandatory data to export a single res (used with ResStack)
72 ResData( const OString
&rGId
);
73 ResData( const OString
&rGId
, const OString
&rFilename
);
74 bool SetId(const OString
&rId
, sal_uInt16 nLevel
);
91 OStringHashMap sQuickHelpText
;
93 OStringHashMap sTitle
;
105 #define LIST_NON 0x0000
106 #define LIST_STRING 0x0001
107 #define LIST_FILTER 0x0002
108 #define LIST_ITEM 0x0004
109 #define LIST_PAIRED 0x0005
110 #define STRING_TYP_TEXT 0x0010
111 #define STRING_TYP_QUICKHELPTEXT 0x0040
112 #define STRING_TYP_TITLE 0x0080
115 typedef ::std::vector
< ResData
* > ResStack
;
118 /// Purpose: syntax check and export of *.src, called from lexer
124 std::ofstream
* mSimple
;
129 ResStack aResStack
; ///< stack for parsing recursive
131 bool bDefine
; // cur. res. in a define?
132 bool bNextMustBeDefineEOL
; ///< define but no \ at lineend
133 std::size_t nLevel
; // res. recursiv? how deep?
134 sal_uInt16 nList
; ///< cur. res. is List
135 std::size_t nListIndex
;
136 std::size_t nListLevel
;
139 bool bError
; // any errors while export?
144 std::vector
<OString
> aLanguages
;
146 ParserQueue
* pParseQueue
;
148 bool WriteData( ResData
*pResData
, bool bCreateNew
= false ); ///< called before dest. cur ResData
149 bool WriteExportList( ResData
*pResData
, ExportList
& rExportList
, const sal_uInt16 nTyp
);
151 OString
MergePairedList( OString
const & sLine
, OString
const & sText
);
153 OString
FullId(); ///< creates cur. GID
155 static OString
GetPairedListID(const OString
& rText
);
156 static OString
GetPairedListString(const OString
& rText
);
157 static OString
StripList(const OString
& rText
);
159 void InsertListEntry(const OString
&rLine
);
160 static void CleanValue( OString
&rValue
);
161 static OString
GetText(const OString
&rSource
, int nToken
);
163 void ResData2Output( MergeEntrys
*pEntry
, sal_uInt16 nType
, const OString
& rTextType
);
164 void MergeRest( ResData
*pResData
);
165 static void ConvertMergeContent( OString
&rText
);
166 static void ConvertExportContent( OString
&rText
);
168 void WriteToMerged(const OString
&rText
, bool bSDFContent
);
169 void SetChildWithText();
171 static void CutComment( OString
&rText
);
173 void WriteUTF8ByteOrderMarkToOutput() { *aOutput
.mSimple
<< '\xEF' << '\xBB' << '\xBF'; }
176 Export( const OString
&rOutput
);
177 Export(const OString
&rMergeSource
, const OString
&rOutput
, const OString
&rLanguage
, bool bUTF8BOM
);
181 int Execute( int nToken
, const char * pToken
); ///< called from lexer
183 void SetError() { bError
= true; }
184 bool GetError() { return bError
; }
185 ParserQueue
* GetParseQueue() { return pParseQueue
; }
192 /// Purpose: holds information of data to merge
195 friend class MergeDataFile
;
197 OStringHashMap sText
;
198 OStringBoolHashMap bTextFirst
;
199 OStringHashMap sQuickHelpText
;
200 OStringBoolHashMap bQuickHelpTextFirst
;
201 OStringHashMap sTitle
;
202 OStringBoolHashMap bTitleFirst
;
206 void InsertEntry(const OString
&rId
, const OString
&rText
,
207 const OString
&rQuickHelpText
, const OString
&rTitle
)
210 sText
[ rId
] = rText
;
211 bTextFirst
[ rId
] = true;
212 sQuickHelpText
[ rId
] = rQuickHelpText
;
213 bQuickHelpTextFirst
[ rId
] = true;
214 sTitle
[ rId
] = rTitle
;
215 bTitleFirst
[ rId
] = true;
217 bool GetText( OString
&rReturn
, sal_uInt16 nTyp
, const OString
&nLangIndex
, bool bDel
= false );
220 Generate QTZ string with ResData
221 For executable which works one language and without PO files.
223 static OString
GetQTZText(const ResData
& rResData
, const OString
& rOrigText
);
228 // class MergeDataHashMap
233 /** Container for MergeData
235 This class is an HashMap with a hidden insertion
236 order. The class can used just like a simple
237 HashMap, but good to know that it's use is
238 more effective if the accessing(find) order
239 match with the insertion order.
241 In the most case, this match is good.
242 (e.g. reading PO files of different languages,
245 class MergeDataHashMap
248 typedef std::unordered_map
<OString
, MergeData
*, OStringHash
> HashMap_t
;
253 , aLastInsertion(m_aHashMap
.end())
254 , aLastFound(m_aHashMap
.end())
255 , aFirstInOrder(m_aHashMap
.end())
263 typedef HashMap_t::iterator iterator
;
264 typedef HashMap_t::const_iterator const_iterator
;
266 std::pair
<iterator
,bool> insert(const OString
& rKey
, MergeData
* pMergeData
);
267 iterator
find(const OString
& rKey
);
269 iterator
begin() {return m_aHashMap
.begin();}
270 iterator
end() {return m_aHashMap
.end();}
272 const_iterator
begin() const {return m_aHashMap
.begin();}
273 const_iterator
end() const {return m_aHashMap
.end();}
277 HashMap_t m_aHashMap
;
278 iterator aLastInsertion
;
280 iterator aFirstInOrder
;
287 /// Purpose: holds information of data to merge (one resource)
290 friend class MergeDataHashMap
;
297 MergeEntrys
* pMergeEntrys
;
299 MergeDataHashMap::iterator m_aNextData
;
301 MergeData( const OString
&rTyp
, const OString
&rGID
, const OString
&rLID
, const OString
&rFilename
);
303 MergeEntrys
* GetMergeEntries() { return pMergeEntrys
;}
305 bool operator==( ResData
*pData
);
309 // class MergeDataFile
312 /// Purpose: holds information of data to merge, read from PO file
316 MergeDataHashMap aMap
;
317 std::set
<OString
> aLanguageSet
;
319 MergeData
*GetMergeData( ResData
*pResData
, bool bCaseSensitve
= false );
320 void InsertEntry(const OString
&rTYP
, const OString
&rGID
,
321 const OString
&rLID
, const OString
&nLang
,
322 const OString
&rTEXT
, const OString
&rQHTEXT
,
323 const OString
&rTITLE
, const OString
&sFilename
,
324 bool bFirstLang
, bool bCaseSensitive
);
326 explicit MergeDataFile(
327 const OString
&rFileName
, const OString
& rFile
,
328 bool bCaseSensitive
, bool bWithQtz
= true );
332 std::vector
<OString
> GetLanguages() const;
333 const MergeDataHashMap
& getMap() const { return aMap
; }
335 MergeEntrys
*GetMergeEntrys( ResData
*pResData
);
336 MergeEntrys
*GetMergeEntrysCaseSensitive( ResData
*pResData
);
338 static OString
CreateKey(const OString
& rTYP
, const OString
& rGID
,
339 const OString
& rLID
, const OString
& rFilename
, bool bCaseSensitive
= false);
346 QueueEntry(int nTypVal
, const OString
&rLineVal
)
347 : nTyp(nTypVal
), sLine(rLineVal
)
358 ParserQueue( Export
& aExportObj
);
361 inline void Push( const QueueEntry
& aEntry
);
362 bool bCurrentIsM
; // public ?
363 bool bNextIsM
; // public ?
364 bool bLastWasM
; // public ?
365 bool bMflag
; // public ?
369 std::queue
<QueueEntry
>* aQueueNext
;
370 std::queue
<QueueEntry
>* aQueueCur
;
375 inline void Pop( std::queue
<QueueEntry
>& aQueue
);
378 #endif // INCLUDED_L10NTOOLS_INC_EXPORT_HXX
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */