From ce51bf1a6ef36bbd1eea751add342cae6f1004d2 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 31 Mar 2013 20:11:57 +0200 Subject: Make a bit cleaner transformation of help strings *Not escape tags and double quots in tags, but find tags(icu regexp) when merge and use this infromation to make strings valid. *Define a new Quot function for helpex, which works with icu UnicodeCharacter. *Move tag search to xmlparse.cxx and use icu just in helpex. *QuotHTML not unescape just replace xml charcters. (unescaping is also useless in uimerge.cxx) *Move UnQuotHTML() to helper. (was used it in xmlparse.cxx and cfgmerge.cxx) *Use UnQuotHTML() in uimerge.cxx too. Change-Id: Ice8940ef69279709a1c5d84c6ae1b0d62a71ca76 --- l10ntools/source/po.cxx | 82 ++----------------------------------------------- 1 file changed, 2 insertions(+), 80 deletions(-) (limited to 'l10ntools/source/po.cxx') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 36e6ebb6f2ce..bbfe0633bab6 100755 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -17,15 +17,12 @@ #include #include -#include #include "po.hxx" #define POESCAPED OString("\\n\\t\\r\\\\\\\"") #define POUNESCAPED OString("\n\t\r\\\"") -using namespace U_ICU_NAMESPACE; - /** Container of po entry Provide all file operations related to LibreOffice specific @@ -282,92 +279,17 @@ namespace const OString& rText,const bool bHelpText = false ) { if ( bHelpText ) - return lcl_UnEscapeText(rText,"\\<\\>\\\"\\\\","<>\"\\"); + return rText; else return lcl_UnEscapeText(rText,"\\n\\t\\r","\n\t\r"); } - //Find all special tag in a string using a regular expression - static void lcl_FindAllTag( - const OString& rText,std::vector& o_vFoundTags ) - { - - UErrorCode nIcuErr = U_ZERO_ERROR; - static const sal_uInt32 nSearchFlags = - UREGEX_DOTALL | UREGEX_CASE_INSENSITIVE; - OUString sLocaleText( OStringToOUString(rText,RTL_TEXTENCODING_UTF8) ); - static const OUString sPattern( - "<[/]\?\?[a-z_-]+?(?:| +[a-z]+?=\".*?\") *[/]\?\?>"); - static const UnicodeString sSearchPat( - reinterpret_cast(sPattern.getStr()), - sPattern.getLength() ); - UnicodeString sSource( - reinterpret_cast( - sLocaleText.getStr()), sLocaleText.getLength() ); - - RegexMatcher aRegexMatcher( sSearchPat, nSearchFlags, nIcuErr ); - aRegexMatcher.reset( sSource ); - int64_t nStartPos = 0; - while( aRegexMatcher.find(nStartPos, nIcuErr) && - nIcuErr == U_ZERO_ERROR ) - { - UnicodeString sMatch = - aRegexMatcher.group(nIcuErr); - o_vFoundTags.push_back( - OUStringToOString( - OUString( - reinterpret_cast( - sMatch.getBuffer()),sMatch.length()), - RTL_TEXTENCODING_UTF8)); - nStartPos = aRegexMatcher.start(nIcuErr)+1; - } - } - - //Escape special tags - static OString lcl_EscapeTags( const OString& rText ) - { - typedef std::vector StrVec_t; - static const OString vInitializer[] = { - "ahelp", "link", "item", "emph", "defaultinline", - "switchinline", "caseinline", "variable", - "bookmark_value", "image", "embedvar", "alt" }; - static const StrVec_t vTagsForEscape( vInitializer, - vInitializer + sizeof(vInitializer) / sizeof(vInitializer[0]) ); - StrVec_t vFoundTags; - lcl_FindAllTag(rText,vFoundTags); - OString sResult = rText; - for(StrVec_t::const_iterator pFound = vFoundTags.begin(); - pFound != vFoundTags.end(); ++pFound) - { - bool bEscapeThis = false; - for(StrVec_t::const_iterator pEscape = vTagsForEscape.begin(); - pEscape != vTagsForEscape.end(); ++pEscape) - { - if (pFound->startsWith("<" + *pEscape) || - *pFound == "") - { - bEscapeThis = true; - break; - } - } - if( bEscapeThis || *pFound=="
" || - *pFound =="") - { - OString sToReplace = "\\<" + - pFound->copy(1,pFound->getLength()-2). - replaceAll("\"","\\\"") + "\\>"; - sResult = sResult.replaceAll(*pFound, sToReplace); - } - } - return sResult; - } - //Escape to get merge string static OString lcl_EscapeMergeText( const OString& rText,const bool bHelpText = false ) { if ( bHelpText ) - return lcl_EscapeTags(rText.replaceAll("\\","\\\\")); + return rText; else return lcl_EscapeText(rText,"\n\t\r","\\n\\t\\r"); } -- cgit v1.2.3