nss: upgrade to release 3.73
[LibreOffice.git] / l10ntools / inc / cfgmerge.hxx
blob3f4fdb55c9470b0148832baa6eda85935e92252c
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_CFGMERGE_HXX
21 #define INCLUDED_L10NTOOLS_INC_CFGMERGE_HXX
23 #include <sal/config.h>
25 #include <fstream>
26 #include <unordered_map>
27 #include <memory>
28 #include <vector>
29 #include "po.hxx"
31 typedef std::unordered_map<OString, OString> OStringHashMap;
36 class CfgStackData
38 friend class CfgParser;
39 friend class CfgExport;
40 friend class CfgMerge;
41 private:
42 OString sTagType;
43 OString sIdentifier;
45 OString sResTyp;
47 OString sTextTag;
48 OString sEndTextTag;
50 OStringHashMap sText;
51 public:
52 CfgStackData(const OString &rTag, const OString &rId)
53 : sTagType( rTag ), sIdentifier( rId )
56 const OString &GetTagType() const { return sTagType; }
57 const OString &GetIdentifier() const { return sIdentifier; }
64 class CfgStack
66 private:
67 std::vector< CfgStackData* > maList;
69 public:
70 CfgStack() {}
71 ~CfgStack();
73 CfgStackData *Push(const OString &rTag, const OString &rId);
74 void Pop()
76 if (!maList.empty())
78 delete maList.back();
79 maList.pop_back();
83 CfgStackData *GetStackData();
85 OString GetAccessPath( size_t nPos );
87 size_t size() const { return maList.size(); }
90 /// Parser for *.xcu files
91 class CfgParser
93 protected:
94 OString sCurrentResTyp;
95 OString sCurrentIsoLang;
96 OString sCurrentText;
98 OString sLastWhitespace;
100 CfgStack aStack;
101 CfgStackData *pStackData;
103 bool bLocalize;
105 virtual void WorkOnText(
106 OString &rText,
107 const OString &rLangIndex )=0;
109 virtual void WorkOnResourceEnd()=0;
111 virtual void Output(const OString & rOutput)=0;
113 private:
114 void ExecuteAnalyzedToken( int nToken, char *pToken );
115 void AddText(
116 OString &rText,
117 const OString &rIsoLang,
118 const OString &rResTyp );
120 static bool IsTokenClosed(const OString &rToken);
122 public:
123 CfgParser();
124 virtual ~CfgParser();
126 void Execute( int nToken, char * pToken );
129 /// Export strings from *.xcu files
130 class CfgExport : public CfgParser
132 private:
133 OString sPath;
134 PoOfstream pOutputStream;
136 protected:
137 virtual void WorkOnText(
138 OString &rText,
139 const OString &rIsoLang
140 ) override;
142 void WorkOnResourceEnd() override;
143 void Output(const OString& rOutput) override;
144 public:
145 CfgExport(
146 const OString &rOutputFile,
147 const OString &rFilePath
149 virtual ~CfgExport() override;
152 /// Merge strings to *.xcu files
153 class CfgMerge : public CfgParser
155 private:
156 std::unique_ptr<MergeDataFile> pMergeDataFile;
157 std::vector<OString> aLanguages;
158 std::unique_ptr<ResData> pResData;
160 OString sFilename;
161 bool bEnglish;
163 std::ofstream pOutputStream;
165 protected:
166 virtual void WorkOnText(OString &rText, const OString &rLangIndex) override;
168 void WorkOnResourceEnd() override;
170 void Output(const OString& rOutput) override;
171 public:
172 CfgMerge(
173 const OString &rMergeSource, const OString &rOutputFile,
174 const OString &rFilename, const OString &rLanguage );
175 virtual ~CfgMerge() override;
178 #endif
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */