summaryrefslogtreecommitdiff
path: root/l10ntools/inc/cfgmerge.hxx
blob: 3f4fdb55c9470b0148832baa6eda85935e92252c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_L10NTOOLS_INC_CFGMERGE_HXX
#define INCLUDED_L10NTOOLS_INC_CFGMERGE_HXX

#include <sal/config.h>

#include <fstream>
#include <unordered_map>
#include <memory>
#include <vector>
#include "po.hxx"

typedef std::unordered_map<OString, OString> OStringHashMap;




class CfgStackData
{
friend class CfgParser;
friend class CfgExport;
friend class CfgMerge;
private:
    OString sTagType;
    OString sIdentifier;

    OString sResTyp;

    OString sTextTag;
    OString sEndTextTag;

    OStringHashMap sText;
public:
    CfgStackData(const OString &rTag, const OString &rId)
        : sTagType( rTag ), sIdentifier( rId )
    {}

    const OString &GetTagType() const { return sTagType; }
    const OString &GetIdentifier() const { return sIdentifier; }

};




class CfgStack
{
private:
    std::vector< CfgStackData* > maList;

public:
    CfgStack() {}
    ~CfgStack();

    CfgStackData *Push(const OString &rTag, const OString &rId);
    void Pop()
    {
        if (!maList.empty())
        {
            delete maList.back();
            maList.pop_back();
        }
    }

    CfgStackData *GetStackData();

    OString GetAccessPath( size_t nPos );

    size_t size() const { return maList.size(); }
};

/// Parser for *.xcu files
class CfgParser
{
protected:
    OString sCurrentResTyp;
    OString sCurrentIsoLang;
    OString sCurrentText;

    OString sLastWhitespace;

    CfgStack aStack;
    CfgStackData *pStackData;

    bool bLocalize;

    virtual void WorkOnText(
        OString &rText,
        const OString &rLangIndex )=0;

    virtual void WorkOnResourceEnd()=0;

    virtual void Output(const OString & rOutput)=0;

private:
    void ExecuteAnalyzedToken( int nToken, char *pToken );
    void AddText(
        OString &rText,
        const OString &rIsoLang,
        const OString &rResTyp );

    static bool IsTokenClosed(const OString &rToken);

public:
    CfgParser();
    virtual ~CfgParser();

    void Execute( int nToken, char * pToken );
};

/// Export strings from *.xcu files
class CfgExport : public CfgParser
{
private:
    OString sPath;
    PoOfstream pOutputStream;

protected:
    virtual void WorkOnText(
        OString &rText,
        const OString &rIsoLang
        ) override;

    void WorkOnResourceEnd() override;
    void Output(const OString& rOutput) override;
public:
    CfgExport(
        const OString &rOutputFile,
        const OString &rFilePath
    );
    virtual ~CfgExport() override;
};

/// Merge strings to *.xcu files
class CfgMerge : public CfgParser
{
private:
    std::unique_ptr<MergeDataFile> pMergeDataFile;
    std::vector<OString> aLanguages;
    std::unique_ptr<ResData> pResData;

    OString sFilename;
    bool bEnglish;

    std::ofstream pOutputStream;

protected:
    virtual void WorkOnText(OString &rText, const OString &rLangIndex) override;

    void WorkOnResourceEnd() override;

    void Output(const OString& rOutput) override;
public:
    CfgMerge(
        const OString &rMergeSource, const OString &rOutputFile,
        const OString &rFilename, const OString &rLanguage );
    virtual ~CfgMerge() override;
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */