LibreOffice Module i18npool (master) 1
filewriter.cxx
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
20#include <stdio.h>
21#include "LocaleNode.hxx"
22
23// The document handler, which is needed for the saxparser
24// The Documenthandler for reading sax
25
26OFileWriter::OFileWriter(const char *pcFile, const char *locale ): theLocale(locale) {
27
28 printf("file generated=%s\n", pcFile);
29 m_f = fopen(pcFile, "w");
30}
31
33 if(m_f)
34 fclose( m_f );
35}
36
37void OFileWriter::writeInt(sal_Int16 nb) const
38{
39 fprintf(m_f, "%d", nb);
40}
41
42void OFileWriter::writeHexInt(sal_Int16 nb) const
43{
44 fprintf(m_f, "%x", nb);
45}
46
47void OFileWriter::writeAsciiString(const char* str) const
48{
49 fprintf(m_f, "%s", str);
50}
51
52void OFileWriter::writeStringCharacters(std::u16string_view str) const
53{
54 for(size_t i = 0; i < str.size(); i++)
55 fprintf(m_f, "0x%x, ", str[i]);
56}
57
58void OFileWriter::writeOUStringLiteralCharacters(std::u16string_view str) const
59{
60 for(size_t i = 0; i < str.size(); i++)
61 fprintf(m_f, "\\x%04x", str[i]);
62}
63
64void OFileWriter::writeOUStringRefFunction(const char *func, std::u16string_view useLocale) const
65{
66 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
67 const char* locale = aRefLocale.getStr();
68 fprintf(m_f, "extern const OUString * SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
69 fprintf(m_f, "const OUString * SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale.c_str());
70 fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
71}
72
73void OFileWriter::writeOUStringRefFunction(const char *func, std::u16string_view useLocale, const char *to) const
74{
75 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
76 const char* locale = aRefLocale.getStr();
77 fprintf(m_f, "extern OUString const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to);\n", func, locale);
78 fprintf(m_f, "OUString const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale.c_str());
79 fprintf(m_f, "\tto = %s;\n", to);
80 fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
81 fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
82}
83
84void OFileWriter::writeOUStringFunction(const char *func, const char *count, const char *array) const
85{
86 fprintf(m_f, "OUString const * SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale.c_str());
87 fprintf(m_f, "\tcount = %s;\n", count);
88 fprintf(m_f, "\treturn (OUString const *)%s;\n}\n", array);
89}
90
91void OFileWriter::writeOUStringFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
92{
93 fprintf(m_f, "OUString const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale.c_str());
94 fprintf(m_f, "\tcount = %s;\n", count);
95 fprintf(m_f, "\tfrom = %s;\n", from);
96 fprintf(m_f, "\tto = %s;\n", to);
97 fprintf(m_f, "\treturn (const OUString *)%s;\n}\n", array);
98}
99
100void OFileWriter::writeOUStringFunction2(const char *func, const char *style, const char* attr, const char *array) const
101{
102 fprintf(m_f, "const OUString ** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale.c_str());
103 fprintf(m_f, "\tnStyles = %s;\n", style);
104 fprintf(m_f, "\tnAttributes = %s;\n", attr);
105 fprintf(m_f, "\treturn (const OUString **)%s;\n}\n", array);
106}
107
108void OFileWriter::writeOUStringRefFunction2(const char *func, std::u16string_view useLocale) const
109{
110 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
111 const char* locale = aRefLocale.getStr();
112 fprintf(m_f, "extern const OUString ** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
113 fprintf(m_f, "const OUString ** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale.c_str());
114 fprintf(m_f, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
115}
116
117void OFileWriter::writeOUStringFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
118{
119 fprintf(m_f, "const OUString *** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale.c_str());
120 fprintf(m_f, "\tnStyles = %s;\n", style);
121 fprintf(m_f, "\tnLevels = %s;\n", levels);
122 fprintf(m_f, "\tnAttributes = %s;\n", attr);
123 fprintf(m_f, "\treturn (const OUString ***) %s;\n}\n", array);
124}
125
126void OFileWriter::writeOUStringRefFunction3(const char *func, std::u16string_view useLocale) const
127{
128 OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
129 const char* locale = aRefLocale.getStr();
130 fprintf(m_f, "extern const OUString *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
131 fprintf(m_f, "const OUString *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale.c_str());
132 fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
133}
134
135void OFileWriter::writeOUStringLiteralIntParameter(const char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
136{
137 fprintf(m_f, "static constexpr OUStringLiteral %s%d = u\"\\x%x\";\n", pAsciiStr, count, val);
138}
139
140bool OFileWriter::writeOUStringLiteralDefaultParameter(const char* pAsciiStr, std::u16string_view str, sal_Int16 count) const
141{
142 bool bBool = str == u"true";
143 fprintf(m_f,"static constexpr OUStringLiteral default%s%d = u\"\\x%x\";\n", pAsciiStr, count, bBool);
144 return bBool;
145}
146
147void OFileWriter::writeOUStringLiteralParameter(const char* pAsciiStr, std::u16string_view aChars) const
148{
149 fprintf(m_f, "static constexpr OUStringLiteral %s = u\"", pAsciiStr);
151 fprintf(m_f, "\";\n");
152}
153
154void OFileWriter::writeParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count) const
155{
156 fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
157 writeStringCharacters(aChars);
158 fprintf(m_f, "0x0};\n");
159}
160
161void OFileWriter::writeOUStringLiteralParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count) const
162{
163 fprintf(m_f, "static constexpr OUStringLiteral %s%d = u\"", pAsciiStr, count);
165 fprintf(m_f, "\";\n");
166}
167
168void OFileWriter::writeOUStringLiteralParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const
169{
170 fprintf(m_f, "static constexpr OUStringLiteral %s%d%d = u\"", pAsciiStr, count0, count1);
172 fprintf(m_f, "\";\n");
173}
174
175void OFileWriter::writeOUStringLiteralParameter(const char* pTagStr, const char* pAsciiStr, std::u16string_view aChars, const sal_Int16 count) const
176{
177 fprintf(m_f, "static constexpr OUStringLiteral %s%s%d = u\"", pTagStr, pAsciiStr, count);
179 fprintf(m_f, "\";\n");
180}
181
182void OFileWriter::writeOUStringLiteralParameter(const char* pTagStr, const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const
183{
184 fprintf(m_f, "static constexpr OUStringLiteral %s%s%d%d = u\"", pTagStr, pAsciiStr, count0, count1);
186 fprintf(m_f, "\";\n");
187}
188
190{
191 if(m_f)
192 {
193 fclose( m_f );
194 const_cast< OFileWriter * > ( this )->m_f = nullptr;
195 }
196}
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
UBlockCode from
UBlockCode to
void writeOUStringRefFunction(const char *func, std::u16string_view useLocale) const
Definition: filewriter.cxx:64
std::string theLocale
Definition: LocaleNode.hxx:64
void writeOUStringFunction3(const char *func, const char *style, const char *levels, const char *attr, const char *array) const
Definition: filewriter.cxx:117
void writeOUStringFunction2(const char *func, const char *style, const char *attr, const char *array) const
Definition: filewriter.cxx:100
void writeOUStringLiteralIntParameter(const char *pAsciiStr, const sal_Int16 count, sal_Int16 val) const
Definition: filewriter.cxx:135
bool writeOUStringLiteralDefaultParameter(const char *pAsciiStr, std::u16string_view str, sal_Int16 count) const
Definition: filewriter.cxx:140
FILE * m_f
Definition: LocaleNode.hxx:65
void writeOUStringLiteralParameter(const char *pAsciiStr, std::u16string_view aChars) const
Definition: filewriter.cxx:147
void writeOUStringRefFunction3(const char *func, std::u16string_view useLocale) const
Definition: filewriter.cxx:126
void writeOUStringLiteralCharacters(std::u16string_view str) const
Definition: filewriter.cxx:58
void writeOUStringFunction(const char *func, const char *count, const char *array) const
Definition: filewriter.cxx:84
void writeStringCharacters(std::u16string_view str) const
Definition: filewriter.cxx:52
void writeAsciiString(const char *str) const
Definition: filewriter.cxx:47
void writeInt(sal_Int16 nb) const
Definition: filewriter.cxx:37
void writeParameter(const char *pAsciiStr, std::u16string_view aChars, sal_Int16 count) const
Definition: filewriter.cxx:154
OFileWriter(const char *pcFile, const char *locale)
Definition: filewriter.cxx:26
void writeHexInt(sal_Int16 nb) const
Definition: filewriter.cxx:42
void closeOutput() const
Definition: filewriter.cxx:189
void writeOUStringRefFunction2(const char *func, std::u16string_view useLocale) const
Definition: filewriter.cxx:108
float u
int i
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)