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