LibreOffice Module i18npool (master) 1
LocaleNode.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#pragma once
20
21#include <string>
22#include <string_view>
23#include <vector>
24#include <memory>
25
26#include <com/sun/star/uno/Sequence.hxx>
27
28namespace com::sun::star::xml::sax { class XAttributeList; }
29
30using namespace ::cppu;
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::xml::sax;
33
35{
36public:
37 OFileWriter(const char *pcFile, const char *locale );
39 void writeStringCharacters(std::u16string_view str) const;
40 void writeOUStringLiteralCharacters(std::u16string_view str) const;
41 void writeAsciiString(const char *str)const ;
42 void writeInt(sal_Int16 nb) const;
43 void writeHexInt(sal_Int16 nb) const;
44 void writeOUStringRefFunction(const char *func, std::u16string_view useLocale) const;
45 void writeOUStringRefFunction(const char *func, std::u16string_view useLocale, const char *to) const;
46 void writeOUStringFunction(const char *func, const char *count, const char *array) const;
47 void writeOUStringFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const;
48 void writeOUStringFunction2(const char *func, const char *style, const char* attr, const char *array) const;
49 void writeOUStringRefFunction2(const char *func, std::u16string_view useLocale) const;
50 void writeOUStringFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const;
51 void writeOUStringRefFunction3(const char *func, std::u16string_view useLocale) const;
52 void writeOUStringLiteralIntParameter(const char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const;
53 bool writeOUStringLiteralDefaultParameter(const char* pAsciiStr, std::u16string_view str, sal_Int16 count) const;
54 void writeOUStringLiteralParameter(const char* pAsciiStr, std::u16string_view aChars) const;
55 void writeParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count) const;
56 void writeOUStringLiteralParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count) const;
57 void writeOUStringLiteralParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const;
58 void writeOUStringLiteralParameter(const char* pTagStr, const char* pAsciiStr, std::u16string_view aChars, const sal_Int16 count) const;
59 void writeOUStringLiteralParameter(const char* pTagStr, const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const;
60 void closeOutput() const;
62 const char * getLocale() const { return theLocale.c_str(); }
63private:
64 std::string theLocale;
66};
67
68class Attr {
69 Sequence <OUString> name;
70 Sequence <OUString> value;
71
72public:
73 explicit Attr (const Reference< XAttributeList > & attr);
74 OUString getValueByName (const char *str) const;
75 const OUString& getValueByIndex (sal_Int32 idx) const ;
76};
77
79{
80 OUString aName;
81 OUString aValue;
84 std::vector<std::unique_ptr<LocaleNode>> children;
85
86protected:
87 mutable int nError;
88
89public:
90 LocaleNode (OUString name, const Reference< XAttributeList > & attr);
91 void setValue(std::u16string_view oValue) { aValue += oValue; };
92 const OUString& getName() const { return aName; };
93 const OUString& getValue() const { return aValue; };
94 const Attr& getAttr() const { return aAttribs; };
95 sal_Int32 getNumberOfChildren () const { return sal_Int32(children.size()); };
96 LocaleNode * getChildAt (sal_Int32 idx) const { return children[idx].get(); };
97 const LocaleNode * findNode ( const char *name) const;
98 virtual ~LocaleNode();
99 void addChild ( LocaleNode * node);
100 const LocaleNode* getRoot() const;
101 int getError() const;
102 virtual void generateCode (const OFileWriter &of) const;
103 // MUST >= nMinLen
104 // nMinLen <= 0 : no error
105 // nMinLen > 0 : error if less than nMinLen characters
106 // SHOULD NOT > nMaxLen
107 // nMaxLen < 0 : any length
108 // nMaxLen >= 0 : warning if more than nMaxLen characters
109 OUString writeOUStringLiteralParameterCheckLen( const OFileWriter &of, const char* pParameterName, const LocaleNode* pNode, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const;
110 OUString writeOUStringLiteralParameterCheckLen( const OFileWriter &of, const char* pNodeName, const char* pParameterName, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const;
111 // ++nError with output to stderr
112 void incError( const char* pStr ) const;
113 // ++nError with output to stderr
114 void incError( std::u16string_view rStr ) const;
115 // ++nError with output to stderr, pStr should contain "%d"
116 void incErrorInt( const char* pStr, int nVal ) const;
117 // ++nError with output to stderr, pStr should contain "%s"
118 void incErrorStr( const char* pStr, std::u16string_view rVal ) const;
119 // ++nError with output to stderr, pStr should contain "%s %s"
120 void incErrorStrStr( const char* pStr, std::u16string_view rVal1, std::u16string_view rVal2 )
121 const;
122 static LocaleNode* createNode (const OUString& name,const Reference< XAttributeList > & attr);
123};
124
125class LCInfoNode : public LocaleNode {
126public:
127 LCInfoNode (const OUString& name,
128 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
129 virtual void generateCode (const OFileWriter &of) const override;
130};
131
132
133class LCCTYPENode : public LocaleNode {
134public:
135 LCCTYPENode (const OUString& name,
136 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
137
138 virtual void generateCode (const OFileWriter &of) const override;
139};
140
141class LCFormatNode : public LocaleNode {
142 static sal_Int16 mnSection;
143 static sal_Int16 mnFormats;
144public:
145 LCFormatNode (const OUString& name,
146 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
147
148 virtual void generateCode (const OFileWriter &of) const override;
149};
150
152public:
153 LCCollationNode (const OUString& name,
154 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
155
156 virtual void generateCode (const OFileWriter &of) const override;
157};
158
159class LCIndexNode : public LocaleNode {
160public:
161 LCIndexNode (const OUString& name,
162 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
163
164 virtual void generateCode (const OFileWriter &of) const override;
165};
166
167class LCSearchNode : public LocaleNode {
168public:
169 LCSearchNode (const OUString& name,
170 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
171
172 virtual void generateCode (const OFileWriter &of) const override;
173};
174
176public:
177 LCCalendarNode (const OUString& name,
178 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
179
180 virtual void generateCode (const OFileWriter &of) const override;
181
182 bool expectedCalendarElement( std::u16string_view rName,
183 const LocaleNode* pNode, sal_Int16 nChild, std::u16string_view rCalendarID ) const;
184};
185
187public:
188 LCCurrencyNode (const OUString& name,
189 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
190
191 virtual void generateCode (const OFileWriter &of) const override;
192};
193
195public:
196 LCTransliterationNode (const OUString& name,
197 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
198
199 virtual void generateCode (const OFileWriter &of) const override;
200};
201
202class LCMiscNode : public LocaleNode {
203public:
204 LCMiscNode (const OUString& name,
205 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
206
207 virtual void generateCode (const OFileWriter &of) const override;
208};
209
211public:
212 LCNumberingLevelNode (const OUString& name,
213 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
214
215 virtual void generateCode (const OFileWriter &of) const override;
216};
217
219public:
220 LCOutlineNumberingLevelNode (const OUString& name,
221 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
222
223 virtual void generateCode (const OFileWriter &of) const override;
224};
225
226/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
UBlockCode from
UBlockCode to
Sequence< OUString > name
Definition: LocaleNode.hxx:69
const OUString & getValueByIndex(sal_Int32 idx) const
OUString getValueByName(const char *str) const
Sequence< OUString > value
Definition: LocaleNode.hxx:70
Attr(const Reference< XAttributeList > &attr)
LCCTYPENode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:135
virtual void generateCode(const OFileWriter &of) const override
Definition: LocaleNode.cxx:284
bool expectedCalendarElement(std::u16string_view rName, const LocaleNode *pNode, sal_Int16 nChild, std::u16string_view rCalendarID) const
virtual void generateCode(const OFileWriter &of) const override
LCCalendarNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:177
LCCollationNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:153
virtual void generateCode(const OFileWriter &of) const override
LCCurrencyNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:188
virtual void generateCode(const OFileWriter &of) const override
virtual void generateCode(const OFileWriter &of) const override
Definition: LocaleNode.cxx:517
LCFormatNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:145
static sal_Int16 mnFormats
Definition: LocaleNode.hxx:143
static sal_Int16 mnSection
Definition: LocaleNode.hxx:142
virtual void generateCode(const OFileWriter &of) const override
LCIndexNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:161
virtual void generateCode(const OFileWriter &of) const override
Definition: LocaleNode.cxx:229
LCInfoNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:127
virtual void generateCode(const OFileWriter &of) const override
LCMiscNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:204
LCNumberingLevelNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:212
virtual void generateCode(const OFileWriter &of) const override
virtual void generateCode(const OFileWriter &of) const override
LCOutlineNumberingLevelNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:220
virtual void generateCode(const OFileWriter &of) const override
LCSearchNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:169
virtual void generateCode(const OFileWriter &of) const override
LCTransliterationNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.hxx:196
void incErrorStrStr(const char *pStr, std::u16string_view rVal1, std::u16string_view rVal2) const
Definition: LocaleNode.cxx:223
void addChild(LocaleNode *node)
Definition: LocaleNode.cxx:62
const OUString & getName() const
Definition: LocaleNode.hxx:92
void incErrorInt(const char *pStr, int nVal) const
Definition: LocaleNode.cxx:211
const OUString & getValue() const
Definition: LocaleNode.hxx:93
sal_Int32 getNumberOfChildren() const
Definition: LocaleNode.hxx:95
const LocaleNode * getRoot() const
Definition: LocaleNode.cxx:67
static LocaleNode * createNode(const OUString &name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.cxx:92
int getError() const
Definition: LocaleNode.cxx:54
OUString writeOUStringLiteralParameterCheckLen(const OFileWriter &of, const char *pParameterName, const LocaleNode *pNode, sal_Int32 nMinLen, sal_Int32 nMaxLen) const
Definition: LocaleNode.cxx:144
const Attr & getAttr() const
Definition: LocaleNode.hxx:94
virtual ~LocaleNode()
Definition: LocaleNode.cxx:88
const LocaleNode * findNode(const char *name) const
Definition: LocaleNode.cxx:76
void setValue(std::u16string_view oValue)
Definition: LocaleNode.hxx:91
OUString aName
Definition: LocaleNode.hxx:80
Attr aAttribs
Definition: LocaleNode.hxx:82
LocaleNode * getChildAt(sal_Int32 idx) const
Definition: LocaleNode.hxx:96
LocaleNode * parent
Definition: LocaleNode.hxx:83
void incError(const char *pStr) const
Definition: LocaleNode.cxx:200
LocaleNode(OUString name, const Reference< XAttributeList > &attr)
Definition: LocaleNode.cxx:46
virtual void generateCode(const OFileWriter &of) const
Definition: LocaleNode.cxx:130
std::vector< std::unique_ptr< LocaleNode > > children
Definition: LocaleNode.hxx:84
OUString aValue
Definition: LocaleNode.hxx:81
void incErrorStr(const char *pStr, std::u16string_view rVal) const
Definition: LocaleNode.cxx:217
void writeOUStringRefFunction(const char *func, std::u16string_view useLocale) const
Definition: filewriter.cxx:64
std::string theLocale
Definition: LocaleNode.hxx:64
void writeOUStringFunction3(const char *func, const char *style, const char *levels, const char *attr, const char *array) const
Definition: filewriter.cxx:117
void writeOUStringFunction2(const char *func, const char *style, const char *attr, const char *array) const
Definition: filewriter.cxx:100
void writeOUStringLiteralIntParameter(const char *pAsciiStr, const sal_Int16 count, sal_Int16 val) const
Definition: filewriter.cxx:135
bool writeOUStringLiteralDefaultParameter(const char *pAsciiStr, std::u16string_view str, sal_Int16 count) const
Definition: filewriter.cxx:140
FILE * m_f
Definition: LocaleNode.hxx:65
void writeOUStringLiteralParameter(const char *pAsciiStr, std::u16string_view aChars) const
Definition: filewriter.cxx:147
void writeOUStringRefFunction3(const char *func, std::u16string_view useLocale) const
Definition: filewriter.cxx:126
void writeOUStringLiteralCharacters(std::u16string_view str) const
Definition: filewriter.cxx:58
void writeOUStringFunction(const char *func, const char *count, const char *array) const
Definition: filewriter.cxx:84
const char * getLocale() const
Return the locale string, something like en_US or de_DE.
Definition: LocaleNode.hxx:62
void writeStringCharacters(std::u16string_view str) const
Definition: filewriter.cxx:52
void writeAsciiString(const char *str) const
Definition: filewriter.cxx:47
void writeInt(sal_Int16 nb) const
Definition: filewriter.cxx:37
void writeParameter(const char *pAsciiStr, std::u16string_view aChars, sal_Int16 count) const
Definition: filewriter.cxx:154
OFileWriter(const char *pcFile, const char *locale)
Definition: filewriter.cxx:26
void writeHexInt(sal_Int16 nb) const
Definition: filewriter.cxx:42
void closeOutput() const
Definition: filewriter.cxx:189
void writeOUStringRefFunction2(const char *func, std::u16string_view useLocale) const
Definition: filewriter.cxx:108
const char * name
const sal_uInt16 idx[]