summaryrefslogtreecommitdiff
path: root/l10ntools
diff options
context:
space:
mode:
Diffstat (limited to 'l10ntools')
-rw-r--r--l10ntools/StaticLibrary_transex.mk3
-rw-r--r--l10ntools/inc/common.hxx53
-rw-r--r--l10ntools/inc/export.hxx122
-rw-r--r--l10ntools/inc/helper.hxx39
-rw-r--r--l10ntools/inc/helpmerge.hxx1
-rw-r--r--l10ntools/inc/lngmerge.hxx2
-rw-r--r--l10ntools/inc/xrmmerge.hxx1
-rw-r--r--l10ntools/source/cfgmerge.cxx100
-rw-r--r--l10ntools/source/common.cxx153
-rw-r--r--l10ntools/source/common.hxx76
-rw-r--r--l10ntools/source/export.cxx114
-rw-r--r--l10ntools/source/export2.cxx364
-rw-r--r--l10ntools/source/helper.cxx88
-rw-r--r--l10ntools/source/helper.hxx181
-rw-r--r--l10ntools/source/helpex.cxx5
-rw-r--r--l10ntools/source/helpmerge.cxx3
-rw-r--r--l10ntools/source/lngex.cxx6
-rw-r--r--l10ntools/source/lngmerge.cxx15
-rw-r--r--l10ntools/source/merge.cxx102
-rw-r--r--l10ntools/source/propex.cxx8
-rw-r--r--l10ntools/source/propmerge.cxx2
-rw-r--r--l10ntools/source/stringex.cxx8
-rw-r--r--l10ntools/source/stringmerge.cxx23
-rw-r--r--l10ntools/source/treemerge.cxx26
-rw-r--r--l10ntools/source/treex.cxx6
-rw-r--r--l10ntools/source/uimerge.cxx72
-rw-r--r--l10ntools/source/xmlparse.cxx78
-rw-r--r--l10ntools/source/xrmmerge.cxx11
28 files changed, 714 insertions, 948 deletions
diff --git a/l10ntools/StaticLibrary_transex.mk b/l10ntools/StaticLibrary_transex.mk
index 033358ac76bd..0c3bbff42970 100644
--- a/l10ntools/StaticLibrary_transex.mk
+++ b/l10ntools/StaticLibrary_transex.mk
@@ -43,7 +43,8 @@ $(eval $(call gb_StaticLibrary_use_externals,transex,\
))
$(eval $(call gb_StaticLibrary_add_exception_objects,transex,\
- l10ntools/source/export2 \
+ l10ntools/source/helper \
+ l10ntools/source/common \
l10ntools/source/merge \
l10ntools/source/po \
))
diff --git a/l10ntools/inc/common.hxx b/l10ntools/inc/common.hxx
new file mode 100644
index 000000000000..93f2d008cb82
--- /dev/null
+++ b/l10ntools/inc/common.hxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+/// Methods used by all of executables
+
+#ifndef INCLUDED_L10NTOOLS_SOURCE_COMMON_HXX
+#define INCLUDED_L10NTOOLS_SOURCE_COMMON_HXX
+
+#include "sal/config.h"
+
+#include <iostream>
+#include <rtl/string.hxx>
+#include "po.hxx"
+
+namespace common {
+
+//result type of handleArguments()
+struct HandledArgs
+{
+ OString m_sInputFile;
+ OString m_sOutputFile;
+ OString m_sMergeSrc;
+ OString m_sLanguage;
+ bool m_bMergeMode;
+ HandledArgs()
+ : m_sInputFile( OString() )
+ , m_sOutputFile( OString() )
+ , m_sMergeSrc( OString() )
+ , m_sLanguage( OString() )
+ , m_bMergeMode( false )
+ {}
+};
+
+bool handleArguments(int argc, char * argv[], HandledArgs& o_aHandledArgs);
+
+void writeUsage(const OString& rName, const OString& rFileType);
+
+void writePoEntry(
+ const OString& rExecutable, PoOfstream& rPoStream, const OString& rSourceFile,
+ const OString& rResType, const OString& rGroupId, const OString& rLocalId,
+ const OString& rHelpText, const OString& rText, const PoEntry::TYPE eType = PoEntry::TTEXT );
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx
index fbe7adac497c..e3a0913515e6 100644
--- a/l10ntools/inc/export.hxx
+++ b/l10ntools/inc/export.hxx
@@ -109,6 +109,8 @@ public:
class ResData
{
public:
+ ResData(const rtl::OString &rPF, const rtl::OString &rGId);
+ ResData(const rtl::OString &rPF, const rtl::OString &rGId , const rtl::OString &rFilename);
~ResData();
sal_Bool SetId(const rtl::OString &rId, sal_uInt16 nLevel);
@@ -153,67 +155,6 @@ public:
ExportList *pPairedList;
rtl::OString sPForm;
-
- ResData(const rtl::OString &rPF, const rtl::OString &rGId)
- :
- nWidth( 0 ),
- nChildIndex( 0 ),
- nIdLevel( ID_LEVEL_NULL ),
- bChild( sal_False ),
- bChildWithText( sal_False ),
- bText( sal_False ),
- bHelpText( sal_False ),
- bQuickHelpText( sal_False ),
- bTitle( sal_False ),
- bList( sal_False ),
- bRestMerged( sal_False ),
- sGId( rGId ),
- nTextRefId( REFID_NONE ),
- nHelpTextRefId( REFID_NONE ),
- nQuickHelpTextRefId( REFID_NONE ),
- nTitleRefId( REFID_NONE ),
- sTextTyp( "Text" ),
- pStringList( NULL ),
- pUIEntries( NULL ),
- pItemList( NULL ),
- pFilterList( NULL ),
- pPairedList( NULL ),
- sPForm( rPF )
- {
- sGId = sGId.replaceAll("\r", rtl::OString());
- sPForm = sPForm.replaceAll("\r", rtl::OString());
- }
-
- ResData(const rtl::OString &rPF, const rtl::OString &rGId , const rtl::OString &rFilename)
- :
- nWidth( 0 ),
- nChildIndex( 0 ),
- nIdLevel( ID_LEVEL_NULL ),
- bChild( sal_False ),
- bChildWithText( sal_False ),
- bText( sal_False ),
- bHelpText( sal_False ),
- bQuickHelpText( sal_False ),
- bTitle( sal_False ),
- bList( sal_False ),
- bRestMerged( sal_False ),
- sGId( rGId ),
- sFilename( rFilename ),
- nTextRefId( REFID_NONE ),
- nHelpTextRefId( REFID_NONE ),
- nQuickHelpTextRefId( REFID_NONE ),
- nTitleRefId( REFID_NONE ),
- sTextTyp( "Text" ),
- pStringList( NULL ),
- pUIEntries( NULL ),
- pItemList( NULL ),
- pFilterList( NULL ),
- pPairedList( NULL ),
- sPForm( rPF )
- {
- sGId = sGId.replaceAll("\r", rtl::OString());
- sPForm = sPForm.replaceAll("\r", rtl::OString());
- }
};
@@ -244,23 +185,6 @@ typedef ::std::vector< ResData* > ResStack;
class WordTransformer;
class ParserQueue;
-//result type of handleArguments()
-struct HandledArgs
-{
- OString m_sInputFile;
- OString m_sOutputFile;
- OString m_sMergeSrc;
- OString m_sLanguage;
- bool m_bMergeMode;
- HandledArgs()
- : m_sInputFile( OString() )
- , m_sOutputFile( OString() )
- , m_sMergeSrc( OString() )
- , m_sLanguage( OString() )
- , m_bMergeMode( false )
- {}
-};
-
class Export
{
private:
@@ -292,40 +216,11 @@ private:
sal_Bool bReadOver;
sal_Bool bDontWriteOutput;
rtl::OString sLastTextTyp;
- static bool isInitialized;
+ bool isInitialized;
rtl::OString sFilename;
+ rtl::OString sLanguages;
-
-public:
- ParserQueue* pParseQueue; // public ?
- static rtl::OString sLanguages; // public ?
-
- static bool handleArguments(int argc, char * argv[], HandledArgs& o_aHandledArgs);
- static void writeUsage(const OString& rName, const OString& rFileType);
- static void writePoEntry(const OString& rExecutable, PoOfstream& rPoStream, const OString& rSourceFile,
- const OString& rResType, const OString& rGroupId, const OString& rLocalId,
- const OString& rHelpText, const OString& rText,
- const PoEntry::TYPE eType = PoEntry::TTEXT);
-
- static void InitLanguages( bool bMergeMode = false );
- static void InitForcedLanguages( bool bMergeMode = false );
- static std::vector<rtl::OString> GetLanguages();
-
- static void SetLanguages( std::vector<rtl::OString> val );
- static void RemoveUTF8ByteOrderMarker( rtl::OString &rString );
- static bool hasUTF8ByteOrderMarker( const rtl::OString &rString );
- static rtl::OString QuoteHTML( rtl::OString const &rString );
-
- static rtl::OString UnquoteHTML( rtl::OString const &rString );
-
- static bool isSourceLanguage(const rtl::OString &rLanguage);
- static bool isAllowed(const rtl::OString &rLanguage);
-
- static void Languages( std::vector<rtl::OString>::const_iterator& begin , std::vector<rtl::OString>::const_iterator& end );
-
-private:
- static std::vector<rtl::OString> aLanguages;
- static std::vector<rtl::OString> aForcedLanguages;
+ std::vector<rtl::OString> aLanguages;
sal_Bool WriteData( ResData *pResData, sal_Bool bCreateNew = sal_False );// called befor dest. cur ResData
sal_Bool WriteExportList( ResData *pResData, ExportList *pExportList,
@@ -352,17 +247,20 @@ private:
void WriteToMerged(const rtl::OString &rText , bool bSDFContent);
void SetChildWithText();
+ void InitLanguages( bool bMergeMode = false );
+
void CutComment( rtl::OString &rText );
public:
- Export(const rtl::OString &rOutput);
- Export(const rtl::OString &rMergeSource, const rtl::OString &rOutput);
+ Export(const OString &rOutput, const OString &rLanguage);
+ Export(const OString &rMergeSource, const OString &rOutput, const OString &rLanguage);
~Export();
void Init();
int Execute( int nToken, const char * pToken ); // called from lexer
void SetError() { bError = sal_True; }
sal_Bool GetError() { return bError; }
+ ParserQueue* pParseQueue; // public!!
};
diff --git a/l10ntools/inc/helper.hxx b/l10ntools/inc/helper.hxx
new file mode 100644
index 000000000000..4dd2dd137937
--- /dev/null
+++ b/l10ntools/inc/helper.hxx
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+/// Helper methods to work with xml files
+
+#ifndef INCLUDED_L10NTOOLS_SOURCE_HELPER_HXX
+#define INCLUDED_L10NTOOLS_SOURCE_HELPER_HXX
+
+#include "sal/config.h"
+#include "sal/types.h"
+
+#include <cassert>
+
+#include <libxml/parser.h>
+
+#include <rtl/string.hxx>
+#include <rtl/strbuf.hxx>
+
+
+namespace helper {
+
+OString QuotHTML(const rtl::OString &rString);
+
+bool isWellFormedXML( OString const & text );
+
+//Convert xmlChar* to OString
+OString xmlStrToOString( const xmlChar* pString );
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/inc/helpmerge.hxx b/l10ntools/inc/helpmerge.hxx
index fd11609a9a59..1f11726182f6 100644
--- a/l10ntools/inc/helpmerge.hxx
+++ b/l10ntools/inc/helpmerge.hxx
@@ -17,7 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include "export.hxx"
#include "xmlparse.hxx"
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
diff --git a/l10ntools/inc/lngmerge.hxx b/l10ntools/inc/lngmerge.hxx
index 4631bb3536f8..8c5940cbdfee 100644
--- a/l10ntools/inc/lngmerge.hxx
+++ b/l10ntools/inc/lngmerge.hxx
@@ -22,8 +22,8 @@
#include <iosfwd>
#include <vector>
+#include "common.hxx"
#include "export.hxx"
-#include "po.hxx"
typedef std::vector< rtl::OString* > LngLineList;
diff --git a/l10ntools/inc/xrmmerge.hxx b/l10ntools/inc/xrmmerge.hxx
index 83736263796c..8659fe1f4f19 100644
--- a/l10ntools/inc/xrmmerge.hxx
+++ b/l10ntools/inc/xrmmerge.hxx
@@ -20,7 +20,6 @@
#include "sal/config.h"
#include <fstream>
-#include "po.hxx"
//
// XRMResParser
diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx
index 4586e7192d4f..695620004e5e 100644
--- a/l10ntools/source/cfgmerge.cxx
+++ b/l10ntools/source/cfgmerge.cxx
@@ -47,10 +47,10 @@ extern "C" {
FILE * init(int argc, char ** argv) {
- HandledArgs aArgs;
- if ( !Export::handleArguments(argc, argv, aArgs) )
+ common::HandledArgs aArgs;
+ if ( !common::handleArguments(argc, argv, aArgs) )
{
- Export::writeUsage("cfgex","*.xcu");
+ common::writeUsage("cfgex","*.xcu");
std::exit(EXIT_FAILURE);
}
global::inputPathname = aArgs.m_sInputFile;
@@ -83,6 +83,88 @@ void workOnTokenSet(int nTyp, char * pTokenText) {
}
+namespace
+{
+
+static OString lcl_QuoteHTML( const OString& rString )
+{
+ rtl::OStringBuffer sReturn;
+ for ( sal_Int32 i = 0; i < rString.getLength(); i++ ) {
+ rtl::OString sTemp = rString.copy( i );
+ if ( sTemp.match( "<Arg n=" ) ) {
+ while ( i < rString.getLength() && rString[i] != '>' ) {
+ sReturn.append(rString[i]);
+ i++;
+ }
+ if ( rString[i] == '>' ) {
+ sReturn.append('>');
+ i++;
+ }
+ }
+ if ( i < rString.getLength()) {
+ switch ( rString[i]) {
+ case '<':
+ sReturn.append("&lt;");
+ break;
+
+ case '>':
+ sReturn.append("&gt;");
+ break;
+
+ case '\"':
+ sReturn.append("&quot;");
+ break;
+
+ case '\'':
+ sReturn.append("&apos;");
+ break;
+
+ case '&':
+ if ((( i + 4 ) < rString.getLength()) &&
+ ( rString.copy( i, 5 ) == "&amp;" ))
+ sReturn.append(rString[i]);
+ else
+ sReturn.append("&amp;");
+ break;
+
+ default:
+ sReturn.append(rString[i]);
+ break;
+ }
+ }
+ }
+ return sReturn.makeStringAndClear();
+}
+
+static OString lcl_UnquoteHTML( const OString& rString )
+{
+ rtl::OStringBuffer sReturn;
+ for (sal_Int32 i = 0; i != rString.getLength();) {
+ if (rString.match("&amp;", i)) {
+ sReturn.append('&');
+ i += RTL_CONSTASCII_LENGTH("&amp;");
+ } else if (rString.match("&lt;", i)) {
+ sReturn.append('<');
+ i += RTL_CONSTASCII_LENGTH("&lt;");
+ } else if (rString.match("&gt;", i)) {
+ sReturn.append('>');
+ i += RTL_CONSTASCII_LENGTH("&gt;");
+ } else if (rString.match("&quot;", i)) {
+ sReturn.append('"');
+ i += RTL_CONSTASCII_LENGTH("&quot;");
+ } else if (rString.match("&apos;", i)) {
+ sReturn.append('\'');
+ i += RTL_CONSTASCII_LENGTH("&apos;");
+ } else {
+ sReturn.append(rString[i]);
+ ++i;
+ }
+ }
+ return sReturn.makeStringAndClear();
+}
+
+} // anonymous namespace
+
//
// class CfgStackData
//
@@ -407,9 +489,9 @@ void CfgExport::WorkOnResourceEnd()
if ( sText.isEmpty())
sText = sFallback;
- sText = Export::UnquoteHTML( sText );
+ sText = lcl_UnquoteHTML( sText );
- Export::writePoEntry(
+ common::writePoEntry(
"Cfgex", pOutputStream, sPath, pStackData->sResTyp,
sGroupId, sLocalId, sXComment, sText);
}
@@ -422,7 +504,7 @@ void CfgExport::WorkOnText(
const rtl::OString &rIsoLang
)
{
- if( rIsoLang.getLength() ) rText = Export::UnquoteHTML( rText );
+ if( rIsoLang.getLength() ) rText = lcl_UnquoteHTML( rText );
}
@@ -499,10 +581,10 @@ void CfgMerge::WorkOnText(rtl::OString &rText, const rtl::OString& rLangIndex)
rtl::OString sContent;
pEntrys->GetText( sContent, STRING_TYP_TEXT, rLangIndex );
- if ( Export::isAllowed( rLangIndex ) &&
+ if ( !rLangIndex.equalsIgnoreAsciiCase("en-US") &&
( sContent != "-" ) && !sContent.isEmpty())
{
- rText = Export::QuoteHTML( rText );
+ rText = lcl_QuoteHTML( rText );
}
}
}
@@ -534,7 +616,7 @@ void CfgMerge::WorkOnResourceEnd()
( sContent != "-" ) && !sContent.isEmpty())
{
- rtl::OString sText = Export::QuoteHTML( sContent);
+ rtl::OString sText = lcl_QuoteHTML( sContent);
rtl::OString sAdditionalLine( "\t" );
diff --git a/l10ntools/source/common.cxx b/l10ntools/source/common.cxx
new file mode 100644
index 000000000000..35302117a984
--- /dev/null
+++ b/l10ntools/source/common.cxx
@@ -0,0 +1,153 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "common.hxx"
+#include "po.cxx"
+
+//flags for handleArguments()
+#define STATE_NON 0x0001
+#define STATE_INPUT 0x0002
+#define STATE_OUTPUT 0x0003
+#define STATE_MERGESRC 0x0005
+#define STATE_LANGUAGES 0x0006
+
+namespace common {
+
+bool handleArguments(
+ int argc, char * argv[], HandledArgs& o_aHandledArgs)
+{
+ o_aHandledArgs = HandledArgs();
+ sal_uInt16 nState = STATE_NON;
+
+ for( int i = 1; i < argc; i++ )
+ {
+ if ( OString( argv[ i ] ).toAsciiUpperCase() == "-I" )
+ {
+ nState = STATE_INPUT; // next token specifies source file
+ }
+ else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-O" )
+ {
+ nState = STATE_OUTPUT; // next token specifies the dest file
+ }
+ else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-M" )
+ {
+ nState = STATE_MERGESRC; // next token specifies the merge database
+ }
+ else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-L" )
+ {
+ nState = STATE_LANGUAGES;
+ }
+ else
+ {
+ switch ( nState )
+ {
+ case STATE_NON:
+ {
+ return false; // no valid command line
+ }
+ case STATE_INPUT:
+ {
+ o_aHandledArgs.m_sInputFile = OString( argv[i] );
+ }
+ break;
+ case STATE_OUTPUT:
+ {
+ o_aHandledArgs.m_sOutputFile = OString( argv[i] );
+ }
+ break;
+ case STATE_MERGESRC:
+ {
+ o_aHandledArgs.m_sMergeSrc = OString( argv[i] );
+ o_aHandledArgs.m_bMergeMode = true;
+ }
+ break;
+ case STATE_LANGUAGES:
+ {
+ o_aHandledArgs.m_sLanguage = OString( argv[i] );
+ }
+ break;
+ }
+ }
+ }
+ if( !o_aHandledArgs.m_sInputFile.isEmpty() &&
+ !o_aHandledArgs.m_sOutputFile.isEmpty() )
+ {
+ return true;
+ }
+ else
+ {
+ o_aHandledArgs = HandledArgs();
+ return false;
+ }
+}
+
+void writeUsage(const OString& rName, const OString& rFileType)
+{
+ std::cout
+ << " Syntax: " << rName.getStr()
+ << " -i FileIn -o FileOut [-m DataBase] [-l Lang]\n"
+ << " FileIn: Source files (" << rFileType.getStr() << ")\n"
+ << " FileOut: Destination file (*.*)\n"
+ << " DataBase: Mergedata (*.po)\n"
+ << " Lang: Restrict the handled languag; one element of\n"
+ << " (de, en-US, ...) or all\n";
+}
+
+void writePoEntry(
+ const OString& rExecutable, PoOfstream& rPoStream, const OString& rSourceFile,
+ const OString& rResType, const OString& rGroupId, const OString& rLocalId,
+ const OString& rHelpText, const OString& rText, const PoEntry::TYPE eType )
+{
+ try
+ {
+ PoEntry aPO(rSourceFile, rResType, rGroupId, rLocalId, rHelpText, rText, eType);
+ rPoStream.writeEntry( aPO );
+ }
+ catch( PoEntry::Exception& aException )
+ {
+ if(aException == PoEntry::NOSOURCFILE)
+ {
+ std::cerr << rExecutable << " warning: no sourcefile specified for po entry\n";
+ }
+ else
+ {
+ std::cerr << rExecutable << " warning: inavlid po attributes extracted from " << rSourceFile << "\n";
+ if(aException == PoEntry::NOGROUPID)
+ {
+ std::cerr << "No groupID specified!\n";
+ std::cerr << "String: " << rText << "\n";
+ }
+ else if (aException == PoEntry::NOSTRING)
+ {
+ std::cerr << "No string specified!\n";
+ std::cerr << "GroupID: " << rGroupId << "\n";
+ if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
+ }
+ else
+ {
+ if (aException == PoEntry::NORESTYPE)
+ {
+ std::cerr << "No resource type specified!\n";
+ }
+ else if (aException == PoEntry::WRONGHELPTEXT)
+ {
+ std::cerr << "x-comment length is 5 characters:" << rHelpText << "\n";
+ }
+
+ std::cerr << "GroupID: " << rGroupId << "\n";
+ if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
+ std::cerr << "String: " << rText << "\n";
+ }
+ }
+ }
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/common.hxx b/l10ntools/source/common.hxx
deleted file mode 100644
index 6c2d2c71f472..000000000000
--- a/l10ntools/source/common.hxx
+++ /dev/null
@@ -1,76 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Version: MPL 1.1 / GPLv3+ / LGPLv3+
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License or as specified alternatively below. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * Major Contributor(s):
- * [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
- * (initial developer) ]
- *
- * All Rights Reserved.
- *
- * For minor contributions see the git repository.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
- * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
- * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
- * instead of those above.
- */
-
-#ifndef INCLUDED_L10NTOOLS_SOURCE_COMMON_HXX
-#define INCLUDED_L10NTOOLS_SOURCE_COMMON_HXX
-
-#include "sal/config.h"
-
-#include <cstdlib>
-#include <iostream>
-
-#include "osl/file.hxx"
-#include "osl/process.h"
-#include "osl/thread.h"
-#include "rtl/string.h"
-#include "rtl/string.hxx"
-#include "rtl/textcvt.h"
-#include "rtl/uri.hxx"
-#include "rtl/ustring.h"
-#include "rtl/ustring.hxx"
-
-namespace common {
-
-inline rtl::OUString pathnameToAbsoluteUrl(rtl::OUString const & pathname) {
- rtl::OUString url;
- if (osl::FileBase::getFileURLFromSystemPath(pathname, url)
- != osl::FileBase::E_None)
- {
- std::cerr << "Error: Cannot convert input pathname to URL\n";
- std::exit(EXIT_FAILURE);
- }
- rtl::OUString cwd;
- if (osl_getProcessWorkingDir(&cwd.pData) != osl_Process_E_None) {
- std::cerr << "Error: Cannot determine cwd\n";
- std::exit(EXIT_FAILURE);
- }
- if (osl::FileBase::getAbsoluteFileURL(cwd, url, url)
- != osl::FileBase::E_None)
- {
- std::cerr << "Error: Cannot convert input URL to absolute URL\n";
- std::exit(EXIT_FAILURE);
- }
- return url;
-}
-
-}
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx
index 912f80b4c392..900e850d13b4 100644
--- a/l10ntools/source/export.cxx
+++ b/l10ntools/source/export.cxx
@@ -27,7 +27,6 @@
#include <stdlib.h>
#include "common.hxx"
#include "export.hxx"
-#include "helper.hxx"
#include "tokens.h"
#include <iostream>
#include <rtl/strbuf.hxx>
@@ -45,20 +44,19 @@ OString inputPathname;
boost::scoped_ptr< Export > exporter;
}
+
}
extern "C" {
FILE * init(int argc, char ** argv) {
- HandledArgs aArgs;
- if ( !Export::handleArguments(argc, argv, aArgs) )
+ common::HandledArgs aArgs;
+ if ( !common::handleArguments(argc, argv, aArgs) )
{
- Export::writeUsage("transex3","*.src/*.hrc");
+ common::writeUsage("transex3","*.src/*.hrc");
std::exit(EXIT_FAILURE);
}
- Export::sLanguages = aArgs.m_sLanguage;
- Export::InitLanguages();
global::inputPathname = aArgs.m_sInputFile;
FILE * pFile = std::fopen(global::inputPathname.getStr(), "r");
@@ -71,9 +69,9 @@ FILE * init(int argc, char ** argv) {
if (aArgs.m_bMergeMode) {
global::exporter.reset(
- new Export(aArgs.m_sMergeSrc.getStr(), aArgs.m_sOutputFile.getStr()));
+ new Export(aArgs.m_sMergeSrc, aArgs.m_sOutputFile, aArgs.m_sLanguage));
} else {
- global::exporter.reset(new Export(aArgs.m_sOutputFile.getStr()));
+ global::exporter.reset(new Export(aArgs.m_sOutputFile, aArgs.m_sLanguage));
}
global::exporter->Init();
@@ -159,7 +157,25 @@ sal_Bool ResData::SetId( const rtl::OString& rId, sal_uInt16 nLevel )
// class Export
//
-Export::Export(const rtl::OString &rOutput)
+namespace
+{
+
+static sal_Int32 lcl_countOccurrences(const OString& text, char c)
+{
+ sal_Int32 n = 0;
+ for (sal_Int32 i = 0;; ++i) {
+ i = text.indexOf(c, i);
+ if (i == -1) {
+ break;
+ }
+ ++n;
+ }
+ return n;
+}
+
+}
+
+Export::Export(const OString &rOutput, const OString &rLanguage)
:
pWordTransformer( NULL ),
bDefine( sal_False ),
@@ -173,11 +189,12 @@ Export::Export(const rtl::OString &rOutput)
bError( sal_False ),
bReadOver( sal_False ),
bDontWriteOutput( sal_False ),
- sFilename( global::inputPathname )
+ isInitialized( false ),
+ sFilename( global::inputPathname ),
+ sLanguages( rLanguage ),
+ pParseQueue( new ParserQueue( *this ) )
{
- pParseQueue = new ParserQueue( *this );
-
- if( !isInitialized ) InitLanguages();
+ InitLanguages();
// used when export is enabled
// open output stream
@@ -188,7 +205,9 @@ Export::Export(const rtl::OString &rOutput)
}
}
-Export::Export(const rtl::OString &rMergeSource, const rtl::OString &rOutput)
+Export::Export(
+ const OString &rMergeSource, const OString &rOutput,
+ const OString &rLanguage )
:
pWordTransformer( NULL ),
bDefine( sal_False ),
@@ -203,10 +222,12 @@ Export::Export(const rtl::OString &rMergeSource, const rtl::OString &rOutput)
bError( sal_False ),
bReadOver( sal_False ),
bDontWriteOutput( sal_False ),
- sFilename( global::inputPathname )
+ isInitialized( false ),
+ sFilename( global::inputPathname ),
+ sLanguages( rLanguage ),
+ pParseQueue( new ParserQueue( *this ) )
{
- pParseQueue = new ParserQueue( *this );
- if( !isInitialized ) InitLanguages( bMergeMode );
+ InitLanguages( bMergeMode );
// used when merge is enabled
// open output stream
@@ -544,8 +565,8 @@ int Export::Execute( int nToken, const char * pToken )
nListLevel = 0;
}
if (sToken.indexOf( '{' ) != -1
- && (helper::countOccurrences(sToken, '{')
- > helper::countOccurrences(sToken, '}')))
+ && (lcl_countOccurrences(sToken, '{')
+ > lcl_countOccurrences(sToken, '}')))
{
Parse( LEVELUP, "" );
}
@@ -642,7 +663,7 @@ int Export::Execute( int nToken, const char * pToken )
SetChildWithText();
sal_Int32 n = 0;
rtl::OString sEntry(sToken.getToken(1, '"', n));
- if ( helper::countOccurrences(sToken, '"') > 2 )
+ if ( lcl_countOccurrences(sToken, '"') > 2 )
sEntry += "\"";
if ( sEntry == "\\\"" )
sEntry = "\"";
@@ -686,7 +707,7 @@ int Export::Execute( int nToken, const char * pToken )
sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("UINAME")))
{
SetChildWithText();
- if ( Export::isSourceLanguage( sLangIndex ) )
+ if ( sLangIndex.equalsIgnoreAsciiCase("en-US") )
pResData->SetId( sText, ID_LEVEL_TEXT );
pResData->bText = sal_True;
@@ -935,16 +956,16 @@ sal_Bool Export::WriteData( ResData *pResData, sal_Bool bCreateNew )
if (sXText.isEmpty())
sXText = "-";
- writePoEntry(
+ common::writePoEntry(
"Transex3", *aOutput.mPo, global::inputPathname,
pResData->sResTyp, sGID, sLID, sXHText, sXText);
if( !sXQHText.isEmpty() )
- writePoEntry(
+ common::writePoEntry(
"Transex3", *aOutput.mPo, global::inputPathname, pResData->sResTyp,
sGID, sLID, OString(), sXQHText, PoEntry::TQUICKHELPTEXT );
if( !sXTitle.isEmpty() )
- writePoEntry(
+ common::writePoEntry(
"Transex3", *aOutput.mPo, global::inputPathname, pResData->sResTyp,
sGID, sLID, OString(), sXTitle, PoEntry::TTITLE );
@@ -1051,7 +1072,7 @@ sal_Bool Export::WriteExportList(ResData *pResData, ExportList *pExportList,
if( sText == "\\\"" )
sText = "\"";
}
- writePoEntry(
+ common::writePoEntry(
"Transex3", *aOutput.mPo, global::inputPathname,
rTyp, sGID, sLID, OString(), sText);
}
@@ -1150,7 +1171,7 @@ void Export::InsertListEntry(const rtl::OString &rText, const rtl::OString &rLin
}else
(*pCurEntry)[ m_sListLang ] = rText;
- if ( Export::isSourceLanguage( m_sListLang ) ) {
+ if ( m_sListLang.equalsIgnoreAsciiCase("en-US") ) {
(*pCurEntry)[ SOURCE_LANGUAGE ] = rLine;
pList->NewSourceLanguageListEntry();
@@ -1204,7 +1225,7 @@ rtl::OString Export::GetText(const rtl::OString &rSource, int nToken)
replaceAll("\\0x7F", "-=<[0x7F]>=-");
sal_uInt16 nState = TXT_STATE_TEXT;
- for (sal_Int32 i = 1; i <= helper::countOccurrences(sTmp, '"'); ++i)
+ for (sal_Int32 i = 1; i <= lcl_countOccurrences(sTmp, '"'); ++i)
{
rtl::OString sToken(sTmp.getToken(i, '"'));
if (!sToken.isEmpty()) {
@@ -1501,7 +1522,10 @@ sal_Bool Export::PrepareTextToMerge(rtl::OString &rText, sal_uInt16 nTyp,
// Init Languages
if( Export::sLanguages.equalsIgnoreAsciiCase("ALL") )
- SetLanguages( pMergeDataFile->GetLanguages() );
+ {
+ aLanguages = pMergeDataFile->GetLanguages();
+ isInitialized = true;
+ }
else if( !isInitialized )InitLanguages();
}
@@ -1518,13 +1542,13 @@ sal_Bool Export::PrepareTextToMerge(rtl::OString &rText, sal_uInt16 nTyp,
rtl::OString sContent;
pEntrys->GetTransex3Text(sContent, nTyp, rLangIndex);
- if (sContent.isEmpty() && (!Export::isSourceLanguage(rLangIndex)))
+ if (sContent.isEmpty() && !rLangIndex.equalsIgnoreAsciiCase("en-US"))
{
rText = sOrigText;
return sal_False; // no data found
}
- if (Export::isSourceLanguage(rLangIndex))
+ if (rLangIndex.equalsIgnoreAsciiCase("en-US"))
return sal_False;
rtl::OString sPostFix( rText.copy( ++nEnd ));
@@ -1565,7 +1589,7 @@ void Export::ResData2Output( PFormEntrys *pEntry, sal_uInt16 nType, const rtl::O
sOutput += rTextType;
- if ( ! Export::isSourceLanguage( sCur ) ) {
+ if ( !sCur.equalsIgnoreAsciiCase("en-US") ) {
sOutput += "[ ";
sOutput += sCur;
sOutput += " ] ";
@@ -1602,7 +1626,10 @@ void Export::MergeRest( ResData *pResData, sal_uInt16 nMode )
// Init Languages
if (Export::sLanguages.equalsIgnoreAsciiCase("ALL"))
- SetLanguages( pMergeDataFile->GetLanguages() );
+ {
+ aLanguages = pMergeDataFile->GetLanguages();
+ isInitialized = true;
+ }
else if( !isInitialized )InitLanguages();
}
@@ -1898,6 +1925,29 @@ void Export::SetChildWithText()
}
}
+void Export::InitLanguages( bool bMerge ){
+
+ if( !isInitialized )
+ {
+ rtl::OString sTmp;
+ OStringBoolHashMap aEnvLangs;
+
+ sal_Int32 nIndex = 0;
+ do
+ {
+ rtl::OString aToken = sLanguages.getToken(0, ',', nIndex);
+ sTmp = aToken.getToken(0, '=').trim();
+ if( bMerge && sTmp.equalsIgnoreAsciiCase("en-US") ){}
+ else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) ){
+ aLanguages.push_back( sTmp );
+ }
+ }
+ while ( nIndex >= 0 );
+
+ isInitialized = true;
+ }
+}
+
void ParserQueue::Push( const QueueEntry& aEntry )
{
sal_Int32 nLen = aEntry.sLine.getLength();
diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx
deleted file mode 100644
index 9e69db245a47..000000000000
--- a/l10ntools/source/export2.cxx
+++ /dev/null
@@ -1,364 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include "sal/config.h"
-
-#include "export.hxx"
-#include <stdio.h>
-#include <osl/time.h>
-#include <osl/process.h>
-#include <rtl/strbuf.hxx>
-#include <rtl/ustring.hxx>
-#include <sal/macros.h>
-#include <iostream>
-#include <iomanip>
-#include <time.h>
-#include <stdlib.h>
-
-//flags for handleArguments()
-#define STATE_NON 0x0001
-#define STATE_INPUT 0x0002
-#define STATE_OUTPUT 0x0003
-#define STATE_MERGESRC 0x0006
-#define STATE_LANGUAGES 0x0007
-
-//
-// class ResData();
-//
-
-/*****************************************************************************/
-ResData::~ResData()
-/*****************************************************************************/
-{
- if ( pStringList ) {
- // delete existing res. of type StringList
- for ( size_t i = 0; i < pStringList->size(); i++ ) {
- ExportListEntry* test = (*pStringList)[ i ];
- if( test != NULL ) delete test;
- }
- delete pStringList;
- }
- if ( pFilterList ) {
- // delete existing res. of type FilterList
- for ( size_t i = 0; i < pFilterList->size(); i++ ) {
- ExportListEntry* test = (*pFilterList)[ i ];
- delete test;
- }
- delete pFilterList;
- }
- if ( pItemList ) {
- // delete existing res. of type ItemList
- for ( size_t i = 0; i < pItemList->size(); i++ ) {
- ExportListEntry* test = (*pItemList)[ i ];
- delete test;
- }
- delete pItemList;
- }
- if ( pUIEntries ) {
- // delete existing res. of type UIEntries
- for ( size_t i = 0; i < pUIEntries->size(); i++ ) {
- ExportListEntry* test = (*pUIEntries)[ i ];
- delete test;
- }
- delete pUIEntries;
- }
-}
-
-//
-// class Export
-//
-
-/*****************************************************************************/
-rtl::OString Export::sLanguages;
-/*****************************************************************************/
-
-bool Export::handleArguments(
- int argc, char * argv[], HandledArgs& o_aHandledArgs)
-{
- o_aHandledArgs = HandledArgs();
- sal_uInt16 nState = STATE_NON;
-
- for( int i = 1; i < argc; i++ )
- {
- if ( OString( argv[ i ] ).toAsciiUpperCase() == "-I" )
- {
- nState = STATE_INPUT; // next token specifies source file
- }
- else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-O" )
- {
- nState = STATE_OUTPUT; // next token specifies the dest file
- }
- else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-M" )
- {
- nState = STATE_MERGESRC; // next token specifies the merge database
- }
- else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-L" )
- {
- nState = STATE_LANGUAGES;
- }
- else
- {
- switch ( nState )
- {
- case STATE_NON:
- {
- return false; // no valid command line
- }
- case STATE_INPUT:
- {
- o_aHandledArgs.m_sInputFile = OString( argv[i] );
- }
- break;
- case STATE_OUTPUT:
- {
- o_aHandledArgs.m_sOutputFile = OString( argv[i] );
- }
- break;
- case STATE_MERGESRC:
- {
- o_aHandledArgs.m_sMergeSrc = OString( argv[i] );
- o_aHandledArgs.m_bMergeMode = true;
- }
- break;
- case STATE_LANGUAGES:
- {
- o_aHandledArgs.m_sLanguage = OString( argv[i] );
- }
- break;
- }
- }
- }
- if( !o_aHandledArgs.m_sInputFile.isEmpty() &&
- !o_aHandledArgs.m_sOutputFile.isEmpty() )
- {
- return true;
- }
- else
- {
- o_aHandledArgs = HandledArgs();
- return false;
- }
-}
-
-void Export::writeUsage(const OString& rName, const OString& rFileType)
-{
- std::cout
- << " Syntax: " << rName.getStr()
- << " -i FileIn -o FileOut [-m DataBase] [-l Lang]\n"
- << " FileIn: Source files (" << rFileType.getStr() << ")\n"
- << " FileOut: Destination file (*.*)\n"
- << " DataBase: Mergedata (*.po)\n"
- << " Lang: Restrict the handled languag; one element of\n"
- << " (de, en-US, ...) or all\n";
-}
-
-void Export::writePoEntry(
- const OString& rExecutable, PoOfstream& rPoStream, const OString& rSourceFile,
- const OString& rResType, const OString& rGroupId, const OString& rLocalId,
- const OString& rHelpText, const OString& rText, const PoEntry::TYPE eType )
-{
- try
- {
- PoEntry aPO(rSourceFile, rResType, rGroupId, rLocalId, rHelpText, rText, eType);
- rPoStream.writeEntry( aPO );
- }
- catch( PoEntry::Exception& aException )
- {
- if(aException == PoEntry::NOSOURCFILE)
- {
- std::cerr << rExecutable << " warning: no sourcefile specified for po entry\n";
- }
- else
- {
- std::cerr << rExecutable << " warning: inavlid po attributes extracted from " << rSourceFile << "\n";
- if(aException == PoEntry::NOGROUPID)
- {
- std::cerr << "No groupID specified!\n";
- std::cerr << "String: " << rText << "\n";
- }
- else if (aException == PoEntry::NOSTRING)
- {
- std::cerr << "No string specified!\n";
- std::cerr << "GroupID: " << rGroupId << "\n";
- if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
- }
- else
- {
- if (aException == PoEntry::NORESTYPE)
- {
- std::cerr << "No resource type specified!\n";
- }
- else if (aException == PoEntry::WRONGHELPTEXT)
- {
- std::cerr << "x-comment length is 5 characters:" << rHelpText << "\n";
- }
-
- std::cerr << "GroupID: " << rGroupId << "\n";
- if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
- std::cerr << "String: " << rText << "\n";
- }
- }
- }
-}
-
-
-/*****************************************************************************/
-void Export::SetLanguages( std::vector<rtl::OString> val ){
-/*****************************************************************************/
- aLanguages = val;
- isInitialized = true;
-}
-/*****************************************************************************/
-std::vector<rtl::OString> Export::GetLanguages(){
-/*****************************************************************************/
- return aLanguages;
-}
-std::vector<rtl::OString> Export::aLanguages = std::vector<rtl::OString>();
-std::vector<rtl::OString> Export::aForcedLanguages = std::vector<rtl::OString>();
-
-/*****************************************************************************/
-rtl::OString Export::QuoteHTML( rtl::OString const &rString )
-/*****************************************************************************/
-{
- rtl::OStringBuffer sReturn;
- for ( sal_Int32 i = 0; i < rString.getLength(); i++ ) {
- rtl::OString sTemp = rString.copy( i );
- if ( sTemp.match( "<Arg n=" ) ) {
- while ( i < rString.getLength() && rString[i] != '>' ) {
- sReturn.append(rString[i]);
- i++;
- }
- if ( rString[i] == '>' ) {
- sReturn.append('>');
- i++;
- }
- }
- if ( i < rString.getLength()) {
- switch ( rString[i]) {
- case '<':
- sReturn.append("&lt;");
- break;
-
- case '>':
- sReturn.append("&gt;");
- break;
-
- case '\"':
- sReturn.append("&quot;");
- break;
-
- case '\'':
- sReturn.append("&apos;");
- break;
-
- case '&':
- if ((( i + 4 ) < rString.getLength()) &&
- ( rString.copy( i, 5 ) == "&amp;" ))
- sReturn.append(rString[i]);
- else
- sReturn.append("&amp;");
- break;
-
- default:
- sReturn.append(rString[i]);
- break;
- }
- }
- }
- return sReturn.makeStringAndClear();
-}
-
-void Export::RemoveUTF8ByteOrderMarker( rtl::OString &rString )
-{
- if( hasUTF8ByteOrderMarker( rString ) )
- rString = rString.copy(3);
-}
-
-bool Export::hasUTF8ByteOrderMarker( const rtl::OString &rString )
-{
- return rString.getLength() >= 3 && rString[0] == '\xEF' &&
- rString[1] == '\xBB' && rString[2] == '\xBF' ;
-}
-
-/*****************************************************************************/
-rtl::OString Export::UnquoteHTML( rtl::OString const &rString )
-/*****************************************************************************/
-{
- rtl::OStringBuffer sReturn;
- for (sal_Int32 i = 0; i != rString.getLength();) {
- if (rString.match("&amp;", i)) {
- sReturn.append('&');
- i += RTL_CONSTASCII_LENGTH("&amp;");
- } else if (rString.match("&lt;", i)) {
- sReturn.append('<');
- i += RTL_CONSTASCII_LENGTH("&lt;");
- } else if (rString.match("&gt;", i)) {
- sReturn.append('>');
- i += RTL_CONSTASCII_LENGTH("&gt;");
- } else if (rString.match("&quot;", i)) {
- sReturn.append('"');
- i += RTL_CONSTASCII_LENGTH("&quot;");
- } else if (rString.match("&apos;", i)) {
- sReturn.append('\'');
- i += RTL_CONSTASCII_LENGTH("&apos;");
- } else {
- sReturn.append(rString[i]);
- ++i;
- }
- }
- return sReturn.makeStringAndClear();
-}
-
-bool Export::isSourceLanguage(const rtl::OString &rLanguage)
-{
- return !isAllowed(rLanguage);
-}
-
-bool Export::isAllowed(const rtl::OString &rLanguage)
-{
- return !rLanguage.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US"));
-}
-
-bool Export::isInitialized = false;
-
-/*****************************************************************************/
-void Export::InitLanguages( bool bMergeMode ){
-/*****************************************************************************/
- if( !isInitialized )
- {
- rtl::OString sTmp;
- OStringBoolHashMap aEnvLangs;
-
- sal_Int32 nIndex = 0;
- do
- {
- rtl::OString aToken = sLanguages.getToken(0, ',', nIndex);
- sTmp = aToken.getToken(0, '=').trim();
- if( bMergeMode && !isAllowed( sTmp ) ){}
- else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) ){
- aLanguages.push_back( sTmp );
- }
- }
- while ( nIndex >= 0 );
-
- isInitialized = true;
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/helper.cxx b/l10ntools/source/helper.cxx
new file mode 100644
index 000000000000..cbcf6d1572fb
--- /dev/null
+++ b/l10ntools/source/helper.cxx
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "helper.hxx"
+
+namespace helper {
+
+rtl::OString QuotHTML(const rtl::OString &rString)
+{
+ rtl::OStringBuffer sReturn;
+ for (sal_Int32 i = 0; i < rString.getLength(); ++i) {
+ switch (rString[i]) {
+ case '\\':
+ if (i < rString.getLength()) {
+ switch (rString[i + 1]) {
+ case '"':
+ case '<':
+ case '>':
+ case '\\':
+ ++i;
+ break;
+ }
+ }
+ // fall through
+ default:
+ sReturn.append(rString[i]);
+ break;
+
+ case '<':
+ sReturn.append("&lt;");
+ break;
+
+ case '>':
+ sReturn.append("&gt;");
+ break;
+
+ case '"':
+ sReturn.append("&quot;");
+ break;
+
+ case '&':
+ if (rString.match("&amp;", i))
+ sReturn.append('&');
+ else
+ sReturn.append("&amp;");
+ break;
+ }
+ }
+ return sReturn.makeStringAndClear();
+}
+
+bool isWellFormedXML( OString const & text )
+{
+ xmlDocPtr doc;
+ OString content;
+ bool result = true;
+
+ content = "<root>";
+ content += text;
+ content += "</root>";
+ doc = xmlParseMemory(content.getStr(),(int)content.getLength());
+ if (doc == NULL) {
+ result = false;
+ }
+ xmlFreeDoc(doc);
+ xmlCleanupParser();
+ return result;
+}
+
+//Convert xmlChar* to OString
+OString xmlStrToOString( const xmlChar* pString )
+{
+ xmlChar* pTemp = xmlStrdup( pString );
+ OString sResult =
+ static_cast<OString>(reinterpret_cast<sal_Char*>( pTemp ));
+ xmlFree( pTemp );
+ return sResult;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/helper.hxx b/l10ntools/source/helper.hxx
deleted file mode 100644
index 1d268dd1c0f7..000000000000
--- a/l10ntools/source/helper.hxx
+++ /dev/null
@@ -1,181 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Version: MPL 1.1 / GPLv3+ / LGPLv3+
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License or as specified alternatively below. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * Major Contributor(s):
- * [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
- * (initial developer) ]
- *
- * All Rights Reserved.
- *
- * For minor contributions see the git repository.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
- * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
- * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
- * instead of those above.
- */
-
-#ifndef INCLUDED_L10NTOOLS_SOURCE_HELPER_HXX
-#define INCLUDED_L10NTOOLS_SOURCE_HELPER_HXX
-
-#include "sal/config.h"
-
-#include <algorithm>
-#include <cassert>
-
-#include <libxml/parser.h>
-
-#include "rtl/string.hxx"
-#include "rtl/ustring.hxx"
-#include "rtl/strbuf.hxx"
-#include "sal/types.h"
-
-namespace helper {
-
-// cf. comphelper::string::isdigitAsciiString:
-inline bool isAllAsciiDigits(rtl::OString const & text) {
- for (sal_Int32 i = 0; i != text.getLength(); ++i) {
- if (text[i] < '0' || text[i] > '9') {
- return false;
- }
- }
- return true;
-}
-
-// cf. comphelper::string::isupperAsciiString:
-inline bool isAllAsciiUpperCase(rtl::OString const & text) {
- for (sal_Int32 i = 0; i != text.getLength(); ++i) {
- if (text[i] < 'A' || text[i] > 'Z') {
- return false;
- }
- }
- return true;
-}
-
-// cf. comphelper::string::islowerAsciiString:
-inline bool isAllAsciiLowerCase(rtl::OString const & text) {
- for (sal_Int32 i = 0; i != text.getLength(); ++i) {
- if (text[i] < 'a' || text[i] > 'z') {
- return false;
- }
- }
- return true;
-}
-
-inline sal_Int32 countOccurrences(rtl::OString const & text, char c) {
- sal_Int32 n = 0;
- for (sal_Int32 i = 0;; ++i) {
- i = text.indexOf(c, i);
- if (i == -1) {
- break;
- }
- ++n;
- }
- return n;
-}
-
-inline sal_Int32 indexOfAnyAsciiL(
- rtl::OUString const & text, char const * chars, sal_Int32 charsLen,
- sal_Int32 index = 0)
-{
- for (; index != text.getLength(); ++index) {
- sal_Unicode c = text[index];
- if (c <= 0x7F
- && (rtl_str_indexOfChar_WithLength(
- chars, charsLen, static_cast< char >(c))
- != -1))
- {
- return index;
- }
- }
- return -1;
-}
-
-rtl::OString QuotHTML(const rtl::OString &rString)
-{
- rtl::OStringBuffer sReturn;
- for (sal_Int32 i = 0; i < rString.getLength(); ++i) {
- switch (rString[i]) {
- case '\\':
- if (i < rString.getLength()) {
- switch (rString[i + 1]) {
- case '"':
- case '<':
- case '>':
- case '\\':
- ++i;
- break;
- }
- }
- // fall through
- default:
- sReturn.append(rString[i]);
- break;
-
- case '<':
- sReturn.append("&lt;");
- break;
-
- case '>':
- sReturn.append("&gt;");
- break;
-
- case '"':
- sReturn.append("&quot;");
- break;
-
- case '&':
- if (rString.matchL(RTL_CONSTASCII_STRINGPARAM("&amp;"), i))
- sReturn.append('&');
- else
- sReturn.append(RTL_CONSTASCII_STRINGPARAM("&amp;"));
- break;
- }
- }
- return sReturn.makeStringAndClear();
-}
-
-inline bool isWellFormedXML( OString const & text )
-{
- xmlDocPtr doc;
- OString content;
- bool result = true;
-
- content = "<root>";
- content += text;
- content += "</root>";
- doc = xmlParseMemory(content.getStr(),(int)content.getLength());
- if (doc == NULL) {
- result = false;
- }
- xmlFreeDoc(doc);
- xmlCleanupParser();
- return result;
-}
-
-
-template< typename T > inline T abbreviate(
- T const & text, sal_Int32 start, sal_Int32 length)
-{
- start = std::max(sal_Int32(0), start);
- assert(start <= text.getLength());
- return text.copy(start, std::min(text.getLength() - start, length));
-}
-
-}
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/helpex.cxx b/l10ntools/source/helpex.cxx
index 5d46262d80b4..35aec5e3b8d9 100644
--- a/l10ntools/source/helpex.cxx
+++ b/l10ntools/source/helpex.cxx
@@ -30,6 +30,7 @@
#include "sal/main.h"
#include "helpmerge.hxx"
+#include "common.hxx"
#ifndef TESTDRIVER
@@ -60,8 +61,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
}
}
- HandledArgs aArgs;
- if ( !Export::handleArguments( argc, argv, aArgs) )
+ common::HandledArgs aArgs;
+ if ( !common::handleArguments( argc, argv, aArgs) )
{
WriteUsage();
return 1;
diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx
index ddcece2b492c..60ae8ed21962 100644
--- a/l10ntools/source/helpmerge.cxx
+++ b/l10ntools/source/helpmerge.cxx
@@ -40,6 +40,7 @@
#include <direct.h>
#endif
+#include "export.hxx"
#include "common.hxx"
#include "helper.hxx"
#include "po.hxx"
@@ -135,7 +136,7 @@ bool HelpParser::CreatePO(
replaceAll("\n",OString()).
replaceAll("\t",OString()).trim());
- Export::writePoEntry(
+ common::writePoEntry(
"Helpex", aPoOutput, sHelpFile, rGsi1,
posm->first, pXMLElement->GetOldref(), OString(), data);
diff --git a/l10ntools/source/lngex.cxx b/l10ntools/source/lngex.cxx
index 0677e8a2172a..957ebd4645a9 100644
--- a/l10ntools/source/lngex.cxx
+++ b/l10ntools/source/lngex.cxx
@@ -27,10 +27,10 @@
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
- HandledArgs aArgs;
- if ( !Export::handleArguments(argc, argv, aArgs) )
+ common::HandledArgs aArgs;
+ if ( !common::handleArguments(argc, argv, aArgs) )
{
- Export::writeUsage("ulfex","*.ulf");
+ common::writeUsage("ulfex","*.ulf");
return 1;
}
diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx
index 8586a8a84914..052f9705ab1e 100644
--- a/l10ntools/source/lngmerge.cxx
+++ b/l10ntools/source/lngmerge.cxx
@@ -24,7 +24,7 @@
#include <iterator>
#include <string>
-#include "common.hxx"
+#include "po.hxx"
#include "lngmerge.hxx"
namespace {
@@ -33,6 +33,15 @@ rtl::OString getBracketedContent(rtl::OString text) {
return text.getToken(1, '[').getToken(0, ']');
}
+static void lcl_RemoveUTF8ByteOrderMarker( OString &rString )
+{
+ if( rString.getLength() >= 3 && rString[0] == '\xEF' &&
+ rString[1] == '\xBB' && rString[2] == '\xBF' )
+ {
+ rString = rString.copy(3);
+ }
+}
+
}
//
@@ -59,7 +68,7 @@ LngParser::LngParser(const rtl::OString &rLngFile,
if( bFirstLine )
{
// Always remove UTF8 BOM from the first line
- Export::RemoveUTF8ByteOrderMarker( sLine );
+ lcl_RemoveUTF8ByteOrderMarker( sLine );
bFirstLine = false;
}
@@ -129,7 +138,7 @@ void LngParser::WritePO(PoOfstream &aPOStream,
if ( sAct.isEmpty() && !sCur.isEmpty() )
sAct = rText_inout[ rtl::OString("en-US") ];
- Export::writePoEntry(
+ common::writePoEntry(
"Ulfex", aPOStream, rActFileName, "LngText",
rID, OString(), OString(), sAct);
}
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index 34f590c4bccf..46c7828d969c 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -60,6 +60,108 @@ namespace
}
//
+// class ResData
+//
+
+ResData::ResData(const rtl::OString &rPF, const rtl::OString &rGId)
+ :
+ nWidth( 0 ),
+ nChildIndex( 0 ),
+ nIdLevel( ID_LEVEL_NULL ),
+ bChild( sal_False ),
+ bChildWithText( sal_False ),
+ bText( sal_False ),
+ bHelpText( sal_False ),
+ bQuickHelpText( sal_False ),
+ bTitle( sal_False ),
+ bList( sal_False ),
+ bRestMerged( sal_False ),
+ sGId( rGId ),
+ nTextRefId( REFID_NONE ),
+ nHelpTextRefId( REFID_NONE ),
+ nQuickHelpTextRefId( REFID_NONE ),
+ nTitleRefId( REFID_NONE ),
+ sTextTyp( "Text" ),
+ pStringList( NULL ),
+ pUIEntries( NULL ),
+ pItemList( NULL ),
+ pFilterList( NULL ),
+ pPairedList( NULL ),
+ sPForm( rPF )
+{
+ sGId = sGId.replaceAll("\r", rtl::OString());
+ sPForm = sPForm.replaceAll("\r", rtl::OString());
+}
+
+ResData::ResData(const rtl::OString &rPF, const rtl::OString &rGId , const rtl::OString &rFilename)
+ :
+ nWidth( 0 ),
+ nChildIndex( 0 ),
+ nIdLevel( ID_LEVEL_NULL ),
+ bChild( sal_False ),
+ bChildWithText( sal_False ),
+ bText( sal_False ),
+ bHelpText( sal_False ),
+ bQuickHelpText( sal_False ),
+ bTitle( sal_False ),
+ bList( sal_False ),
+ bRestMerged( sal_False ),
+ sGId( rGId ),
+ sFilename( rFilename ),
+ nTextRefId( REFID_NONE ),
+ nHelpTextRefId( REFID_NONE ),
+ nQuickHelpTextRefId( REFID_NONE ),
+ nTitleRefId( REFID_NONE ),
+ sTextTyp( "Text" ),
+ pStringList( NULL ),
+ pUIEntries( NULL ),
+ pItemList( NULL ),
+ pFilterList( NULL ),
+ pPairedList( NULL ),
+ sPForm( rPF )
+{
+ sGId = sGId.replaceAll("\r", rtl::OString());
+ sPForm = sPForm.replaceAll("\r", rtl::OString());
+}
+
+
+ResData::~ResData()
+{
+ if ( pStringList ) {
+ // delete existing res. of type StringList
+ for ( size_t i = 0; i < pStringList->size(); i++ ) {
+ ExportListEntry* test = (*pStringList)[ i ];
+ if( test != NULL ) delete test;
+ }
+ delete pStringList;
+ }
+ if ( pFilterList ) {
+ // delete existing res. of type FilterList
+ for ( size_t i = 0; i < pFilterList->size(); i++ ) {
+ ExportListEntry* test = (*pFilterList)[ i ];
+ delete test;
+ }
+ delete pFilterList;
+ }
+ if ( pItemList ) {
+ // delete existing res. of type ItemList
+ for ( size_t i = 0; i < pItemList->size(); i++ ) {
+ ExportListEntry* test = (*pItemList)[ i ];
+ delete test;
+ }
+ delete pItemList;
+ }
+ if ( pUIEntries ) {
+ // delete existing res. of type UIEntries
+ for ( size_t i = 0; i < pUIEntries->size(); i++ ) {
+ ExportListEntry* test = (*pUIEntries)[ i ];
+ delete test;
+ }
+ delete pUIEntries;
+ }
+}
+
+//
// class PFormEntrys
//
diff --git a/l10ntools/source/propex.cxx b/l10ntools/source/propex.cxx
index 8517bfb3bdd4..b12f4d32d6f6 100644
--- a/l10ntools/source/propex.cxx
+++ b/l10ntools/source/propex.cxx
@@ -9,15 +9,15 @@
#include "sal/main.h"
-#include "export.hxx"
+#include "common.hxx"
#include "propmerge.hxx"
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
{
- HandledArgs aArgs;
- if( !Export::handleArguments(argc, argv, aArgs) )
+ common::HandledArgs aArgs;
+ if( !common::handleArguments(argc, argv, aArgs) )
{
- Export::writeUsage("propex","*.properties");
+ common::writeUsage("propex","*.properties");
return 1;
}
diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx
index 6f87a4efb7d4..72affe367d6d 100644
--- a/l10ntools/source/propmerge.cxx
+++ b/l10ntools/source/propmerge.cxx
@@ -144,7 +144,7 @@ void PropParser::Extract( const OString& rPOFile )
OString sID = sLine.copy( 0, nEqualSign ).trim();
OString sText = lcl_ConvertToUTF8( sLine.copy( nEqualSign + 1 ).trim() );
- Export::writePoEntry(
+ common::writePoEntry(
"Propex", aPOStream, m_sSource, "property",
sID, OString(), OString(), sText);
}
diff --git a/l10ntools/source/stringex.cxx b/l10ntools/source/stringex.cxx
index cf4a227c7a5a..1b507f82eca3 100644
--- a/l10ntools/source/stringex.cxx
+++ b/l10ntools/source/stringex.cxx
@@ -10,15 +10,15 @@
#include <iostream>
#include "sal/main.h"
-#include "export.hxx"
+#include "common.hxx"
#include "stringmerge.hxx"
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
{
- HandledArgs aArgs;
- if( !Export::handleArguments(argc, argv, aArgs) )
+ common::HandledArgs aArgs;
+ if( !common::handleArguments(argc, argv, aArgs) )
{
- Export::writeUsage("stringex","string.xml");
+ common::writeUsage("stringex","string.xml");
return 1;
}
diff --git a/l10ntools/source/stringmerge.cxx b/l10ntools/source/stringmerge.cxx
index bc7417d0721f..b81ea71f4d05 100644
--- a/l10ntools/source/stringmerge.cxx
+++ b/l10ntools/source/stringmerge.cxx
@@ -18,24 +18,11 @@
#include <libxml/xmlstring.h>
#include "export.hxx"
+#include "helper.hxx"
#include "common.hxx"
#include "po.hxx"
#include "stringmerge.hxx"
-
-namespace
-{
- //Convert xmlChar* to OString
- static OString lcl_xmlStrToOString( const xmlChar* pString )
- {
- xmlChar* pTemp = xmlStrdup( pString );
- OString sResult =
- static_cast<OString>(reinterpret_cast<sal_Char*>( pTemp ));
- xmlFree( pTemp );
- return sResult;
- }
-}
-
//Parse strings.xml file
StringParser::StringParser(
const OString& rInputFile, const OString& rLang )
@@ -84,10 +71,10 @@ void StringParser::Extract( const OString& rPOFile )
xmlChar* pID = xmlGetProp(pCurrent, (const xmlChar*)("name"));
xmlChar* pText = xmlNodeGetContent(pCurrent);
- Export::writePoEntry(
+ common::writePoEntry(
"Stringex", aPOStream, m_pSource->name, "string",
- lcl_xmlStrToOString( pID ), OString(), OString(),
- lcl_xmlStrToOString( pText ));
+ helper::xmlStrToOString( pID ), OString(), OString(),
+ helper::xmlStrToOString( pText ));
xmlFree( pID );
xmlFree( pText );
@@ -134,7 +121,7 @@ void StringParser::Merge(
{
xmlChar* pID = xmlGetProp(pCurrent, (const xmlChar*)("name"));
ResData aResData(
- "", lcl_xmlStrToOString( pID ),
+ "", helper::xmlStrToOString( pID ),
static_cast<OString>(m_pSource->name) );
xmlFree( pID );
aResData.sResTyp = "string";
diff --git a/l10ntools/source/treemerge.cxx b/l10ntools/source/treemerge.cxx
index d259efcd9d46..b340ebea170d 100644
--- a/l10ntools/source/treemerge.cxx
+++ b/l10ntools/source/treemerge.cxx
@@ -18,22 +18,14 @@
#include <libxml/xmlstring.h>
#include "export.hxx"
+#include "helper.hxx"
#include "common.hxx"
+#include "po.hxx"
#include "treemerge.hxx"
namespace
{
- //Convert xmlChar* to OString
- static OString lcl_xmlStrToOString( const xmlChar* pString )
- {
- xmlChar* pTemp = xmlStrdup( pString );
- OString sResult =
- static_cast<OString>(reinterpret_cast<sal_Char*>( pTemp ));
- xmlFree( pTemp );
- return sResult;
- }
-
//Extract strings from nodes on all level recursively
static void lcl_ExtractLevel(
const xmlDocPtr pSource, const xmlNodePtr pRoot,
@@ -52,9 +44,9 @@ namespace
xmlChar* pText =
xmlGetProp(pCurrent, (const xmlChar*)("title"));
- Export::writePoEntry(
- "Treex", rPOStream, pSource->name, lcl_xmlStrToOString( pNodeName ),
- lcl_xmlStrToOString( pID ), OString(), OString(), lcl_xmlStrToOString( pText ));
+ common::writePoEntry(
+ "Treex", rPOStream, pSource->name, helper::xmlStrToOString( pNodeName ),
+ helper::xmlStrToOString( pID ), OString(), OString(), helper::xmlStrToOString( pText ));
xmlFree( pID );
xmlFree( pText );
@@ -73,7 +65,7 @@ namespace
xmlNodePtr pReturn = pCurrent;
xmlChar* pID = xmlGetProp(pReturn, (const xmlChar*)("id"));
const OString sID =
- lcl_xmlStrToOString( pID );
+ helper::xmlStrToOString( pID );
xmlFree( pID );
const sal_Int32 nFirstSlash = sID.indexOf("/");
@@ -122,7 +114,7 @@ namespace
xmlChar* sTitle =
xmlNodeListGetString(pXhpFile, pXhpNode->children, 1);
OString sNewTitle =
- lcl_xmlStrToOString( sTitle ).
+ helper::xmlStrToOString( sTitle ).
replaceAll("$[officename]","%PRODUCTNAME").
replaceAll("$[officeversion]","%PRODUCTVERSION");
xmlNodeSetContent(
@@ -165,10 +157,10 @@ namespace
{
xmlChar* pID = xmlGetProp(pCurrent, (const xmlChar*)("id"));
ResData aResData(
- "", lcl_xmlStrToOString( pID ),
+ "", helper::xmlStrToOString( pID ),
static_cast<OString>(io_pSource->name) );
xmlFree( pID );
- aResData.sResTyp = lcl_xmlStrToOString( pNodeName );
+ aResData.sResTyp = helper::xmlStrToOString( pNodeName );
PFormEntrys* pEntrys =
pMergeDataFile->GetPFormEntrys( &aResData );
if( pEntrys )
diff --git a/l10ntools/source/treex.cxx b/l10ntools/source/treex.cxx
index 51874808b71e..7c572309b2d4 100644
--- a/l10ntools/source/treex.cxx
+++ b/l10ntools/source/treex.cxx
@@ -11,7 +11,7 @@
#include <cstring>
#include "sal/main.h"
-#include "export.hxx"
+#include "common.hxx"
#include "treemerge.hxx"
void WriteUsage()
@@ -45,8 +45,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
break;
}
}
- HandledArgs aArgs;
- if( !Export::handleArguments(argc, argv, aArgs) )
+ common::HandledArgs aArgs;
+ if( !common::handleArguments(argc, argv, aArgs) )
{
WriteUsage();
return 1;
diff --git a/l10ntools/source/uimerge.cxx b/l10ntools/source/uimerge.cxx
index 6e0ec03b33ca..76fc9ef8b400 100644
--- a/l10ntools/source/uimerge.cxx
+++ b/l10ntools/source/uimerge.cxx
@@ -21,6 +21,7 @@
#include <stdio.h>
#include "common.hxx"
+#include "helper.hxx"
#include "export.hxx"
#include "tokens.h"
#include "po.hxx"
@@ -31,19 +32,6 @@
rtl::OString sInputFileName;
rtl::OString sOutputFile;
-namespace
-{
- //Convert xmlChar* to OString
- static OString lcl_xmlStrToOString( const xmlChar* pString )
- {
- xmlChar* pTemp = xmlStrdup( pString );
- OString sResult =
- static_cast<OString>(reinterpret_cast<sal_Char*>( pTemp ));
- xmlFree( pTemp );
- return sResult;
- }
-}
-
int extractTranslations()
{
PoOfstream aPOStream( sOutputFile, PoOfstream::APP);
@@ -73,11 +61,11 @@ int extractTranslations()
for(xmlAttrPtr attribute = nodeLevel2->properties; attribute != NULL; attribute = attribute->next)
{
xmlChar *content = xmlNodeListGetString(res, attribute->children, 1);
- vIDs.push_back(lcl_xmlStrToOString(content));
+ vIDs.push_back(helper::xmlStrToOString(content));
xmlFree(content);
}
- OString sText = lcl_xmlStrToOString(xmlNodeGetContent(nodeLevel2));
- Export::writePoEntry(
+ OString sText = helper::xmlStrToOString(xmlNodeGetContent(nodeLevel2));
+ common::writePoEntry(
"Uiex", aPOStream, sInputFileName, vIDs[0],
(vIDs.size()>=2) ? vIDs[1] : OString(),
(vIDs.size()>=3) ? vIDs[2] : OString(),
@@ -99,50 +87,6 @@ int extractTranslations()
namespace
{
- rtl::OString QuotHTML(const rtl::OString &rString)
- {
- rtl::OStringBuffer sReturn;
- for (sal_Int32 i = 0; i < rString.getLength(); ++i) {
- switch (rString[i]) {
- case '\\':
- if (i < rString.getLength()) {
- switch (rString[i + 1]) {
- case '"':
- case '<':
- case '>':
- case '\\':
- ++i;
- break;
- }
- }
- // fall through
- default:
- sReturn.append(rString[i]);
- break;
-
- case '<':
- sReturn.append("&lt;");
- break;
-
- case '>':
- sReturn.append("&gt;");
- break;
-
- case '"':
- sReturn.append("&quot;");
- break;
-
- case '&':
- if (rString.matchL(RTL_CONSTASCII_STRINGPARAM("&amp;"), i))
- sReturn.append('&');
- else
- sReturn.append(RTL_CONSTASCII_STRINGPARAM("&amp;"));
- break;
- }
- }
- return sReturn.makeStringAndClear();
- }
-
bool lcl_MergeLang(
const MergeDataHashMap &rMap,
const rtl::OString &rLanguage,
@@ -172,7 +116,7 @@ namespace
aDestination << " <e "
<< "g=\"" << aI->second->sGID.getStr() << "\" "
<< "i=\"" << aI->second->sLID.getStr() << "\">"
- << QuotHTML(sOut).getStr() << "</e>\n";
+ << helper::QuotHTML(sOut).getStr() << "</e>\n";
}
aDestination << "</t>";
@@ -240,10 +184,10 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
{
int nRetValue = 0;
- HandledArgs aArgs;
- if ( !Export::handleArguments(argc, argv, aArgs) )
+ common::HandledArgs aArgs;
+ if ( !common::handleArguments(argc, argv, aArgs) )
{
- Export::writeUsage("uiex","*.ui");
+ common::writeUsage("uiex","*.ui");
return 1;
}
diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx
index f91cc1eb7c26..8ba715d48f62 100644
--- a/l10ntools/source/xmlparse.cxx
+++ b/l10ntools/source/xmlparse.cxx
@@ -16,7 +16,6 @@
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-
#include "sal/config.h"
#include <iterator> /* std::iterator*/
@@ -24,12 +23,14 @@
#include <stdio.h>
#include <sal/alloca.h>
+#include "helper.hxx"
#include "common.hxx"
#include "xmlparse.hxx"
#include <fstream>
#include <iostream>
#include <osl/mutex.hxx>
#include <osl/thread.hxx>
+#include <osl/process.h>
#include <rtl/strbuf.hxx>
using namespace std;
@@ -868,6 +869,32 @@ XMLDefault& XMLDefault::operator=(const XMLDefault& obj){
#define XML_CHAR_TO_OUSTRING(x) OStringToOUString(OString(x), RTL_TEXTENCODING_UTF8)
#define XML_CHAR_N_TO_OUSTRING(x,n) OStringToOUString(OString(x,n), RTL_TEXTENCODING_UTF8 )
+namespace
+{
+
+static OUString lcl_pathnameToAbsoluteUrl(const OUString& rPathname) {
+ OUString sUrl;
+ if (osl::FileBase::getFileURLFromSystemPath(rPathname, sUrl)
+ != osl::FileBase::E_None)
+ {
+ std::cerr << "Error: Cannot convert input pathname to URL\n";
+ std::exit(EXIT_FAILURE);
+ }
+ OUString sCwd;
+ if (osl_getProcessWorkingDir(&sCwd.pData) != osl_Process_E_None) {
+ std::cerr << "Error: Cannot determine cwd\n";
+ std::exit(EXIT_FAILURE);
+ }
+ if (osl::FileBase::getAbsoluteFileURL(sCwd, sUrl, sUrl)
+ != osl::FileBase::E_None)
+ {
+ std::cerr << "Error: Cannot convert input URL to absolute URL\n";
+ std::exit(EXIT_FAILURE);
+ }
+ return sUrl;
+}
+}
+
/*****************************************************************************/
SimpleXMLParser::SimpleXMLParser()
@@ -1008,7 +1035,7 @@ XMLFile *SimpleXMLParser::Execute( const rtl::OUString &rFileName, XMLFile* pXML
aErrorInformation.sMessage = rtl::OUString( "ERROR: Unable to open file ");
aErrorInformation.sMessage += rFileName;
- rtl::OUString aFileURL(common::pathnameToAbsoluteUrl(rFileName));
+ rtl::OUString aFileURL(lcl_pathnameToAbsoluteUrl(rFileName));
oslFileHandle h;
if (osl_openFile(aFileURL.pData, &h, osl_File_OpenFlag_Read)
@@ -1145,50 +1172,11 @@ XMLFile *SimpleXMLParser::Execute( const rtl::OUString &rFileName, XMLFile* pXML
return pXMLFile;
}
-/*****************************************************************************/
-void XMLUtil::QuotHTML( rtl::OUString &rString )
-/*****************************************************************************/
-{
- OUStringBuffer sReturn;
- for (sal_Int32 i = 0; i < rString.getLength(); ++i) {
- switch (rString[i]) {
- case '\\':
- if (i < rString.getLength()) {
- switch (rString[i + 1]) {
- case '"':
- case '<':
- case '>':
- case '\\':
- ++i;
- break;
- }
- }
- // fall through
- default:
- sReturn.append(rString[i]);
- break;
-
- case '<':
- sReturn.appendAscii(RTL_CONSTASCII_STRINGPARAM("&lt;"));
- break;
- case '>':
- sReturn.appendAscii(RTL_CONSTASCII_STRINGPARAM("&gt;"));
- break;
-
- case '"':
- sReturn.appendAscii(RTL_CONSTASCII_STRINGPARAM("&quot;"));
- break;
-
- case '&':
- if (rString.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("&amp;"), i))
- sReturn.append('&');
- else
- sReturn.appendAscii(RTL_CONSTASCII_STRINGPARAM("&amp;"));
- break;
- }
- }
- rString = sReturn.makeStringAndClear();
+void XMLUtil::QuotHTML( OUString &rString )
+{
+ const OString sString(OUStringToOString(rString, RTL_TEXTENCODING_UTF8));
+ rString = OStringToOUString(helper::QuotHTML( sString ), RTL_TEXTENCODING_UTF8);
}
void XMLUtil::UnQuotHTML( rtl::OUString &rString ){
diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx
index ed0896e038be..d531db496ca1 100644
--- a/l10ntools/source/xrmmerge.cxx
+++ b/l10ntools/source/xrmmerge.cxx
@@ -25,6 +25,7 @@
#include "common.hxx"
#include "export.hxx"
+#include "po.hxx"
#include "xrmmerge.hxx"
#include "tokens.h"
#include "helper.hxx"
@@ -59,8 +60,8 @@ extern char *GetOutputFile( int argc, char* argv[])
bDisplayName = sal_False;
bExtensionDescription = sal_False;
- HandledArgs aArgs;
- if ( Export::handleArguments(argc, argv, aArgs) )
+ common::HandledArgs aArgs;
+ if ( common::handleArguments(argc, argv, aArgs) )
{
// command line is valid
bMergeMode = aArgs.m_bMergeMode;
@@ -75,7 +76,7 @@ extern char *GetOutputFile( int argc, char* argv[])
else
{
// command line is not valid
- Export::writeUsage("xrmex","*.xrm/*.xml");
+ common::writeUsage("xrmex","*.xrm/*.xml");
return NULL;
}
}
@@ -421,7 +422,7 @@ void XRMResExport::EndOfText(
pResData->sText[sCur].replaceAll("\x0A", rtl::OString()));
if( !sAct.isEmpty() )
- Export::writePoEntry(
+ common::writePoEntry(
"Xrmex", pOutputStream, sPath, sResourceType,
pResData->sGId, OString(), OString(), sAct );
}
@@ -565,7 +566,7 @@ void XRMResMerge::WorkOnText(
PFormEntrys *pEntrys = pMergeDataFile->GetPFormEntrys( pResData );
if ( pEntrys ) {
rtl::OString sContent;
- if ( Export::isAllowed( sLang ) &&
+ if ( !sLang.equalsIgnoreAsciiCase("en-US") &&
( pEntrys->GetText(
sContent, STRING_TYP_TEXT, sLang )) &&
( sContent != "-" ) && !sContent.isEmpty() &&