1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <string_view>
26 #include <com/sun/star/uno/Sequence.hxx>
28 namespace com::sun::star::xml::sax
{ class XAttributeList
; }
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::xml::sax
;
36 OFileWriter(const char *pcFile
, const char *locale
);
38 void writeStringCharacters(std::u16string_view str
) const;
39 void writeOUStringLiteralCharacters(std::u16string_view str
) const;
40 void writeAsciiString(const char *str
)const ;
41 void writeInt(sal_Int16 nb
) const;
42 void writeHexInt(sal_Int16 nb
) const;
43 void writeOUStringRefFunction(const char *func
, std::u16string_view useLocale
) const;
44 void writeOUStringRefFunction(const char *func
, std::u16string_view useLocale
, const char *to
) const;
45 void writeOUStringFunction(const char *func
, const char *count
, const char *array
) const;
46 void writeOUStringFunction(const char *func
, const char *count
, const char *array
, const char *from
, const char *to
) const;
47 void writeOUStringFunction2(const char *func
, const char *style
, const char* attr
, const char *array
) const;
48 void writeOUStringRefFunction2(const char *func
, std::u16string_view useLocale
) const;
49 void writeOUStringFunction3(const char *func
, const char *style
, const char* levels
, const char* attr
, const char *array
) const;
50 void writeOUStringRefFunction3(const char *func
, std::u16string_view useLocale
) const;
51 void writeOUStringLiteralIntParameter(const char* pAsciiStr
, const sal_Int16 count
, sal_Int16 val
) const;
52 bool writeOUStringLiteralDefaultParameter(const char* pAsciiStr
, std::u16string_view str
, sal_Int16 count
) const;
53 void writeOUStringLiteralParameter(const char* pAsciiStr
, std::u16string_view aChars
) const;
54 void writeParameter(const char* pAsciiStr
, std::u16string_view aChars
, sal_Int16 count
) const;
55 void writeOUStringLiteralParameter(const char* pAsciiStr
, std::u16string_view aChars
, sal_Int16 count
) const;
56 void writeOUStringLiteralParameter(const char* pAsciiStr
, std::u16string_view aChars
, sal_Int16 count0
, sal_Int16 count1
) const;
57 void writeOUStringLiteralParameter(const char* pTagStr
, const char* pAsciiStr
, std::u16string_view aChars
, const sal_Int16 count
) const;
58 void writeOUStringLiteralParameter(const char* pTagStr
, const char* pAsciiStr
, std::u16string_view aChars
, sal_Int16 count0
, sal_Int16 count1
) const;
59 void closeOutput() const;
60 /// Return the locale string, something like en_US or de_DE
61 const char * getLocale() const { return theLocale
.c_str(); }
63 std::string theLocale
;
68 Sequence
<OUString
> name
;
69 Sequence
<OUString
> value
;
72 explicit Attr (const Reference
< XAttributeList
> & attr
);
73 OUString
getValueByName (const char *str
) const;
74 const OUString
& getValueByIndex (sal_Int32 idx
) const ;
83 std::vector
<std::unique_ptr
<LocaleNode
>> children
;
89 LocaleNode (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;
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
writeOUStringLiteralParameterCheckLen( const OFileWriter
&of
, const char* pParameterName
, const LocaleNode
* pNode
, sal_Int32 nMinLen
, sal_Int32 nMaxLen
) const;
109 OUString
writeOUStringLiteralParameterCheckLen( 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
)
121 static LocaleNode
* createNode (const OUString
& name
,const Reference
< XAttributeList
> & attr
);
124 class LCInfoNode
: public LocaleNode
{
126 LCInfoNode (const OUString
& name
,
127 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
128 virtual void generateCode (const OFileWriter
&of
) const override
;
132 class LCCTYPENode
: public LocaleNode
{
134 LCCTYPENode (const OUString
& name
,
135 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
137 virtual void generateCode (const OFileWriter
&of
) const override
;
140 class LCFormatNode
: public LocaleNode
{
141 static sal_Int16 mnSection
;
142 static sal_Int16 mnFormats
;
144 LCFormatNode (const OUString
& name
,
145 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
147 virtual void generateCode (const OFileWriter
&of
) const override
;
150 class LCCollationNode
: public LocaleNode
{
152 LCCollationNode (const OUString
& name
,
153 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
155 virtual void generateCode (const OFileWriter
&of
) const override
;
158 class LCIndexNode
: public LocaleNode
{
160 LCIndexNode (const OUString
& name
,
161 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
163 virtual void generateCode (const OFileWriter
&of
) const override
;
166 class LCSearchNode
: public LocaleNode
{
168 LCSearchNode (const OUString
& name
,
169 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
171 virtual void generateCode (const OFileWriter
&of
) const override
;
174 class LCCalendarNode
: public LocaleNode
{
176 LCCalendarNode (const OUString
& name
,
177 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
179 virtual void generateCode (const OFileWriter
&of
) const override
;
181 bool expectedCalendarElement( std::u16string_view rName
,
182 const LocaleNode
* pNode
, sal_Int16 nChild
, std::u16string_view rCalendarID
) const;
185 class LCCurrencyNode
: public LocaleNode
{
187 LCCurrencyNode (const OUString
& name
,
188 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
190 virtual void generateCode (const OFileWriter
&of
) const override
;
193 class LCTransliterationNode
: public LocaleNode
{
195 LCTransliterationNode (const OUString
& name
,
196 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
198 virtual void generateCode (const OFileWriter
&of
) const override
;
201 class LCMiscNode
: public LocaleNode
{
203 LCMiscNode (const OUString
& name
,
204 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
206 virtual void generateCode (const OFileWriter
&of
) const override
;
209 class LCNumberingLevelNode
: public LocaleNode
{
211 LCNumberingLevelNode (const OUString
& name
,
212 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
214 virtual void generateCode (const OFileWriter
&of
) const override
;
217 class LCOutlineNumberingLevelNode
: public LocaleNode
{
219 LCOutlineNumberingLevelNode (const OUString
& name
,
220 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
222 virtual void generateCode (const OFileWriter
&of
) const override
;
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */