summaryrefslogtreecommitdiff
path: root/l10ntools/source
diff options
context:
space:
mode:
authorZolnai Tamás <zolnaitamas2000@gmail.com>2013-04-13 05:43:53 +0200
committerZolnai Tamás <zolnaitamas2000@gmail.com>2013-04-13 05:44:02 +0200
commitd885a85a48a4706934e170b7a6671e5e029089a0 (patch)
tree03d6dd088d97ce10a5bed62c565078df8d6a264c /l10ntools/source
parentedc3bfd558f3065a5444ad3f5c456da9546d16c4 (diff)
Make l10ntools executables escape clear
Steps of escaping process: 1. Executables unescape the string for export(if necessary) 2. Po class work with unescaped string 3. Escape strings to PO format and write out 4. Read from PO and unescape strings 5. Executables make own transformation on string and merge Use general functions for escaping (helper) Delete unneeded escaping methods(xrmmerge, merge) Delete some unused method from PoEntry class Change-Id: I7f9414581aae9e6de7d1573862a32cdbd68c9545
Diffstat (limited to 'l10ntools/source')
-rw-r--r--l10ntools/source/export.cxx85
-rw-r--r--l10ntools/source/helper.cxx43
-rw-r--r--l10ntools/source/merge.cxx14
-rwxr-xr-xl10ntools/source/po.cxx100
-rw-r--r--l10ntools/source/stringmerge.cxx7
-rw-r--r--l10ntools/source/xrmmerge.cxx29
6 files changed, 90 insertions, 188 deletions
diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx
index d5ee143954e8..a61cf135335a 100644
--- a/l10ntools/source/export.cxx
+++ b/l10ntools/source/export.cxx
@@ -22,6 +22,7 @@
#include <cstddef>
#include <cstring>
+#include "helper.hxx"
#include "boost/scoped_ptr.hpp"
#include <stdio.h>
#include <stdlib.h>
@@ -954,6 +955,11 @@ sal_Bool Export::WriteData( ResData *pResData, sal_Bool bCreateNew )
if (sXText.isEmpty())
sXText = "-";
+ ConvertExportContent(sXText);
+ ConvertExportContent(sXHText);
+ ConvertExportContent(sXQHText);
+ ConvertExportContent(sXTitle);
+
common::writePoEntry(
"Transex3", *aOutput.mPo, global::inputPathname,
pResData->sResTyp, sGID, sLID, sXHText, sXText);
@@ -1070,6 +1076,7 @@ sal_Bool Export::WriteExportList(ResData *pResData, ExportList *pExportList,
if( sText == "\\\"" )
sText = "\"";
}
+ ConvertExportContent(sText);
common::writePoEntry(
"Transex3", *aOutput.mPo, global::inputPathname,
rTyp, sGID, sLID, OString(), sText);
@@ -1316,68 +1323,28 @@ void Export::ConvertMergeContent( OString &rText )
/*****************************************************************************/
{
sal_Bool bNoOpen = ( rText.indexOf( "\\\"" ) != 0 );
- sal_Bool bNoClose = !rText.endsWithL(RTL_CONSTASCII_STRINGPARAM("\\\""));
- OStringBuffer sNew;
- for ( sal_Int32 i = 0; i < rText.getLength(); i++ )
- {
- OString sChar( rText[i]);
- if (sChar.equalsL(RTL_CONSTASCII_STRINGPARAM("\\")))
- {
- if (( i + 1 ) < rText.getLength())
- {
- sal_Char cNext = rText[i + 1];
- if ( cNext == '\"' )
- {
- sChar = OString('\"');
- i++;
- }
- else if ( cNext == 'n' )
- {
- sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\n"));
- i++;
- }
- else if ( cNext == 't' )
- {
- sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\t"));
- i++;
- }
- else if ( cNext == '\'' )
- {
- sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\\'"));
- i++;
- }
- else
- {
- sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\\\"));
- }
- }
- else
- {
- sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\\\"));
- }
- }
- else if (sChar.equalsL(RTL_CONSTASCII_STRINGPARAM("\"")))
- {
- sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\\""));
- }
- else if (sChar.equalsL(RTL_CONSTASCII_STRINGPARAM("")))
- {
- sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\0x7F"));
- }
- sNew.append(sChar);
- }
+ sal_Bool bNoClose = !rText.endsWith("\\\"");
- rText = sNew.makeStringAndClear();
- if ( bNoOpen ) {
- OString sTmp( rText );
- rText = "\"";
- rText += sTmp;
- }
+ rText = rText.replaceAll("\\\"'","\'"); /// Temporary: until PO files contain escaped single quotes
+ /// (Maybe next PO update solve this)
+ rText =
+ helper::escapeAll(
+ rText.replaceAll("","\\0x7F"),
+ "\n""\t""\\""\"","\\n""\\t""\\\\""\\\"");
+
+ if ( bNoOpen )
+ rText = "\"" + rText;
+
if ( bNoClose )
rText += "\"";
}
+void Export::ConvertExportContent( OString& rText )
+{
+ rText = helper::unEscapeAll(rText,"\\n""\\t""\\\\""\\\"","\n""\t""\\""\"");
+}
+
sal_Bool Export::PrepareTextToMerge(OString &rText, sal_uInt16 nTyp,
OString &rLangIndex, ResData *pResData)
{
@@ -1539,7 +1506,7 @@ sal_Bool Export::PrepareTextToMerge(OString &rText, sal_uInt16 nTyp,
}
OString sContent;
- pEntrys->GetTransex3Text(sContent, nTyp, rLangIndex);
+ pEntrys->GetText(sContent, nTyp, rLangIndex);
if (sContent.isEmpty() && !rLangIndex.equalsIgnoreAsciiCase("en-US"))
{
rText = sOrigText;
@@ -1573,7 +1540,7 @@ void Export::ResData2Output( PFormEntrys *pEntry, sal_uInt16 nType, const OStrin
sCur = aLanguages[ n ];
OString sText;
- sal_Bool bText = pEntry->GetTransex3Text( sText, nType, sCur , sal_True );
+ sal_Bool bText = pEntry->GetText( sText, nType, sCur , sal_True );
if ( bText && !sText.isEmpty() && sText != "-" ) {
OString sOutput;
if ( bNextMustBeDefineEOL) {
@@ -1772,7 +1739,7 @@ void Export::MergeRest( ResData *pResData, sal_uInt16 nMode )
OString sText;
sal_Bool bText = false;
if ( pEntrys )
- bText = pEntrys->GetTransex3Text( sText, STRING_TYP_TEXT, sCur, sal_True );
+ bText = pEntrys->GetText( sText, STRING_TYP_TEXT, sCur, sal_True );
if ( bText && !sText.isEmpty() )
{
sal_Int32 nStart, nEnd;
diff --git a/l10ntools/source/helper.cxx b/l10ntools/source/helper.cxx
index 69163d0e38ae..6c3a04559078 100644
--- a/l10ntools/source/helper.cxx
+++ b/l10ntools/source/helper.cxx
@@ -11,6 +11,49 @@
namespace helper {
+OString escapeAll(
+ const OString& rText, const OString& rUnEscaped, const OString& rEscaped )
+{
+ assert( rEscaped.getLength() == 2*rUnEscaped.getLength() );
+ OStringBuffer sReturn;
+ for ( sal_Int32 nIndex = 0; nIndex < rText.getLength(); ++nIndex )
+ {
+ sal_Int32 nUnEscapedOne = rUnEscaped.indexOf(rText[nIndex]);
+ if( nUnEscapedOne != -1 )
+ {
+ sReturn.append(rEscaped.copy(nUnEscapedOne*2,2));
+ }
+ else
+ sReturn.append(rText[nIndex]);
+ }
+ return sReturn.makeStringAndClear();
+}
+
+
+OString unEscapeAll(
+ const OString& rText, const OString& rEscaped, const OString& rUnEscaped)
+{
+ assert( rEscaped.getLength() == 2*rUnEscaped.getLength() );
+ OStringBuffer sReturn;
+ const sal_Int32 nLength = rText.getLength();
+ for ( sal_Int32 nIndex = 0; nIndex < nLength; ++nIndex )
+ {
+ if( rText[nIndex] == '\\' && nIndex+1 < nLength )
+ {
+ sal_Int32 nEscapedOne = rEscaped.indexOf(rText.copy(nIndex,2));
+ if( nEscapedOne != -1 )
+ {
+ sReturn.append(rUnEscaped[nEscapedOne/2]);
+ ++nIndex;
+ }
+ }
+ else
+ sReturn.append(rText[nIndex]);
+ }
+ return sReturn.makeStringAndClear();
+}
+
+
OString QuotHTML(const OString &rString)
{
OStringBuffer sReturn;
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index d3bd71b04196..3487030b52a9 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -165,20 +165,6 @@ ResData::~ResData()
// class PFormEntrys
//
-sal_Bool PFormEntrys::GetTransex3Text( OString &rReturn,
- sal_uInt16 nTyp, const OString &nLangIndex, sal_Bool bDel )
-{
- sal_Bool rc = GetText( rReturn , nTyp , nLangIndex , bDel );
- for( sal_Int32 idx = 0; idx < rReturn.getLength(); idx++ )
- {
- if( rReturn[idx] == '\"' && ( idx >= 1 ) && rReturn[idx-1] == '\\' )
- {
- rReturn = rReturn.replaceAt( idx-1, 1, OString() );
- }
- }
- return rc;
-}
-/*****************************************************************************/
sal_Bool PFormEntrys::GetText( OString &rReturn,
sal_uInt16 nTyp, const OString &nLangIndex, sal_Bool bDel )
{
diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx
index bbfe0633bab6..34f3eeb10de7 100755
--- a/l10ntools/source/po.cxx
+++ b/l10ntools/source/po.cxx
@@ -19,9 +19,7 @@
#include <boost/crc.hpp>
#include "po.hxx"
-
-#define POESCAPED OString("\\n\\t\\r\\\\\\\"")
-#define POUNESCAPED OString("\n\t\r\\\"")
+#include "helper.hxx"
/** Container of po entry
@@ -85,49 +83,16 @@ public:
namespace
{
- //Escape text
- static OString lcl_EscapeText(const OString& rText,
- const OString& rUnEscaped= POUNESCAPED,
- const OString& rEscaped = POESCAPED)
- {
- assert( rEscaped.getLength() == 2*rUnEscaped.getLength() );
- OString sResult = rText;
- int nCount = 0;
- for(sal_Int32 nIndex=0; nIndex<rText.getLength(); ++nIndex)
- {
- sal_Int32 nActChar = rUnEscaped.indexOf(rText[nIndex]);
- if(nActChar!=-1)
- sResult = sResult.replaceAt((nIndex)+(nCount++),1,
- rEscaped.copy(2*nActChar,2));
- }
- return sResult;
- }
-
- //Unescape text
- static OString lcl_UnEscapeText(const OString& rText,
- const OString& rEscaped = POESCAPED,
- const OString& rUnEscaped = POUNESCAPED)
- {
- assert( rEscaped.getLength() == 2*rUnEscaped.getLength() );
- OString sResult = rText;
- int nCount = 0;
- for(sal_Int32 nIndex=0; nIndex<rText.getLength()-1; ++nIndex)
- {
- sal_Int32 nActChar = rEscaped.indexOf(rText.copy(nIndex,2));
- if(nActChar % 2 == 0)
- sResult = sResult.replaceAt((nIndex++)-(nCount++),2,
- rUnEscaped.copy(nActChar/2,1));
- }
- return sResult;
- }
-
//Convert a normal string to msg/po output string
static OString lcl_GenMsgString(const OString& rString)
{
if ( rString.isEmpty() )
return "\"\"";
- OString sResult = "\"" + lcl_EscapeText(rString) + "\"";
+ OString sResult =
+ "\"" +
+ helper::escapeAll(rString,"\n""\t""\r""\\""\"","\\n""\\t""\\r""\\\\""\\\"") +
+ "\"";
sal_Int32 nIndex = 0;
while((nIndex=sResult.indexOf("\\n",nIndex))!=-1)
{
@@ -148,7 +113,11 @@ namespace
//Convert msg string to normal form
static OString lcl_GenNormString(const OString& rString)
{
- return lcl_UnEscapeText(rString.copy(1,rString.getLength()-2));
+ return
+ helper::unEscapeAll(
+ rString.copy(1,rString.getLength()-2),
+ "\\n""\\t""\\r""\\\\""\\\"",
+ "\n""\t""\r""\\""\"");
}
}
@@ -273,26 +242,6 @@ namespace
sKeyId[5] = '\0';
return OString(sKeyId);
}
-
- //Unescape merge string
- static OString lcl_UnEscapeMergeText(
- const OString& rText,const bool bHelpText = false )
- {
- if ( bHelpText )
- return rText;
- else
- return lcl_UnEscapeText(rText,"\\n\\t\\r","\n\t\r");
- }
-
- //Escape to get merge string
- static OString lcl_EscapeMergeText(
- const OString& rText,const bool bHelpText = false )
- {
- if ( bHelpText )
- return rText;
- else
- return lcl_EscapeText(rText,"\n\t\r","\\n\\t\\r");
- }
}
//Default constructor
@@ -338,15 +287,12 @@ PoEntry::PoEntry(
only three element*/
}
m_pGenPo->setMsgCtxt(sMsgCtxt);
- m_pGenPo->setMsgId(
- lcl_UnEscapeMergeText(
- rText,rSourceFile.endsWith(".xhp")));
+ m_pGenPo->setMsgId(rText);
m_pGenPo->setExtractCom(
( !rHelpText.isEmpty() ? rHelpText + "\n" : OString( "" )) +
lcl_GenKeyId(
m_pGenPo->getReference() + sMsgCtxt + m_pGenPo->getMsgId() ) );
m_bIsInitialized = true;
-
}
//Destructor
@@ -468,35 +414,15 @@ OString PoEntry::getKeyId() const
OString PoEntry::getMsgId() const
{
assert( m_bIsInitialized );
- return
- lcl_EscapeMergeText(
- m_pGenPo->getMsgId(), getSourceFile().endsWith(".xhp") );
+ return m_pGenPo->getMsgId();
}
//Get translated string in merge format
OString PoEntry::getMsgStr() const
{
assert( m_bIsInitialized );
- return
- lcl_EscapeMergeText(
- m_pGenPo->getMsgStr(), getSourceFile().endsWith(".xhp") );
-
-}
+ return m_pGenPo->getMsgStr();
-//Set translated string when input is in merge format
-void PoEntry::setMsgStr(const OString& rMsgStr)
-{
- assert( m_bIsInitialized );
- m_pGenPo->setMsgStr(
- lcl_UnEscapeMergeText(
- rMsgStr,getSourceFile().endsWith(".xhp")));
-}
-
-//Set fuzzy flag
-void PoEntry::setFuzzy(const bool bFuzzy)
-{
- assert( m_bIsInitialized );
- m_pGenPo->setFuzzy(bFuzzy);
}
//Check whether po-s belong to the same localization component
diff --git a/l10ntools/source/stringmerge.cxx b/l10ntools/source/stringmerge.cxx
index b81ea71f4d05..bc2057aae1ab 100644
--- a/l10ntools/source/stringmerge.cxx
+++ b/l10ntools/source/stringmerge.cxx
@@ -70,11 +70,12 @@ void StringParser::Extract( const OString& rPOFile )
{
xmlChar* pID = xmlGetProp(pCurrent, (const xmlChar*)("name"));
xmlChar* pText = xmlNodeGetContent(pCurrent);
-
+ const OString sTemp =
+ helper::unEscapeAll(helper::xmlStrToOString( pText ),"\\n""\\t","\n""\t");
common::writePoEntry(
"Stringex", aPOStream, m_pSource->name, "string",
helper::xmlStrToOString( pID ), OString(), OString(),
- helper::xmlStrToOString( pText ));
+ sTemp);
xmlFree( pID );
xmlFree( pText );
@@ -131,7 +132,7 @@ void StringParser::Merge(
{
OString sNewText;
pEntrys->GetText( sNewText, STRING_TYP_TEXT, m_sLang );
- sNewText = sNewText.replaceAll("\'","\\\'").replaceAll("\"","\\\"");
+ sNewText = helper::escapeAll(sNewText, "\n""\t""\'""\"","\\n""\\t""\\\'""\\\"");
xmlNodeSetContent(
pCurrent,
xmlEncodeSpecialChars( NULL,
diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx
index 04fccfbf9484..458beacc5f28 100644
--- a/l10ntools/source/xrmmerge.cxx
+++ b/l10ntools/source/xrmmerge.cxx
@@ -313,20 +313,6 @@ void XRMResParser::Error( const OString &rError )
yyerror(( char * ) rError.getStr());
}
-/*****************************************************************************/
-void XRMResParser::ConvertStringToDBFormat( OString &rString )
-/*****************************************************************************/
-{
- rString = rString.trim().replaceAll("\t", "\\t");
-}
-
-/*****************************************************************************/
-void XRMResParser::ConvertStringToXMLFormat( OString &rString )
-/*****************************************************************************/
-{
- rString = rString.replaceAll("\\t", "\t");
-}
-
//
// class XMLResExport
//
@@ -377,7 +363,7 @@ void XRMResExport::WorkOnDesc(
file.read (memblock, size);
file.close();
memblock[size] = '\0';
- rText = OString(memblock).replaceAll("\n", "\\n");
+ rText = OString(memblock);
delete[] memblock;
}
WorkOnText( rOpenTag, rText );
@@ -395,13 +381,9 @@ void XRMResExport::WorkOnText(
if ( !pResData )
{
- OString sPlatform( "" );
- pResData = new ResData( sPlatform, GetGID() );
+ pResData = new ResData( OString(), GetGID() );
}
-
- OString sText(rText);
- ConvertStringToDBFormat(sText);
- pResData->sText[sLang] = sText;
+ pResData->sText[sLang] = rText;
}
/*****************************************************************************/
@@ -418,8 +400,7 @@ void XRMResExport::EndOfText(
{
sCur = aLanguages[ n ];
- OString sAct(
- pResData->sText[sCur].replaceAll("\x0A", OString()));
+ OString sAct = pResData->sText[sCur];
if( !sAct.isEmpty() )
common::writePoEntry(
@@ -528,7 +509,6 @@ void XRMResMerge::WorkOnDesc(
}
OString sOutputDescFile(
sOutputFile.copy(0, i + 1) + sLocDescFilename);
- sText = sText.replaceAll("\\n", "\n");
ofstream file(sOutputDescFile.getStr());
if (file.is_open()) {
file << sText.getStr();
@@ -573,7 +553,6 @@ void XRMResMerge::WorkOnText(
helper::isWellFormedXML( sContent ))
{
rText = sContent;
- ConvertStringToXMLFormat( rText );
}
}
}