LibreOffice Module l10ntools (master) 1
cfgmerge.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_L10NTOOLS_INC_CFGMERGE_HXX
21#define INCLUDED_L10NTOOLS_INC_CFGMERGE_HXX
22
23#include <sal/config.h>
24
25#include <fstream>
26#include <unordered_map>
27#include <memory>
28#include <utility>
29#include <vector>
30#include "po.hxx"
31#include "export.hxx"
32
33typedef std::unordered_map<OString, OString> OStringHashMap;
34
35
36
37
39{
40friend class CfgParser;
41friend class CfgExport;
42friend class CfgMerge;
43private:
44 OString sTagType;
45 OString sIdentifier;
46
47 OString sResTyp;
48
49 OString sTextTag;
50 OString sEndTextTag;
51
53public:
54 CfgStackData(OString _sTag, OString _sId)
55 : sTagType(std::move( _sTag )), sIdentifier(std::move( _sId ))
56 {}
57
58 const OString &GetTagType() const { return sTagType; }
59 const OString &GetIdentifier() const { return sIdentifier; }
60
61};
62
63
64
65
67{
68private:
69 std::vector< CfgStackData* > maList;
70
71public:
73 ~CfgStack();
74
75 CfgStackData *Push(const OString &rTag, const OString &rId);
76 void Pop()
77 {
78 if (!maList.empty())
79 {
80 delete maList.back();
81 maList.pop_back();
82 }
83 }
84
86
87 OString GetAccessPath( size_t nPos );
88
89 size_t size() const { return maList.size(); }
90};
91
94{
95protected:
98 OString sCurrentText;
99
101
104
106
107 virtual void WorkOnText(
108 OString &rText,
109 const OString &rLangIndex )=0;
110
111 virtual void WorkOnResourceEnd()=0;
112
113 virtual void Output(const OString & rOutput)=0;
114
115private:
116 void ExecuteAnalyzedToken( int nToken, char *pToken );
117 void AddText(
118 OString &rText,
119 const OString &rIsoLang,
120 const OString &rResTyp );
121
122 static bool IsTokenClosed(std::string_view rToken);
123
124public:
125 CfgParser();
126 virtual ~CfgParser();
127
128 void Execute( int nToken, char * pToken );
129};
130
132class CfgExport : public CfgParser
133{
134private:
135 OString sPath;
137
138protected:
139 virtual void WorkOnText(
140 OString &rText,
141 const OString &rIsoLang
142 ) override;
143
144 void WorkOnResourceEnd() override;
145 void Output(const OString& rOutput) override;
146public:
147 CfgExport(
148 const OString &rOutputFile,
149 OString sFilePath
150 );
151 virtual ~CfgExport() override;
152};
153
155class CfgMerge : public CfgParser
156{
157private:
158 std::unique_ptr<MergeDataFile> pMergeDataFile;
159 std::vector<OString> aLanguages;
160 std::unique_ptr<ResData> pResData;
161
162 OString sFilename;
164
165 std::ofstream pOutputStream;
166
167protected:
168 virtual void WorkOnText(OString &rText, const OString &rLangIndex) override;
169
170 void WorkOnResourceEnd() override;
171
172 void Output(const OString& rOutput) override;
173public:
174 CfgMerge(
175 const OString &rMergeSource, const OString &rOutputFile,
176 OString sFilename, const OString &rLanguage );
177 virtual ~CfgMerge() override;
178};
179
180#endif
181
182/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< OString, OString > OStringHashMap
Definition: cfgmerge.hxx:33
Export strings from *.xcu files.
Definition: cfgmerge.hxx:133
PoOfstream pOutputStream
Definition: cfgmerge.hxx:136
virtual void WorkOnText(OString &rText, const OString &rIsoLang) override
Definition: cfgmerge.cxx:391
virtual ~CfgExport() override
Definition: cfgmerge.cxx:357
OString sPath
Definition: cfgmerge.hxx:135
void Output(const OString &rOutput) override
Definition: cfgmerge.cxx:307
void WorkOnResourceEnd() override
Definition: cfgmerge.cxx:363
CfgExport(const OString &rOutputFile, OString sFilePath)
Definition: cfgmerge.cxx:344
Merge strings to *.xcu files.
Definition: cfgmerge.hxx:156
std::vector< OString > aLanguages
Definition: cfgmerge.hxx:159
virtual void WorkOnText(OString &rText, const OString &rLangIndex) override
Definition: cfgmerge.cxx:435
CfgMerge(const OString &rMergeSource, const OString &rOutputFile, OString sFilename, const OString &rLanguage)
Definition: cfgmerge.cxx:402
OString sFilename
Definition: cfgmerge.hxx:162
virtual ~CfgMerge() override
Definition: cfgmerge.cxx:430
void Output(const OString &rOutput) override
Definition: cfgmerge.cxx:460
std::unique_ptr< ResData > pResData
Definition: cfgmerge.hxx:160
bool bEnglish
Definition: cfgmerge.hxx:163
std::ofstream pOutputStream
Definition: cfgmerge.hxx:165
std::unique_ptr< MergeDataFile > pMergeDataFile
Definition: cfgmerge.hxx:158
void WorkOnResourceEnd() override
Definition: cfgmerge.cxx:465
Parser for *.xcu files.
Definition: cfgmerge.hxx:94
void ExecuteAnalyzedToken(int nToken, char *pToken)
Definition: cfgmerge.cxx:175
OString sLastWhitespace
Definition: cfgmerge.hxx:100
virtual void WorkOnText(OString &rText, const OString &rLangIndex)=0
virtual ~CfgParser()
Definition: cfgmerge.cxx:135
virtual void Output(const OString &rOutput)=0
OString sCurrentResTyp
Definition: cfgmerge.hxx:96
CfgStackData * pStackData
Definition: cfgmerge.hxx:103
CfgStack aStack
Definition: cfgmerge.hxx:102
OString sCurrentIsoLang
Definition: cfgmerge.hxx:97
static bool IsTokenClosed(std::string_view rToken)
Definition: cfgmerge.cxx:154
bool bLocalize
Definition: cfgmerge.hxx:105
virtual void WorkOnResourceEnd()=0
void AddText(OString &rText, const OString &rIsoLang, const OString &rResTyp)
Definition: cfgmerge.cxx:159
OString sCurrentText
Definition: cfgmerge.hxx:98
void Execute(int nToken, char *pToken)
Definition: cfgmerge.cxx:311
const OString & GetTagType() const
Definition: cfgmerge.hxx:58
OStringHashMap sText
Definition: cfgmerge.hxx:52
const OString & GetIdentifier() const
Definition: cfgmerge.hxx:59
OString sTextTag
Definition: cfgmerge.hxx:49
OString sIdentifier
Definition: cfgmerge.hxx:45
CfgStackData(OString _sTag, OString _sId)
Definition: cfgmerge.hxx:54
OString sResTyp
Definition: cfgmerge.hxx:47
OString sTagType
Definition: cfgmerge.hxx:44
OString sEndTextTag
Definition: cfgmerge.hxx:50
void Pop()
Definition: cfgmerge.hxx:76
CfgStackData * GetStackData()
Definition: cfgmerge.cxx:118
OString GetAccessPath(size_t nPos)
Definition: cfgmerge.cxx:105
size_t size() const
Definition: cfgmerge.hxx:89
CfgStack()
Definition: cfgmerge.hxx:72
std::vector< CfgStackData * > maList
Definition: cfgmerge.hxx:69
CfgStackData * Push(const OString &rTag, const OString &rId)
Definition: cfgmerge.cxx:91
Interface to write po entry to files as output streams.
Definition: po.hxx:101