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 <vector>
24 #include <memory>
25 
26 #include <com/sun/star/uno/Sequence.hxx>
27 
28 namespace com::sun::star::xml::sax { class XAttributeList; }
29 
30 using namespace ::std;
31 using namespace ::cppu;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::xml::sax;
34 
35 class OFileWriter
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, const OUString& 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, const OUString& 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, const OUString& 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, const OUString& useLocale) const;
51     void  writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const;
52     bool  writeDefaultParameter(const sal_Char* pAsciiStr, const OUString& str, sal_Int16 count) const;
53     void  writeParameter(const sal_Char* pAsciiStr, const OUString& aChars) const;
54     void  writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count) const;
55     void  writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const;
56     void  writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, const sal_Int16 count) const;
57     void  writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const;
58     void  closeOutput() const;
59     /// Return the locale string, something like en_US or de_DE
getLocale() const60     const char * getLocale() const { return theLocale.c_str(); }
61 private:
62     std::string theLocale;
63     FILE *m_f;
64 };
65 
66 class Attr {
67     Sequence <OUString> name;
68     Sequence <OUString> value;
69 
70 public:
71     explicit Attr (const Reference< XAttributeList > & attr);
72     OUString getValueByName (const sal_Char *str) const;
73     const OUString& getValueByIndex (sal_Int32 idx) const ;
74 };
75 
76 class LocaleNode
77 {
78     OUString aName;
79     OUString aValue;
80     Attr aAttribs;
81     LocaleNode * parent;
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);
setValue(const OUString & oValue)89     void setValue(const OUString &oValue) { aValue += oValue; };
getName() const90     const OUString& getName() const { return aName; };
getValue() const91     const OUString& getValue() const { return aValue; };
getAttr() const92     const Attr& getAttr() const { return aAttribs; };
getNumberOfChildren() const93     sal_Int32 getNumberOfChildren () const { return sal_Int32(children.size()); };
getChildAt(sal_Int32 idx) const94     LocaleNode * getChildAt (sal_Int32 idx) const { return children[idx].get(); };
95     const LocaleNode * findNode ( const sal_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( const OUString& 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, const OUString& rVal ) const;
117     // ++nError with output to stderr, pStr should contain "%s %s"
118     void incErrorStrStr( const char* pStr, const OUString& rVal1, const OUString& rVal2 ) const;
119     static LocaleNode* createNode (const OUString& name,const Reference< XAttributeList > & attr);
120 };
121 
122 class LCInfoNode : public LocaleNode {
123 public:
LCInfoNode(const OUString & name,const Reference<XAttributeList> & attr)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 
130 class LCCTYPENode : public LocaleNode {
131 public:
LCCTYPENode(const OUString & name,const Reference<XAttributeList> & attr)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 
138 class LCFormatNode : public LocaleNode {
139     static sal_Int16 mnSection;
140     static sal_Int16 mnFormats;
141 public:
LCFormatNode(const OUString & name,const Reference<XAttributeList> & attr)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 
148 class LCCollationNode : public LocaleNode {
149 public:
LCCollationNode(const OUString & name,const Reference<XAttributeList> & attr)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 
156 class LCIndexNode : public LocaleNode {
157 public:
LCIndexNode(const OUString & name,const Reference<XAttributeList> & attr)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 
164 class LCSearchNode : public LocaleNode {
165 public:
LCSearchNode(const OUString & name,const Reference<XAttributeList> & attr)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 
172 class LCCalendarNode : public LocaleNode {
173 public:
LCCalendarNode(const OUString & name,const Reference<XAttributeList> & attr)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 
180 class LCCurrencyNode : public LocaleNode {
181 public:
LCCurrencyNode(const OUString & name,const Reference<XAttributeList> & attr)182     LCCurrencyNode (const OUString& name,
183                 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
184 
185     virtual void generateCode (const OFileWriter &of) const override;
186 };
187 
188 class LCTransliterationNode : public LocaleNode {
189 public:
LCTransliterationNode(const OUString & name,const Reference<XAttributeList> & attr)190     LCTransliterationNode (const OUString& name,
191                 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
192 
193     virtual void generateCode (const OFileWriter &of) const override;
194 };
195 
196 class LCMiscNode : public LocaleNode {
197 public:
LCMiscNode(const OUString & name,const Reference<XAttributeList> & attr)198     LCMiscNode (const OUString& name,
199                 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
200 
201     virtual void generateCode (const OFileWriter &of) const override;
202 };
203 
204 class LCNumberingLevelNode : public LocaleNode {
205 public:
LCNumberingLevelNode(const OUString & name,const Reference<XAttributeList> & attr)206     LCNumberingLevelNode (const OUString& name,
207                 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
208 
209     virtual void generateCode (const OFileWriter &of) const override;
210 };
211 
212 class LCOutlineNumberingLevelNode : public LocaleNode {
213 public:
LCOutlineNumberingLevelNode(const OUString & name,const Reference<XAttributeList> & attr)214     LCOutlineNumberingLevelNode (const OUString& name,
215                 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
216 
217     virtual void generateCode (const OFileWriter &of) const override;
218 };
219 
220 #endif
221 
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
223