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