diff options
author | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-03-27 20:08:50 +0100 |
---|---|---|
committer | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-03-27 20:09:31 +0100 |
commit | 8e26b4783f1f47ff5d489e7df5869240eefd1071 (patch) | |
tree | 80c4c9899fb3b05fcadc845444b06e1e3221e1c2 /l10ntools/source/cfgmerge.cxx | |
parent | 239fb4cb41cb0d1ed42bf5cf8ecdabdca4a28a68 (diff) |
Refactor l10ntools
Delete unused functions.
Make Export class more encapsulated.
Move to local that functions which are used only in one file.
Common contans method which are used by all executables.
Helper contains methods belong to xml parsing.
Change-Id: I28773a2c7eea90da7df7f32720fd38de2cb661ac
Diffstat (limited to 'l10ntools/source/cfgmerge.cxx')
-rw-r--r-- | l10ntools/source/cfgmerge.cxx | 100 |
1 files changed, 91 insertions, 9 deletions
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("<"); + break; + + case '>': + sReturn.append(">"); + break; + + case '\"': + sReturn.append("""); + break; + + case '\'': + sReturn.append("'"); + break; + + case '&': + if ((( i + 4 ) < rString.getLength()) && + ( rString.copy( i, 5 ) == "&" )) + sReturn.append(rString[i]); + else + sReturn.append("&"); + 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("&", i)) { + sReturn.append('&'); + i += RTL_CONSTASCII_LENGTH("&"); + } else if (rString.match("<", i)) { + sReturn.append('<'); + i += RTL_CONSTASCII_LENGTH("<"); + } else if (rString.match(">", i)) { + sReturn.append('>'); + i += RTL_CONSTASCII_LENGTH(">"); + } else if (rString.match(""", i)) { + sReturn.append('"'); + i += RTL_CONSTASCII_LENGTH("""); + } else if (rString.match("'", i)) { + sReturn.append('\''); + i += RTL_CONSTASCII_LENGTH("'"); + } 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" ); |