From 63cb8d6bb21ad6bb401efa4eca479f89745c1cfe Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 11 Jul 2012 12:16:13 +0200 Subject: fdo#51954: More tools->rtl string conversion regressions Change-Id: I490cc82b60663d30fdc8e09d9d6021c964656bec --- l10ntools/source/gsicheck.cxx | 2 +- l10ntools/source/helper.hxx | 9 +++++++++ l10ntools/source/tagtest.cxx | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/gsicheck.cxx b/l10ntools/source/gsicheck.cxx index bb0e11601340..98e4b310f01b 100644 --- a/l10ntools/source/gsicheck.cxx +++ b/l10ntools/source/gsicheck.cxx @@ -362,7 +362,7 @@ void GSIBlock::PrintList( ParserMessageList *pList, rtl::OString const & aPrefix if ( pMsg->GetTagBegin() == -1 ) aContext = pLine->GetText().copy( 0, 300 ); else - aContext = pLine->data_.copy( pMsg->GetTagBegin()-150, 300 ); + aContext = helper::abbreviate( pLine->data_, pMsg->GetTagBegin()-150, 300 ); aContext = aContext.trim(); } diff --git a/l10ntools/source/helper.hxx b/l10ntools/source/helper.hxx index 59f86287fd72..ee03eda3a162 100644 --- a/l10ntools/source/helper.hxx +++ b/l10ntools/source/helper.hxx @@ -32,6 +32,7 @@ #include "sal/config.h" +#include #include #include "rtl/string.hxx" @@ -99,6 +100,14 @@ inline sal_Int32 indexOfAnyAsciiL( return -1; } +template< typename T > inline T abbreviate( + T const & text, sal_Int32 start, sal_Int32 length) +{ + start = std::max(0, start); + assert(start <= text.getLength()); + return text.copy(start, std::min(text.getLength() - start, length)); +} + } #endif diff --git a/l10ntools/source/tagtest.cxx b/l10ntools/source/tagtest.cxx index 2a29c3f59e6f..77b3be82ee67 100644 --- a/l10ntools/source/tagtest.cxx +++ b/l10ntools/source/tagtest.cxx @@ -707,7 +707,7 @@ TokenInfo SimpleParser::GetNextToken( ParserMessageList &rErrorList ) // this is only to kick out quoted backslashes while (nQuotedQuotesPos != -1) { - if ( nQuotedBackPos <= nQuotedQuotesPos ) + if ( nQuotedBackPos != -1 && nQuotedBackPos <= nQuotedQuotesPos ) nQuotePos = nQuotedBackPos+2; else { @@ -808,7 +808,7 @@ rtl::OUString SimpleParser::GetNextTokenString( ParserMessageList &rErrorList, s if (nEndPos == -1) { // Token is incomplete. Skip start and search for better ones nPos = nStyle3StartPos +2; - rErrorList.AddError( 24, "Tag Start '\\<' without Tag End '\\>'", TokenInfo( TAG_UNKNOWN_TAG, nStyle3StartPos, aSource.copy(nStyle3StartPos - 10, 20) ) ); + rErrorList.AddError( 24, "Tag Start '\\<' without Tag End '\\>'", TokenInfo( TAG_UNKNOWN_TAG, nStyle3StartPos, helper::abbreviate(aSource, nStyle3StartPos - 10, 20) ) ); return GetNextTokenString( rErrorList, rTagStartPos ); } // check for paired quoted " --> \"sometext\" -- cgit