From 628078fea5be293038ee2cca494ef77227077c35 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 22 Jan 2019 16:55:44 +0100 Subject: 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: Stephan Bergmann --- i18npool/source/localedata/LocaleNode.hxx | 5 +++-- i18npool/source/localedata/filewriter.cxx | 21 +++++++++------------ i18npool/source/localedata/saxparser.cxx | 15 +++++++-------- 3 files changed, 19 insertions(+), 22 deletions(-) (limited to 'i18npool') diff --git a/i18npool/source/localedata/LocaleNode.hxx b/i18npool/source/localedata/LocaleNode.hxx index 7b19cbc82a73..e1b283c72108 100644 --- a/i18npool/source/localedata/LocaleNode.hxx +++ b/i18npool/source/localedata/LocaleNode.hxx @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -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; }; diff --git a/i18npool/source/localedata/filewriter.cxx b/i18npool/source/localedata/filewriter.cxx index 2026e55b5f72..02540996e3ea 100644 --- a/i18npool/source/localedata/filewriter.cxx +++ b/i18npool/source/localedata/filewriter.cxx @@ -18,18 +18,15 @@ */ #include -#include #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); } diff --git a/i18npool/source/localedata/saxparser.cxx b/i18npool/source/localedata/saxparser.cxx index 183611fff00e..e55e0361f319 100644 --- a/i18npool/source/localedata/saxparser.cxx +++ b/i18npool/source/localedata/saxparser.cxx @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include @@ -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 \n\n\n"); of.writeAsciiString("#include \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; }; -- cgit