Kaydet (Commit) 628078fe authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Use std::string instead of fixed-size array to hold string

Change-Id: I8477271f4de4d24cf1019c381ab3b56db2016be9
Reviewed-on: https://gerrit.libreoffice.org/66749
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 25970c57
......@@ -22,6 +22,7 @@
#include <com/sun/star/xml/sax/XParser.hpp>
#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
#include <string>
#include <vector>
#include <memory>
......@@ -62,9 +63,9 @@ public:
void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const;
void closeOutput() const;
/// Return the locale string, something like en_US or de_DE
const char * getLocale() const { return theLocale; }
const char * getLocale() const { return theLocale.c_str(); }
private:
char theLocale[50];
std::string theLocale;
FILE *m_f;
};
......
......@@ -18,18 +18,15 @@
*/
#include <stdio.h>
#include <string.h>
#include "LocaleNode.hxx"
// The document handler, which is needed for the saxparser
// The Documenthandler for reading sax
OFileWriter::OFileWriter(const char *pcFile, const char *locale ) {
OFileWriter::OFileWriter(const char *pcFile, const char *locale ): theLocale(locale) {
printf("file generated=%s\n", pcFile);
m_f = fopen(pcFile, "w");
strncpy( theLocale, locale, sizeof(theLocale) );
theLocale[sizeof(theLocale)-1] = 0;
}
OFileWriter::~OFileWriter() {
......@@ -55,7 +52,7 @@ void OFileWriter::writeStringCharacters(const OUString& str) const
void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
{
fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale.c_str());
fprintf(m_f, "\tcount = %s;\n", count);
fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
}
......@@ -65,13 +62,13 @@ void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale)
OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
const char* locale = aRefLocale.getStr();
fprintf(m_f, "extern sal_Unicode ** SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale.c_str());
fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
}
void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
{
fprintf(m_f, "sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
fprintf(m_f, "sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale.c_str());
fprintf(m_f, "\tcount = %s;\n", count);
fprintf(m_f, "\tfrom = %s;\n", from);
fprintf(m_f, "\tto = %s;\n", to);
......@@ -83,7 +80,7 @@ void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale,
OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
const char* locale = aRefLocale.getStr();
fprintf(m_f, "extern sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to);\n", func, locale);
fprintf(m_f, "sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
fprintf(m_f, "sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale.c_str());
fprintf(m_f, "\tto = %s;\n", to);
fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
......@@ -91,7 +88,7 @@ void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale,
void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
{
fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale);
fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale.c_str());
fprintf(m_f, "\tnStyles = %s;\n", style);
fprintf(m_f, "\tnAttributes = %s;\n", attr);
fprintf(m_f, "\treturn %s;\n}\n", array);
......@@ -102,13 +99,13 @@ void OFileWriter::writeRefFunction2(const char *func, const OUString& useLocale)
OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
const char* locale = aRefLocale.getStr();
fprintf(m_f, "extern const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale);
fprintf(m_f, "const sal_Unicode *** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale.c_str());
fprintf(m_f, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
}
void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
{
fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale);
fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale.c_str());
fprintf(m_f, "\tnStyles = %s;\n", style);
fprintf(m_f, "\tnLevels = %s;\n", levels);
fprintf(m_f, "\tnAttributes = %s;\n", attr);
......@@ -120,7 +117,7 @@ void OFileWriter::writeRefFunction3(const char *func, const OUString& useLocale)
OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
const char* locale = aRefLocale.getStr();
fprintf(m_f, "extern const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale);
fprintf(m_f, "const sal_Unicode **** SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale.c_str());
fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
}
......
......@@ -22,7 +22,7 @@
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <stack>
#include <sal/main.h>
......@@ -148,10 +148,9 @@ public:
TestDocumentHandler(const char* locale, const char* outFile )
: rootNode(nullptr)
, nError(0)
, theLocale(locale)
, of(outFile, locale)
{
strncpy( theLocale, locale, sizeof(theLocale) );
theLocale[sizeof(theLocale)-1] = 0;
}
virtual ~TestDocumentHandler( ) override
......@@ -190,7 +189,7 @@ public: // ExtendedDocumentHandler
virtual void SAL_CALL startDocument() override
{
printf( "parsing document %s started\n", theLocale);
printf( "parsing document %s started\n", theLocale.c_str());
of.writeAsciiString("#include <sal/types.h>\n\n\n");
of.writeAsciiString("#include <stdio.h>\n\n");
of.writeAsciiString("extern \"C\" {\n\n");
......@@ -204,16 +203,16 @@ public: // ExtendedDocumentHandler
int err = rootNode->getError();
if (err)
{
printf( "Error: in data for %s: %d\n", theLocale, err);
printf( "Error: in data for %s: %d\n", theLocale.c_str(), err);
nError += err;
}
}
else
{
++nError;
printf( "Error: no data for %s\n", theLocale);
printf( "Error: no data for %s\n", theLocale.c_str());
}
printf( "parsing document %s finished\n", theLocale);
printf( "parsing document %s finished\n", theLocale.c_str());
of.writeAsciiString("} // extern \"C\"\n\n");
of.closeOutput();
......@@ -294,7 +293,7 @@ public: // ExtendedDocumentHandler
public:
int nError;
sal_Char theLocale[50];
std::string theLocale;
OFileWriter of;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment