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