summaryrefslogtreecommitdiff
path: root/l10ntools/source/gConvXcu.cxx
blob: 58f22d78493cce7e0e7805cdf5dfb21fce08620d (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
181
182
/* -*- 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 .
 */
#include <string>
#include <vector>
using namespace std;



#include "gL10nMem.hxx"
#include "gConvXcu.hxx"



convert_xcu::convert_xcu(l10nMem& crMemory)
                        : convert_gen(crMemory),
                          mbNoCollectingData(true),
                          miLevel(0),
                          mbNoTranslate(false)
{
}



void convert_xcu::doExecute()
{
    xculex();
}



void convert_xcu::pushKey(char *syyText)
{
    string sKey, sTag = copySource(syyText);
    int    nL, nE;

    // find key in tag
    nL = sTag.find("oor:name=\"");
    if (nL != (int)string::npos) {
        // find end of key
        nL += 10;
        nE  = sTag.find("\"", nL);
        if (nE != (int)string::npos)
            sKey = sTag.substr(nL, nE - nL);
    }
    mcStack.push_back(sKey);
}



void convert_xcu::popKey(char *syyText)
{
    copySource(syyText);

    // check for correct node/prop relations
    if (mcStack.size())
        mcStack.pop_back();

    mbNoTranslate = false;
}



void convert_xcu::startCollectData(char *syyText)
{
    int nL;
    string sTag = copySource(syyText);

    if (mbNoTranslate)
        return;

    // locate object name
    nL = sTag.find("xml:lang=\"");
    if (nL != (int)string::npos) {
        // test language
        nL += 10;
        if (sTag.substr(nL,5) == "en-US")
            mbNoCollectingData = false;
        else if (sTag.substr(nL,14) == "x-no-translate")
            mbNoTranslate = true;
        else {
            string sErr = sTag.substr(nL,5) + " is not en-US";
            l10nMem::showError(sErr);
        }
    }
}



void convert_xcu::stopCollectData(char *syyText)
{
    int    nL;
    string useKey, useText = msCollector;

    copySource(syyText);

    // time to do something ?
    if (mbNoCollectingData || mbNoTranslate)
        return;

    // remove any newline
    for (nL = 0;;) {
        nL = useText.find("\n");
        if (nL == (int)string::npos)
            break;
        useText.erase(nL,1);
    }

    mbNoCollectingData = true;

    if (useText.size()) {
        // locate key and extract it
        int max = (int)mcStack.size() - 1;
        for (nL = 0; nL < max; ++nL) {
            useKey += mcStack[nL];
            if (nL < max -1)
                useKey += ".";
        }
        mcMemory.setSourceKey(miLineNo, msSourceFile, useKey, useText, "", "value", mcStack[nL], mbMergeMode);
    }

    if (mbMergeMode) {
        string sLang, sText, sNewLine;

        // prepare to read all languages
        mcMemory.prepareMerge();
        for (; mcMemory.getMergeLang(sLang, sText);) {
            sNewLine = "\n<value xml:lang=\"" + sLang + "\">" + sText + "</value>";
            mcMemory.convertToInetString(sNewLine);
            writeSourceFile(sNewLine);
        }
    }
}



void convert_xcu::copySpecial(char *syyText)
{
    int         nx    = msCollector.size();
    string sText = copySource(syyText, mbNoCollectingData);

    if (!mbNoCollectingData) {
        msCollector.erase(nx);
        mcMemory.convertFromInetString(sText);
        msCollector += sText;
    }
}



void convert_xcu::copyNL(char *syyText)
{
    int         nX    = msCollector.size();
    string sText = copySource(syyText, mbNoCollectingData);

    if (!mbNoCollectingData) {
        msCollector.erase(nX);
        msCollector += ' ';
    }
}



void convert_xcu::addLevel()
{
    ++miLevel;
}