[Libreoffice-commits] .: 2 commits - l10ntools/inc l10ntools/source unotest/source
Stephan Bergmann
sbergmann at kemper.freedesktop.org
Thu Feb 9 06:27:40 PST 2012
l10ntools/inc/tagtest.hxx | 38 +--
l10ntools/source/gsicheck.cxx | 307 ++++++++++++++++----------------
l10ntools/source/helper.hxx | 47 ++++
l10ntools/source/makefile.mk | 2
l10ntools/source/tagtest.cxx | 93 +++++----
unotest/source/cpp/officeconnection.cxx | 7
6 files changed, 275 insertions(+), 219 deletions(-)
New commits:
commit 69aff995cb83cd702520999f592fe21a561042fa
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Feb 9 15:24:12 2012 +0100
Do not fail isStillAlive for "connect:" connections
diff --git a/unotest/source/cpp/officeconnection.cxx b/unotest/source/cpp/officeconnection.cxx
index 1b2e47c..3791ddd 100644
--- a/unotest/source/cpp/officeconnection.cxx
+++ b/unotest/source/cpp/officeconnection.cxx
@@ -180,7 +180,12 @@ OfficeConnection::getComponentContext() const {
}
bool OfficeConnection::isStillAlive() const {
- OSL_ASSERT(process_ != 0);
+ if (process_ == 0) {
+ // In case "soffice" argument starts with "connect:" we have no direct
+ // control over the liveness of the soffice.bin process (would need to
+ // directly monitor the bridge) so can only assume the best here:
+ return true;
+ }
TimeValue delay = { 0, 0 }; // 0 sec
oslProcessError e = osl_joinProcessWithTimeout(process_, &delay);
CPPUNIT_ASSERT(e == osl_Process_E_None || e == osl_Process_E_TimedOut);
commit f07a22ff6fb6c4bb131eacc9c3298b076361cee5
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Feb 9 15:22:47 2012 +0100
gsicheck now only depends on sal
diff --git a/l10ntools/inc/tagtest.hxx b/l10ntools/inc/tagtest.hxx
index b77e260..b546be2 100644
--- a/l10ntools/inc/tagtest.hxx
+++ b/l10ntools/inc/tagtest.hxx
@@ -34,9 +34,9 @@
class GSILine;
-typedef sal_uInt16 TokenId;
+typedef sal_Int32 TokenId;
-#define TOK_INVALIDPOS sal_uInt16( 0xFFFF )
+#define TOK_INVALIDPOS (-1)
class ParserMessage;
typedef ::std::vector< ParserMessage* > Impl_ParserMessageList;
@@ -64,12 +64,12 @@ public:
rtl::OUString aTokenString;
TokenId nId;
- sal_uInt16 nPos; // Position in String
+ sal_Int32 nPos; // Position in String
TokenInfo():bClosed(sal_False),bCloseTag(sal_False),bIsBroken(sal_False),bHasBeenFixed(sal_False),bDone(sal_False),nId( 0 ){;}
-explicit TokenInfo( TokenId pnId, sal_uInt16 nP ):bClosed(sal_False),bCloseTag(sal_False),bIsBroken(sal_False),bHasBeenFixed(sal_False),bDone(sal_False),nId( pnId ),nPos(nP){;}
- explicit TokenInfo( TokenId pnId, sal_uInt16 nP, rtl::OUString const & paStr ):bClosed(sal_False),bCloseTag(sal_False),bIsBroken(sal_False),bHasBeenFixed(sal_False),bDone(sal_False),aTokenString( paStr ),nId( pnId ),nPos(nP) {;}
- explicit TokenInfo( TokenId pnId, sal_uInt16 nP, rtl::OUString const & paStr, ParserMessageList &rErrorList );
+explicit TokenInfo( TokenId pnId, sal_Int32 nP ):bClosed(sal_False),bCloseTag(sal_False),bIsBroken(sal_False),bHasBeenFixed(sal_False),bDone(sal_False),nId( pnId ),nPos(nP){;}
+ explicit TokenInfo( TokenId pnId, sal_Int32 nP, rtl::OUString const & paStr ):bClosed(sal_False),bCloseTag(sal_False),bIsBroken(sal_False),bHasBeenFixed(sal_False),bDone(sal_False),aTokenString( paStr ),nId( pnId ),nPos(nP) {;}
+ explicit TokenInfo( TokenId pnId, sal_Int32 nP, rtl::OUString const & paStr, ParserMessageList &rErrorList );
rtl::OUString GetTagName() const;
@@ -107,8 +107,8 @@ private:
public:
~ParserMessageList() { clear(); }
- void AddError( sal_uInt16 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag );
- void AddWarning( sal_uInt16 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag );
+ void AddError( sal_Int32 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag );
+ void AddWarning( sal_Int32 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag );
sal_Bool HasErrors();
bool empty() const { return maList.empty(); }
@@ -242,19 +242,19 @@ public:
class ParserMessage
{
- sal_uInt16 nErrorNr;
+ sal_Int32 nErrorNr;
rtl::OString aErrorText;
- sal_uInt16 nTagBegin,nTagLength;
+ sal_Int32 nTagBegin,nTagLength;
protected:
- ParserMessage( sal_uInt16 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag );
+ ParserMessage( sal_Int32 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag );
public:
- sal_uInt16 GetErrorNr() { return nErrorNr; }
+ sal_Int32 GetErrorNr() { return nErrorNr; }
rtl::OString GetErrorText() { return aErrorText; }
- sal_uInt16 GetTagBegin() { return nTagBegin; }
- sal_uInt16 GetTagLength() { return nTagLength; }
+ sal_Int32 GetTagBegin() { return nTagBegin; }
+ sal_Int32 GetTagLength() { return nTagLength; }
virtual ~ParserMessage() {}
virtual sal_Bool IsError() =0;
@@ -264,7 +264,7 @@ public:
class ParserError : public ParserMessage
{
public:
- ParserError( sal_uInt16 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag );
+ ParserError( sal_Int32 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag );
virtual sal_Bool IsError() {return sal_True;}
virtual rtl::OString Prefix() {return rtl::OString(RTL_CONSTASCII_STRINGPARAM("Error:")); }
@@ -273,7 +273,7 @@ public:
class ParserWarning : public ParserMessage
{
public:
- ParserWarning( sal_uInt16 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag );
+ ParserWarning( sal_Int32 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag );
virtual sal_Bool IsError() {return sal_False;}
virtual rtl::OString Prefix() {return rtl::OString(RTL_CONSTASCII_STRINGPARAM("Warning:")); }
@@ -282,14 +282,14 @@ public:
class SimpleParser
{
private:
- sal_uInt16 nPos;
+ sal_Int32 nPos;
rtl::OUString aSource;
rtl::OUString aLastToken;
TokenList aTokenList;
TokenInfo aNextTag; // to store closetag in case of combined tags like <br/>
- rtl::OUString GetNextTokenString( ParserMessageList &rErrorList, sal_uInt16 &rTokeStartPos );
+ rtl::OUString GetNextTokenString( ParserMessageList &rErrorList, sal_Int32 &rTokeStartPos );
public:
SimpleParser();
@@ -303,7 +303,7 @@ class TokenParser
{
sal_Bool match( const TokenInfo &aCurrentToken, const TokenId &aExpectedToken );
sal_Bool match( const TokenInfo &aCurrentToken, const TokenInfo &aExpectedToken );
- void ParseError( sal_uInt16 nErrNr, const rtl::OString &rErrMsg, const TokenInfo &rTag );
+ void ParseError( sal_Int32 nErrNr, const rtl::OString &rErrMsg, const TokenInfo &rTag );
void Paragraph();
void PfCase();
void PfCaseBegin();
diff --git a/l10ntools/source/gsicheck.cxx b/l10ntools/source/gsicheck.cxx
index 9fec6bf..9405a91 100644
--- a/l10ntools/source/gsicheck.cxx
+++ b/l10ntools/source/gsicheck.cxx
@@ -28,23 +28,46 @@
#include "sal/config.h"
+#include <algorithm>
+#include <cassert>
#include <cstddef>
#include <fstream>
#include <string>
#include <stdio.h>
-#include <tools/fsys.hxx>
#include <rtl/strbuf.hxx>
-#include <comphelper/string.hxx>
#include "helper.hxx"
#include "tagtest.hxx"
#include "gsicheck.hxx"
-using comphelper::string::getToken;
-using comphelper::string::getTokenCount;
+namespace {
-#define MAX_GID_LID_LEN 250
+sal_Int32 const MAX_GID_LID_LEN = 250;
+
+rtl::OString copyUpTo(
+ rtl::OString const & text, sal_Int32 start, sal_Int32 maximumLength)
+{
+ assert(start >= 0 && start <= text.getLength());
+ return text.copy(start, std::min(text.getLength() - start, maximumLength));
+}
+
+rtl::OString addSuffix(
+ rtl::OString const & pathname, rtl::OString const & suffix)
+{
+ sal_Int32 n = pathname.lastIndexOf('.');
+ if (n == -1) {
+ fprintf(
+ stderr,
+ ("Error: pathname \"%s\" does not contain dot to add suffix in"
+ " front of\n"),
+ pathname.getStr());
+ exit(EXIT_FAILURE);
+ }
+ return pathname.replaceAt(n, 0, suffix);
+}
+
+}
/*****************************************************************************/
void PrintMessage( rtl::OString const & aType, rtl::OString const & aMsg, rtl::OString const & aPrefix,
@@ -69,30 +92,20 @@ void PrintError( rtl::OString const & aMsg, rtl::OString const & aPrefix,
PrintMessage( "Error:", aMsg, aPrefix, aContext, bPrintContext, nLine, aUniqueId );
}
-sal_Bool LanguageOK( rtl::OString const & aLang )
+bool LanguageOK( rtl::OString const & aLang )
{
- if (aLang.isEmpty())
- return sal_False;
-
- using comphelper::string::isdigitAsciiString;
- using comphelper::string::isupperAsciiString;
- using comphelper::string::islowerAsciiString;
-
- if (isdigitAsciiString(aLang))
- return sal_True;
-
- if ( getTokenCount(aLang, '-') == 1 )
- return islowerAsciiString(aLang);
- else if ( getTokenCount(aLang, '-') == 2 )
- {
- rtl::OString aTok0( getToken(aLang, 0, '-') );
- rtl::OString aTok1( getToken(aLang, 1, '-') );
- return !aTok0.isEmpty() && islowerAsciiString(aTok0)
- && !aTok1.isEmpty() && isupperAsciiString(aTok1)
- && !aTok1.equalsIgnoreAsciiCase( aTok0 );
+ sal_Int32 n = 0;
+ rtl::OString t0(aLang.getToken(0, '-', n));
+ if (n == -1) {
+ return !t0.isEmpty()
+ && (helper::isAllAsciiDigits(t0)
+ || helper::isAllAsciiLowerCase(t0));
}
-
- return sal_False;
+ rtl::OString t1(aLang.getToken(0, '-', n));
+ return n == -1
+ && !t0.isEmpty() && helper::isAllAsciiLowerCase(t0)
+ && !t1.isEmpty() && helper::isAllAsciiUpperCase(t1)
+ && !t0.equalsIgnoreAsciiCase(t1);
}
class LazyStream: public std::ofstream
@@ -144,51 +157,67 @@ GSILine::GSILine( const rtl::OString &rLine, std::size_t nLine )
, bFixed ( sal_False )
, data_( rLine )
{
- if ( getTokenCount(rLine, '\t') == 15 )
- {
- aFormat = FORMAT_SDF;
- aUniqId = getToken(rLine, 0, '\t');
- aUniqId += "/";
- aUniqId += getToken(rLine, 1, '\t');
- aUniqId += "/";
- aUniqId += getToken(rLine, 3, '\t');
- aUniqId += "/";
- aUniqId += getToken(rLine, 4, '\t');
- aUniqId += "/";
- aUniqId += getToken(rLine, 5, '\t');
- aUniqId += "/";
- aUniqId += getToken(rLine, 6, '\t');
- aUniqId += "/";
- aUniqId += getToken(rLine, 7, '\t');
- aLineType = "";
- aLangId = getToken(rLine, 9, '\t');
- aText = getToken(rLine, 10, '\t');
- aQuickHelpText = getToken(rLine, 12, '\t');
- aTitle = getToken(rLine, 13, '\t');
-
- // do some more format checks here
- if (!comphelper::string::isdigitAsciiString(getToken(rLine, 8, '\t')))
- {
- PrintError( "The length field does not contain a number!", "Line format", getToken(rLine, 8, '\t'), sal_True, GetLineNumber(), GetUniqId() );
- NotOK();
- }
- if ( !LanguageOK( aLangId ) )
- {
- PrintError( "The Language is invalid!", "Line format", aLangId, sal_True, GetLineNumber(), GetUniqId() );
- NotOK();
- }
- // limit GID and LID to MAX_GID_LID_LEN chars each for database conformity, see #137575#
- if ( getToken(rLine, 4, '\t').getLength() > MAX_GID_LID_LEN || getToken(rLine, 5, '\t').getLength() > MAX_GID_LID_LEN )
- {
- PrintError(rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("GID and LID may only be "))
- .append(static_cast<sal_Int32>(MAX_GID_LID_LEN))
- .append(RTL_CONSTASCII_STRINGPARAM(" chars long each!" )).getStr(),
- "Line format", aLangId, sal_True, GetLineNumber(), GetUniqId());
- NotOK();
- }
+ if (rLine.isEmpty()) {
+ NotOK();
+ return;
}
- else
+
+ aFormat = FORMAT_SDF;
+ sal_Int32 n = 0;
+ aUniqId = rLine.getToken(0, '\t', n); // token 0
+ aUniqId += "/";
+ aUniqId += rLine.getToken(0, '\t', n); // token 1
+ aUniqId += "/";
+ aUniqId += rLine.getToken(1, '\t', n); // token 3
+ aUniqId += "/";
+ rtl::OString gid(rLine.getToken(0, '\t', n)); // token 4
+ aUniqId += gid;
+ aUniqId += "/";
+ rtl::OString lid(rLine.getToken(0, '\t', n)); // token 5
+ aUniqId += lid;
+ aUniqId += "/";
+ aUniqId += rLine.getToken(0, '\t', n); // token 6
+ aUniqId += "/";
+ aUniqId += rLine.getToken(0, '\t', n); // token 7
+ rtl::OString length(rLine.getToken(0, '\t', n)); // token 8
+ aLineType = rtl::OString();
+ aLangId = rLine.getToken(0, '\t', n); // token 9
+ aText = rLine.getToken(0, '\t', n); // token 10
+ aQuickHelpText = rLine.getToken(1, '\t', n); // token 12
+ aTitle = rLine.getToken(0, '\t', n); // token 13
+ if (n == -1) {
+ NotOK();
+ return;
+ }
+ rLine.getToken(0, '\t', n); // token 14
+ if (n != -1) {
+ NotOK();
+ return;
+ }
+
+ // do some more format checks here
+ if (!helper::isAllAsciiDigits(length)) {
+ PrintError(
+ "The length field does not contain a number!", "Line format",
+ length, true, GetLineNumber(), GetUniqId());
+ NotOK();
+ }
+ if (!LanguageOK(aLangId)) {
+ PrintError(
+ "The Language is invalid!", "Line format", aLangId, true,
+ GetLineNumber(), GetUniqId());
+ NotOK();
+ }
+ // Limit GID and LID to MAX_GID_LID_LEN chars each for database conformity,
+ // see #137575#:
+ if (gid.getLength() > MAX_GID_LID_LEN || lid.getLength() > MAX_GID_LID_LEN)
{
+ PrintError(
+ (rtl::OString(
+ RTL_CONSTASCII_STRINGPARAM("GID and LID may only be "))
+ + rtl::OString::valueOf(MAX_GID_LID_LEN)
+ + rtl::OString(RTL_CONSTASCII_STRINGPARAM(" chars long each"))),
+ "Line format", aLangId, true, GetLineNumber(), GetUniqId());
NotOK();
}
}
@@ -204,30 +233,31 @@ void GSILine::NotOK()
void GSILine::ReassembleLine()
/*****************************************************************************/
{
- if ( GetLineFormat() == FORMAT_SDF )
- {
- rtl::OStringBuffer aReassemble;
- for (sal_Int32 i = 0; i < 10; ++i)
- {
- aReassemble.append( helper::getToken( data_, i, '\t' ) );
- aReassemble.append( "\t" );
- }
- aReassemble.append( aText );
- aReassemble.append( "\t" );
- aReassemble.append( helper::getToken( data_, 11, '\t' ) ); // should be empty but there are some places in sc. Not reflected to sources!!
- aReassemble.append( "\t" );
- aReassemble.append( aQuickHelpText );
- aReassemble.append( "\t" );
- aReassemble.append( aTitle );
- for (sal_Int32 i = 14; i < 15; ++i)
- {
- aReassemble.append( "\t" );
- aReassemble.append( helper::getToken( data_, i, '\t' ) );
- }
- data_ = aReassemble.makeStringAndClear();
+ if (GetLineFormat() != FORMAT_SDF) {
+ PrintError(
+ "Cannot reassemble line of unknown type (internal Error).",
+ "Line format", rtl::OString(), false, GetLineNumber(),
+ GetUniqId());
+ return;
}
- else
- PrintError( "Cannot reassemble line of unknown type (internal Error).", "Line format", "", sal_False, GetLineNumber(), GetUniqId() );
+ rtl::OStringBuffer b;
+ sal_Int32 n = 0;
+ for (sal_Int32 i = 0; i != 10; ++i) {
+ b.append(data_.getToken(0, '\t', n)); // token 0--9
+ b.append('\t');
+ }
+ b.append(aText);
+ b.append('\t');
+ b.append(data_.getToken(1, '\t', n));
+ // token 11; should be empty but there are some places in sc not
+ // reflected to sources
+ b.append('\t');
+ b.append(aQuickHelpText);
+ b.append('\t');
+ b.append(aTitle);
+ b.append('\t');
+ b.append(data_.getToken(2, '\t', n)); // token 14
+ data_ = b.makeStringAndClear();
}
//
@@ -328,12 +358,11 @@ void GSIBlock::PrintList( ParserMessageList *pList, rtl::OString const & aPrefix
rtl::OString aContext;
if ( bPrintContext )
{
- if ( pMsg->GetTagBegin() == STRING_NOTFOUND )
+ if ( pMsg->GetTagBegin() == -1 )
aContext = pLine->GetText().copy( 0, 300 );
else
aContext = pLine->data_.copy( pMsg->GetTagBegin()-150, 300 );
- aContext = comphelper::string::stripEnd(aContext, ' ');
- aContext = comphelper::string::stripStart(aContext, ' ');
+ aContext = helper::trimAscii(aContext);
}
PrintMessage( pMsg->Prefix(), pMsg->GetErrorText(), aPrefix, aContext, pLine->GetLineNumber(), pLine->GetUniqId() );
@@ -346,12 +375,17 @@ sal_Bool GSIBlock::IsUTF8( const rtl::OString &aTestee, sal_Bool bFixTags, sal_I
{
rtl::OUString aUTF8Tester(
rtl::OStringToOUString(aTestee, RTL_TEXTENCODING_UTF8));
- nErrorPos = rtl::OUStringToOString(aUTF8Tester, RTL_TEXTENCODING_UTF8).
- indexOf(aTestee);
- if (nErrorPos != -1)
+ rtl::OString aTestee2(
+ rtl::OUStringToOString(aUTF8Tester, RTL_TEXTENCODING_UTF8));
+ sal_Int32 i = 0;
+ while (i != std::min(aTestee.getLength(), aTestee2.getLength())
+ && aTestee[i] == aTestee2[i])
{
- aUTF8Tester = rtl::OUString(
- aTestee.getStr(), nErrorPos, RTL_TEXTENCODING_UTF8);
+ ++i;
+ }
+ if (i != aTestee.getLength() || i != aTestee2.getLength())
+ {
+ aUTF8Tester = rtl::OUString(aTestee.getStr(), i, RTL_TEXTENCODING_UTF8);
nErrorPos = aUTF8Tester.getLength();
aErrorMsg = "UTF8 Encoding seems to be broken";
return sal_False;
@@ -388,7 +422,7 @@ sal_Bool GSIBlock::TestUTF8( GSILine* pTestee, sal_Bool bFixTags )
sal_Bool bHasBeenFixed = sal_False;
if ( !IsUTF8( pTestee->GetText(), bFixTags, nErrorPos, aErrorMsg, bHasBeenFixed, aFixed ) )
{
- rtl::OString aContext( pTestee->GetText().copy( nErrorPos, 20 ) );
+ rtl::OString aContext(copyUpTo(pTestee->GetText(), nErrorPos, 20));
PrintError(rtl::OStringBuffer(aErrorMsg).append(RTL_CONSTASCII_STRINGPARAM(" in Text at Position "))
.append(nErrorPos).getStr(),
"Text format", aContext, pTestee->GetLineNumber(), pTestee->GetUniqId());
@@ -401,7 +435,8 @@ sal_Bool GSIBlock::TestUTF8( GSILine* pTestee, sal_Bool bFixTags )
}
if ( !IsUTF8( pTestee->GetQuickHelpText(), bFixTags, nErrorPos, aErrorMsg, bHasBeenFixed, aFixed ) )
{
- rtl::OString aContext( pTestee->GetQuickHelpText().copy( nErrorPos, 20 ) );
+ rtl::OString aContext(
+ copyUpTo(pTestee->GetQuickHelpText(), nErrorPos, 20));
PrintError(rtl::OStringBuffer(aErrorMsg).append(RTL_CONSTASCII_STRINGPARAM(" in QuickHelpText at Position "))
.append(nErrorPos).getStr(),
"Text format", aContext, pTestee->GetLineNumber(), pTestee->GetUniqId());
@@ -667,15 +702,15 @@ int _cdecl main( int argc, char *argv[] )
sal_Bool bWriteFixed = sal_False;
sal_Bool bFixTags = sal_False;
sal_Bool bAllowSuspicious = sal_False;
- rtl::OUString aErrorFilename;
- rtl::OUString aCorrectFilename;
- rtl::OUString aFixedFilename;
+ rtl::OString aErrorFilename;
+ rtl::OString aCorrectFilename;
+ rtl::OString aFixedFilename;
sal_Bool bFileHasError = sal_False;
rtl::OString aSourceLang( "en-US" ); // English is default
rtl::OString aFilename;
rtl::OString aReferenceFilename;
sal_Bool bReferenceFile = sal_False;
- for ( sal_uInt16 i = 1 ; i < argc ; i++ )
+ for ( int i = 1 ; i < argc ; i++ )
{
if ( *argv[ i ] == '-' )
{
@@ -690,10 +725,7 @@ int _cdecl main( int argc, char *argv[] )
if ( (*(argv[ i ]+3)) == 'f' )
if ( (i+1) < argc )
{
- aErrorFilename = rtl::OUString(
- argv[i + 1],
- rtl_str_getLength(argv[i + 1]),
- RTL_TEXTENCODING_ASCII_US);
+ aErrorFilename = argv[i + 1];
bWriteError = sal_True;
i++;
}
@@ -709,10 +741,7 @@ int _cdecl main( int argc, char *argv[] )
if ( (*(argv[ i ]+3)) == 'f' )
if ( (i+1) < argc )
{
- aCorrectFilename = rtl::OUString(
- argv[i + 1],
- rtl_str_getLength(argv[i + 1]),
- RTL_TEXTENCODING_ASCII_US);
+ aCorrectFilename = argv[i + 1];
bWriteCorrect = sal_True;
i++;
}
@@ -727,10 +756,7 @@ int _cdecl main( int argc, char *argv[] )
if ( (*(argv[ i ]+3)) == 'f' )
if ( (i+1) < argc )
{
- aFixedFilename = rtl::OUString(
- argv[i + 1],
- rtl_str_getLength(argv[i + 1]),
- RTL_TEXTENCODING_ASCII_US);
+ aFixedFilename = argv[i + 1];
bWriteFixed = sal_True;
bFixTags = sal_True;
i++;
@@ -837,12 +863,6 @@ int _cdecl main( int argc, char *argv[] )
- DirEntry aSource = DirEntry( rtl::OStringToOUString( aFilename, RTL_TEXTENCODING_ASCII_US ));
- if ( !aSource.Exists()) {
- fprintf( stderr, "\nERROR: GSI-File %s not found!\n\n", aFilename.getStr() );
- exit ( 2 );
- }
-
std::ifstream aGSI(aFilename.getStr());
if (!aGSI.is_open()) {
fprintf( stderr, "\nERROR: Could not open GSI-File %s!\n\n", aFilename.getStr() );
@@ -852,12 +872,6 @@ int _cdecl main( int argc, char *argv[] )
std::ifstream aReferenceGSI;
if ( bReferenceFile )
{
- DirEntry aReferenceSource = DirEntry( rtl::OStringToOUString( aReferenceFilename, RTL_TEXTENCODING_ASCII_US ));
- if ( !aReferenceSource.Exists()) {
- fprintf( stderr, "\nERROR: GSI-File %s not found!\n\n", aFilename.getStr() );
- exit ( 2 );
- }
-
aReferenceGSI.open(aReferenceFilename.getStr());
if (!aReferenceGSI.is_open()) {
fprintf( stderr, "\nERROR: Could not open Input-File %s!\n\n", aFilename.getStr() );
@@ -866,19 +880,14 @@ int _cdecl main( int argc, char *argv[] )
}
LazyStream aOkOut;
- rtl::OUString aBaseName(aSource.GetBase());
if ( bWriteCorrect )
{
if (aCorrectFilename.isEmpty())
{
- rtl::OUString sTmpBase(aBaseName);
- sTmpBase += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_ok"));
- aSource.SetBase( sTmpBase );
- aCorrectFilename = aSource.GetFull();
+ aCorrectFilename = addSuffix(
+ aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_ok")));
}
- aOkOut.SetFileName(
- rtl::OUStringToOString(
- aCorrectFilename, osl_getThreadTextEncoding()));
+ aOkOut.SetFileName(aCorrectFilename);
}
LazyStream aErrOut;
@@ -886,14 +895,10 @@ int _cdecl main( int argc, char *argv[] )
{
if (aErrorFilename.isEmpty())
{
- rtl::OUString sTmpBase(aBaseName);
- sTmpBase += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_err"));
- aSource.SetBase( sTmpBase );
- aErrorFilename = aSource.GetFull();
+ aErrorFilename = addSuffix(
+ aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_err")));
}
- aErrOut.SetFileName(
- rtl::OUStringToOString(
- aErrorFilename, osl_getThreadTextEncoding()));
+ aErrOut.SetFileName(aErrorFilename);
}
LazyStream aFixOut;
@@ -901,14 +906,10 @@ int _cdecl main( int argc, char *argv[] )
{
if (aFixedFilename.isEmpty())
{
- rtl::OUString sTmpBase(aBaseName);
- sTmpBase += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_fix"));
- aSource.SetBase( sTmpBase );
- aFixedFilename = aSource.GetFull();
+ aFixedFilename = addSuffix(
+ aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_fix")));
}
- aFixOut.SetFileName(
- rtl::OUStringToOString(
- aFixedFilename, osl_getThreadTextEncoding()));
+ aFixOut.SetFileName(aFixedFilename);
}
diff --git a/l10ntools/source/helper.hxx b/l10ntools/source/helper.hxx
index 27ee642..edd2d0f 100644
--- a/l10ntools/source/helper.hxx
+++ b/l10ntools/source/helper.hxx
@@ -35,15 +35,62 @@
#include <cassert>
#include "rtl/string.hxx"
+#include "rtl/ustring.hxx"
#include "sal/types.h"
namespace helper {
+inline bool isAsciiWhitespace(char c) {
+ return (c >= 0x09 && c <= 0x0D) || c == ' '; // HT, LF, VT, FF, CR
+}
+
+// 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 bool endsWith(rtl::OString const & text, rtl::OString const & search) {
return text.getLength() >= search.getLength()
&& text.match(search, text.getLength() - search.getLength());
}
+inline rtl::OString trimAscii(rtl::OString const & text) {
+ sal_Int32 i1 = 0;
+ while (i1 != text.getLength() && isAsciiWhitespace(text[i1])) {
+ ++i1;
+ }
+ sal_Int32 i2 = text.getLength();
+ while (i2 != i1 && isAsciiWhitespace(text[i2 - 1])) {
+ --i2;
+ }
+ return text.copy(i1, i2 - i1);
+}
+
inline sal_Int32 searchAndReplace(
rtl::OString * text, rtl::OString const & search,
rtl::OString const & replace)
diff --git a/l10ntools/source/makefile.mk b/l10ntools/source/makefile.mk
index 6911007..597b614 100644
--- a/l10ntools/source/makefile.mk
+++ b/l10ntools/source/makefile.mk
@@ -107,8 +107,6 @@ APP5TARGET= gsicheck
APP5OBJS= $(OBJ)$/gsicheck.obj $(OBJ)$/tagtest.obj
APP5RPATH= NONE
APP5STDLIBS+= \
- $(TOOLSLIB) \
- $(COMPHELPERLIB) \
$(SALLIB)
# extractor and merger for *.cfg
diff --git a/l10ntools/source/tagtest.cxx b/l10ntools/source/tagtest.cxx
index 5d7f1ab..8238308 100644
--- a/l10ntools/source/tagtest.cxx
+++ b/l10ntools/source/tagtest.cxx
@@ -26,8 +26,13 @@
*
************************************************************************/
-#include <tools/string.hxx>
-#include <rtl/strbuf.hxx>
+#include "sal/config.h"
+
+#include "rtl/strbuf.hxx"
+#include "rtl/string.hxx"
+#include "rtl/ustrbuf.hxx"
+#include "rtl/ustring.hxx"
+
#include "tagtest.hxx"
#if OSL_DEBUG_LEVEL > 1
@@ -43,7 +48,7 @@
-TokenInfo::TokenInfo( TokenId pnId, sal_uInt16 nP, rtl::OUString const & paStr, ParserMessageList &rErrorList )
+TokenInfo::TokenInfo( TokenId pnId, sal_Int32 nP, rtl::OUString const & paStr, ParserMessageList &rErrorList )
: bClosed(sal_False)
, bCloseTag(sal_False)
, bIsBroken(sal_False)
@@ -94,8 +99,8 @@ void TokenInfo::SplitTag( ParserMessageList &rErrorList )
sal_Int32 nLastPos = 2; // skip initial \<
sal_Int32 nCheckPos = nLastPos;
static char const aDelims[] = " \\=>/";
- String aPortion;
- String aValue; // store the value of a property
+ rtl::OUString aPortion;
+ rtl::OUString aValue; // store the value of a property
rtl::OString aName; // store the name of a property/tag
sal_Bool bCheckName = sal_False;
sal_Bool bCheckEmpty = sal_False;
@@ -132,7 +137,7 @@ void TokenInfo::SplitTag( ParserMessageList &rErrorList )
break;
case '/':
{
- if ( aPortion.Len() == 0 )
+ if (aPortion.isEmpty())
{
aState = TC_CLOSETAG;
}
@@ -194,7 +199,7 @@ void TokenInfo::SplitTag( ParserMessageList &rErrorList )
break;
case '\"': aState = TC_INSIDE_STRING;
bCheckEmpty = sal_True;
- aValue.Erase();
+ aValue = rtl::OUString();
break;
default: aState = TC_ERROR;
}
@@ -206,7 +211,7 @@ void TokenInfo::SplitTag( ParserMessageList &rErrorList )
{
case '\"': aState = TC_INSIDE_STRING;
bCheckEmpty = sal_True;
- aValue.Erase();
+ aValue = rtl::OUString();
break;
default: aState = TC_ERROR;
}
@@ -241,7 +246,7 @@ void TokenInfo::SplitTag( ParserMessageList &rErrorList )
{
aState = TC_INSIDE_STRING;
aValue += aPortion;
- aValue += cDelim;
+ aValue += rtl::OUString(cDelim);
}
}
break;
@@ -329,7 +334,7 @@ void TokenInfo::SplitTag( ParserMessageList &rErrorList )
if ( bCheckName )
{
- if ( aPortion.Len() == 0 )
+ if (aPortion.isEmpty())
{
rErrorList.AddError( 25, "Tag/Property name missing ", *this );
bIsBroken = sal_True;
@@ -363,7 +368,7 @@ void TokenInfo::SplitTag( ParserMessageList &rErrorList )
if ( bCheckEmpty )
{
- if ( aPortion.Len() )
+ if (!aPortion.isEmpty())
{
rErrorList.AddError( 25, rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("Found displaced characters '")).append(rtl::OUStringToOString(aPortion, RTL_TEXTENCODING_UTF8)).append(RTL_CONSTASCII_STRINGPARAM("' in Tag ")).makeStringAndClear(), *this );
bIsBroken = sal_True;
@@ -528,34 +533,34 @@ rtl::OUString TokenInfo::GetTagName() const
rtl::OUString TokenInfo::MakeTag() const
{
- String aRet;
- aRet.AppendAscii("\\<");
+ rtl::OUStringBuffer aRet;
+ aRet.appendAscii("\\<");
if ( bCloseTag )
- aRet.AppendAscii("/");
- aRet.Append( GetTagName() );
+ aRet.appendAscii("/");
+ aRet.append( GetTagName() );
StringHashMap::const_iterator iProp;
for( iProp = aProperties.begin() ; iProp != aProperties.end(); ++iProp )
{
- aRet.AppendAscii(" ");
- aRet.Append( String( iProp->first, RTL_TEXTENCODING_UTF8 ) );
- aRet.AppendAscii("=\\\"");
- aRet.Append( iProp->second );
- aRet.AppendAscii("\\\"");
+ aRet.appendAscii(" ");
+ aRet.append( rtl::OStringToOUString( iProp->first, RTL_TEXTENCODING_UTF8 ) );
+ aRet.appendAscii("=\\\"");
+ aRet.append( iProp->second );
+ aRet.appendAscii("\\\"");
}
if ( bClosed )
- aRet.AppendAscii("/");
- aRet.AppendAscii("\\>");
- return aRet;
+ aRet.appendAscii("/");
+ aRet.appendAscii("\\>");
+ return aRet.makeStringAndClear();
}
-void ParserMessageList::AddError( sal_uInt16 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag )
+void ParserMessageList::AddError( sal_Int32 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag )
{
maList.push_back( new ParserError( nErrorNr, rErrorText, rTag ) );
}
-void ParserMessageList::AddWarning( sal_uInt16 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag )
+void ParserMessageList::AddWarning( sal_Int32 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag )
{
maList.push_back( new ParserWarning( nErrorNr, rErrorText, rTag ) );
}
@@ -677,7 +682,7 @@ void SimpleParser::Parse( rtl::OUString const & PaSource )
TokenInfo SimpleParser::GetNextToken( ParserMessageList &rErrorList )
{
TokenInfo aResult;
- sal_uInt16 nTokenStartPos = 0;
+ sal_Int32 nTokenStartPos = 0;
if ( aNextTag.nId != TAG_NOMORETAGS )
{
aResult = aNextTag;
@@ -733,12 +738,12 @@ TokenInfo SimpleParser::GetNextToken( ParserMessageList &rErrorList )
while (aLastToken[nNonBlankEndPos] == ' ')
nNonBlankEndPos--;
if (aLastToken[nNonBlankEndPos] == '/')
- aNextTag = TokenInfo( TAG_COMMONEND, nTokenStartPos, String::CreateFromAscii("\\</").Append(aResult.GetTagName()).AppendAscii("\\>"), rErrorList );
+ aNextTag = TokenInfo( TAG_COMMONEND, nTokenStartPos, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\</")) + aResult.GetTagName() + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\>")), rErrorList );
}
}
else
{
- sal_uInt16 i = 0;
+ sal_Int32 i = 0;
while ( aKnownTags[i].nTag != TAG_UNKNOWN_TAG &&
aLastToken != aKnownTags[i].GetName() )
i++;
@@ -752,7 +757,7 @@ TokenInfo SimpleParser::GetNextToken( ParserMessageList &rErrorList )
return aResult;
}
-rtl::OUString SimpleParser::GetNextTokenString( ParserMessageList &rErrorList, sal_uInt16 &rTagStartPos )
+rtl::OUString SimpleParser::GetNextTokenString( ParserMessageList &rErrorList, sal_Int32 &rTagStartPos )
{
sal_Int32 nStyle2StartPos = aSource.indexOfAsciiL(
RTL_CONSTASCII_STRINGPARAM("$["), nPos );
@@ -765,7 +770,7 @@ rtl::OUString SimpleParser::GetNextTokenString( ParserMessageList &rErrorList, s
rTagStartPos = 0;
if (nStyle2StartPos == -1 && nStyle3StartPos == -1)
- return String(); // no more tokens
+ return rtl::OUString(); // no more tokens
if ( nStyle4StartPos < nStyle2StartPos && nStyle4StartPos <= nStyle3StartPos ) // <= to make sure \\ is always handled first
{ // Skip quoted Backslash
@@ -820,7 +825,7 @@ rtl::OUString SimpleParser::GetLexem( TokenInfo const &aToken )
return aToken.aTokenString;
else
{
- sal_uInt16 i = 0;
+ sal_Int32 i = 0;
while ( aKnownTags[i].nTag != TAG_UNKNOWN_TAG &&
aKnownTags[i].nTag != aToken.nId )
i++;
@@ -1349,7 +1354,7 @@ sal_Bool TokenParser::match( const TokenInfo &aCurrentToken, const TokenInfo &rE
return sal_False;
}
-void TokenParser::ParseError( sal_uInt16 nErrNr, const rtl::OString &rErrMsg, const TokenInfo &rTag )
+void TokenParser::ParseError( sal_Int32 nErrNr, const rtl::OString &rErrMsg, const TokenInfo &rTag )
{
pErrorList->AddError( nErrNr, rErrMsg, rTag);
@@ -1358,12 +1363,12 @@ void TokenParser::ParseError( sal_uInt16 nErrNr, const rtl::OString &rErrMsg, co
}
-ParserMessage::ParserMessage( sal_uInt16 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag )
+ParserMessage::ParserMessage( sal_Int32 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag )
: nErrorNr( PnErrorNr )
, nTagBegin( 0 )
, nTagLength( 0 )
{
- String aLexem( SimpleParser::GetLexem( rTag ) );
+ rtl::OUString aLexem( SimpleParser::GetLexem( rTag ) );
rtl::OStringBuffer aErrorBuffer(rPaErrorText);
aErrorBuffer.append(RTL_CONSTASCII_STRINGPARAM(": "));
aErrorBuffer.append(rtl::OUStringToOString(aLexem, RTL_TEXTENCODING_UTF8));
@@ -1376,14 +1381,14 @@ ParserMessage::ParserMessage( sal_uInt16 PnErrorNr, const rtl::OString &rPaError
}
aErrorText = aErrorBuffer.makeStringAndClear();
nTagBegin = rTag.nPos;
- nTagLength = aLexem.Len();
+ nTagLength = aLexem.getLength();
}
-ParserError::ParserError( sal_uInt16 ErrorNr, const rtl::OString &rErrorText, const TokenInfo &rTag )
+ParserError::ParserError( sal_Int32 ErrorNr, const rtl::OString &rErrorText, const TokenInfo &rTag )
: ParserMessage( ErrorNr, rErrorText, rTag )
{}
-ParserWarning::ParserWarning( sal_uInt16 ErrorNr, const rtl::OString &rErrorText, const TokenInfo &rTag )
+ParserWarning::ParserWarning( sal_Int32 ErrorNr, const rtl::OString &rErrorText, const TokenInfo &rTag )
: ParserMessage( ErrorNr, rErrorText, rTag )
{}
@@ -1409,12 +1414,12 @@ sal_Bool LingTest::IsTagMandatory( TokenInfo const &aToken, TokenId &aMetaTokens
else if ( TAG_COMMONSTART == aTokenId
|| TAG_COMMONEND == aTokenId )
{
- String aTagName = aToken.GetTagName();
- return !(aTagName.EqualsIgnoreCaseAscii( "comment" )
- || aTagName.EqualsIgnoreCaseAscii( "bookmark_value" )
- || aTagName.EqualsIgnoreCaseAscii( "emph" )
- || aTagName.EqualsIgnoreCaseAscii( "item" )
- || aTagName.EqualsIgnoreCaseAscii( "br" ) );
+ rtl::OUString aTagName = aToken.GetTagName();
+ return !(aTagName.equalsIgnoreAsciiCaseAscii( "comment" )
+ || aTagName.equalsIgnoreAsciiCaseAscii( "bookmark_value" )
+ || aTagName.equalsIgnoreAsciiCaseAscii( "emph" )
+ || aTagName.equalsIgnoreAsciiCaseAscii( "item" )
+ || aTagName.equalsIgnoreAsciiCaseAscii( "br" ) );
}
return sal_False;
}
@@ -1474,7 +1479,7 @@ void LingTest::CheckTags( TokenList &aReference, TokenList &aTestee, sal_Bool bF
if ( bFixTags )
{
// we fix only if its a really simple case
- sal_uInt16 nTagCount = 0;
+ sal_Int32 nTagCount = 0;
for ( i=0 ; i < aReference.size() ; i++ )
if ( !aReference[ i ].IsDone() )
nTagCount++;
More information about the Libreoffice-commits
mailing list