diff options
author | Joseph Powers <jpowers27@cox.net> | 2011-01-23 07:22:37 -0800 |
---|---|---|
committer | Joseph Powers <jpowers27@cox.net> | 2011-01-23 07:22:37 -0800 |
commit | 2643ec29f7b6b094caa854d4ff3c348036215f64 (patch) | |
tree | 6751b5841e03aa2362fe8b21f28b189b3729888f /l10ntools | |
parent | b0c5af2c62b897c40778929415ec7c56562ebcd1 (diff) |
Remove DECLARE_LIST() Impl_ParserMessageList & TokenListImpl
Diffstat (limited to 'l10ntools')
-rw-r--r-- | l10ntools/inc/gsicheck.hxx | 2 | ||||
-rw-r--r-- | l10ntools/inc/tagtest.hxx | 88 | ||||
-rw-r--r-- | l10ntools/source/gsicheck.cxx | 5 | ||||
-rw-r--r-- | l10ntools/source/tagtest.cxx | 127 |
4 files changed, 90 insertions, 132 deletions
diff --git a/l10ntools/inc/gsicheck.hxx b/l10ntools/inc/gsicheck.hxx index aff04fe1e5e9..660ddadd303a 100644 --- a/l10ntools/inc/gsicheck.hxx +++ b/l10ntools/inc/gsicheck.hxx @@ -76,7 +76,7 @@ public: void SetTitle( ByteString &aNew ) { aTitle = aNew; ReassembleLine(); } ParserMessageList* GetMessageList() { return &aMessages; }; - BOOL HasMessages(){ return ( aMessages.Count() > 0 ); }; + BOOL HasMessages(){ return ( !aMessages.empty() ); }; BOOL IsOK() const { return bOK; } void NotOK(); diff --git a/l10ntools/inc/tagtest.hxx b/l10ntools/inc/tagtest.hxx index e3756d14bfb8..f301a3539bcf 100644 --- a/l10ntools/inc/tagtest.hxx +++ b/l10ntools/inc/tagtest.hxx @@ -32,6 +32,7 @@ #include <tools/string.hxx> #include <tools/list.hxx> #include <hash_map> /* std::hashmap*/ +#include <vector> class GSILine; @@ -40,11 +41,10 @@ typedef USHORT TokenId; #define TOK_INVALIDPOS USHORT( 0xFFFF ) class ParserMessage; +typedef ::std::vector< ParserMessage* > Impl_ParserMessageList; -DECLARE_LIST( Impl_ParserMessageList, ParserMessage* ) class ParserMessageList; - struct equalByteString{ bool operator()( const ByteString& rKey1, const ByteString& rKey2 ) const { return rKey1.CompareTo( rKey2 )==COMPARE_EQUAL; @@ -123,13 +123,21 @@ explicit TokenInfo( TokenId pnId, USHORT nP, String paStr, ParserMessageList }; -class ParserMessageList : public Impl_ParserMessageList +class ParserMessageList { +private: + Impl_ParserMessageList maList; + public: + ~ParserMessageList() { clear(); } void AddError( USHORT nErrorNr, ByteString aErrorText, const TokenInfo &rTag ); void AddWarning( USHORT nErrorNr, ByteString aErrorText, const TokenInfo &rTag ); BOOL HasErrors(); + bool empty() const { return maList.empty(); } + size_t size() const { return maList.size(); } + ParserMessage* operator [] ( size_t i ) { return ( i < maList.size() ) ? maList[ i ] : NULL; } + void clear(); }; @@ -217,62 +225,42 @@ public: #define TAG_UNKNOWN_TAG ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x800 ) -DECLARE_LIST( TokenListImpl, TokenInfo* ) +typedef ::std::vector< TokenInfo* > TokenListImpl; -class TokenList : private TokenListImpl +class TokenList { private: - + TokenListImpl maList; TokenList& operator =( const TokenList& rList ); -// { TokenListImpl::operator =( rList ); return *this; } - public: - using TokenListImpl::Count; - - - TokenList() : TokenListImpl(){}; - ~TokenList(){ Clear(); }; + TokenList() {}; + ~TokenList(){ clear(); }; - void Clear() + size_t size() const { return maList.size(); } + void clear() { - for ( ULONG i = 0 ; i < Count() ; i++ ) - delete TokenListImpl::GetObject( i ); - TokenListImpl::Clear(); + for ( size_t i = 0 ; i < maList.size() ; i++ ) + delete maList[ i ]; + maList.clear(); } - void Insert( TokenInfo p, ULONG nIndex = LIST_APPEND ) - { TokenListImpl::Insert( new TokenInfo(p), nIndex ); } -/* TokenInfo Remove( ULONG nIndex ) - { - TokenInfo aT = GetObject( nIndex ); - delete TokenListImpl::GetObject( nIndex ); - TokenListImpl::Remove( nIndex ); - return aT; - }*/ -// TokenInfo Remove( TokenInfo p ){ return Remove( GetPos( p ) ); } -// TokenInfo GetCurObject() const { return *TokenListImpl::GetCurObject(); } - TokenInfo& GetObject( ULONG nIndex ) const + + void insert( TokenInfo p, size_t nIndex = LIST_APPEND ) { -// if ( TokenListImpl::GetObject(nIndex) ) - return *TokenListImpl::GetObject(nIndex); -// else -// return TokenInfo(); + if ( nIndex < maList.size() ) { + TokenListImpl::iterator it = maList.begin(); + ::std::advance( it, nIndex ); + maList.insert( it, new TokenInfo(p) ); + } else { + maList.push_back( new TokenInfo(p) ); + } } -/* ULONG GetPos( const TokenInfo p ) const + TokenInfo& operator [] ( size_t nIndex ) const { - for ( ULONG i = 0 ; i < Count() ; i++ ) - if ( p == GetObject( i ) ) - return i; - return LIST_ENTRY_NOTFOUND; - }*/ + return *maList[ nIndex ]; + } TokenList( const TokenList& rList ); -/* { - for ( ULONG i = 0 ; i < rList.Count() ; i++ ) - { - Insert( rList.GetObject( i ), LIST_APPEND ); - } - }*/ }; class ParserMessage @@ -363,8 +351,6 @@ class TokenParser public: TokenParser(); void Parse( const String &aCode, ParserMessageList* pList ); -// ParserMessageList& GetErrors(){ return aErrorList; } -// BOOL HasErrors(){ return ( aErrorList.Count() > 0 ); } TokenList& GetTokenList(){ return aParser.GetTokenList(); } }; @@ -381,14 +367,8 @@ public: void CheckReference( GSILine *aReference ); void CheckTestee( GSILine *aTestee, BOOL bHasSourceLine, BOOL bFixTags ); -// ParserMessageList& GetReferenceErrors(){ return aReferenceParser.GetErrors(); } -// BOOL HasReferenceErrors(){ return aReferenceParser.HasErrors(); } - -// ParserMessageList& GetTesteeErrors(){ return aTesteeParser.GetErrors(); } -// BOOL HasTesteeErrors(){ return aTesteeParser.HasErrors(); } - ParserMessageList& GetCompareWarnings(){ return aCompareWarningList; } - BOOL HasCompareWarnings(){ return ( aCompareWarningList.Count() > 0 ); } + BOOL HasCompareWarnings(){ return ( !aCompareWarningList.empty() ); } String GetFixedTestee(){ return aFixedTestee; } }; diff --git a/l10ntools/source/gsicheck.cxx b/l10ntools/source/gsicheck.cxx index f52b7b12fe8d..510ccce21c3a 100644 --- a/l10ntools/source/gsicheck.cxx +++ b/l10ntools/source/gsicheck.cxx @@ -375,10 +375,9 @@ void GSIBlock::PrintList( ParserMessageList *pList, ByteString aPrefix, GSILine *pLine ) /*****************************************************************************/ { - ULONG i; - for ( i = 0 ; i < pList->Count() ; i++ ) + for ( size_t i = 0 ; i < pList->size() ; i++ ) { - ParserMessage *pMsg = pList->GetObject( i ); + ParserMessage *pMsg = (*pList)[ i ]; ByteString aContext; if ( bPrintContext ) { diff --git a/l10ntools/source/tagtest.cxx b/l10ntools/source/tagtest.cxx index 833879ee5ca8..30cbdd190291 100644 --- a/l10ntools/source/tagtest.cxx +++ b/l10ntools/source/tagtest.cxx @@ -551,23 +551,29 @@ String TokenInfo::MakeTag() const void ParserMessageList::AddError( USHORT nErrorNr, ByteString aErrorText, const TokenInfo &rTag ) { - Insert( new ParserError( nErrorNr, aErrorText, rTag ), LIST_APPEND ); + maList.push_back( new ParserError( nErrorNr, aErrorText, rTag ) ); } void ParserMessageList::AddWarning( USHORT nErrorNr, ByteString aErrorText, const TokenInfo &rTag ) { - Insert( new ParserWarning( nErrorNr, aErrorText, rTag ), LIST_APPEND ); + maList.push_back( new ParserWarning( nErrorNr, aErrorText, rTag ) ); } BOOL ParserMessageList::HasErrors() { - USHORT i; - for ( i=0 ; i < Count() ; i++ ) - if ( GetObject( i )->IsError() ) + for ( size_t i = 0, n = maList.size(); i < n; ++i ) + if ( maList[ i ]->IsError() ) return TRUE; return FALSE; } +void ParserMessageList::clear() +{ + for ( size_t i = 0, n = maList.size(); i < n; ++i ) + delete maList[ i ]; + maList.clear(); +} + struct Tag { String GetName() const { return String::CreateFromAscii( pName ); }; @@ -664,7 +670,7 @@ void SimpleParser::Parse( String PaSource ) nPos = 0; aLastToken.Erase(); aNextTag = TokenInfo( TAG_NOMORETAGS, TOK_INVALIDPOS ); - aTokenList.Clear(); + aTokenList.clear(); }; TokenInfo SimpleParser::GetNextToken( ParserMessageList &rErrorList ) @@ -736,24 +742,18 @@ TokenInfo SimpleParser::GetNextToken( ParserMessageList &rErrorList ) if ( aResult.nId == TAG_UNKNOWN_TAG ) aResult = TokenInfo( TAG_UNKNOWN_TAG, nTokenStartPos, aLastToken ); - aTokenList.Insert( aResult, LIST_APPEND ); + aTokenList.insert( aResult ); return aResult; } String SimpleParser::GetNextTokenString( ParserMessageList &rErrorList, USHORT &rTagStartPos ) { -// USHORT nStyle1StartPos = aSource.SearchAscii( "<#", nPos ); USHORT nStyle2StartPos = aSource.SearchAscii( "$[", nPos ); USHORT nStyle3StartPos = aSource.SearchAscii( "\\<", nPos ); USHORT nStyle4StartPos = aSource.SearchAscii( "\\\\", nPos ); // this is only to kick out quoted backslashes rTagStartPos = 0; -/* removing since a \<... is not likely - // check if the tag starts with a letter to avoid things like <> <= ... > - while ( STRING_NOTFOUND != nStyle3StartPos && !( aSource.Copy( nStyle3StartPos+2, 1 ).IsAlphaAscii() || aSource.GetChar( nStyle3StartPos+2 ) == '/' ) ) - nStyle3StartPos = aSource.SearchAscii( "\\<", nStyle3StartPos+1 ); -*/ if ( STRING_NOTFOUND == nStyle2StartPos && STRING_NOTFOUND == nStyle3StartPos ) return String(); // no more tokens @@ -763,19 +763,7 @@ String SimpleParser::GetNextTokenString( ParserMessageList &rErrorList, USHORT & return GetNextTokenString( rErrorList, rTagStartPos ); } -/* if ( nStyle1StartPos < nStyle2StartPos && nStyle1StartPos <= nStyle3StartPos ) // <= to make sure our spechial tags are recognized before all others - { // test for <# ... > style tokens - USHORT nEndPos = aSource.SearchAscii( ">", nStyle1StartPos ); - if ( nEndPos == STRING_NOTFOUND ) - { // Token is incomplete. Skip start and search for better ones - nPos = nStyle1StartPos +2; - return GetNextTokenString( rErrorList, rTagStartPos ); - } - nPos = nEndPos; - rTagStartPos = nStyle1StartPos; - return aSource.Copy( nStyle1StartPos, nEndPos-nStyle1StartPos +1 ).ToUpperAscii(); - } - else*/ if ( nStyle2StartPos < nStyle3StartPos ) + if ( nStyle2StartPos < nStyle3StartPos ) { // test for $[ ... ] style tokens USHORT nEndPos = aSource.SearchAscii( "]", nStyle2StartPos); if ( nEndPos == STRING_NOTFOUND ) @@ -877,11 +865,6 @@ void TokenParser::Parse( const String &aCode, ParserMessageList* pList ) ParseError( 17, "<#UNDER> expected before <#/UNDER>.", aTag ); } break; -/* case TAG_MISSPARENTHESIS: - { - ParseError( 14, "missing closing parenthesis '>'", aTag ); - } - break;*/ case TAG_AEND: { ParseError( 5, "Extra Tag <#AEND>. <#AVIS> or <#AHID> expected.", aTag ); @@ -1422,13 +1405,9 @@ BOOL LingTest::IsTagMandatory( TokenInfo const &aToken, TokenId &aMetaTokens ) void LingTest::CheckTags( TokenList &aReference, TokenList &aTestee, BOOL bFixTags ) { - ULONG i=0,j=0; + size_t i=0,j=0; // Clean old Warnings - while ( aCompareWarningList.Count() ) - { - delete aCompareWarningList.GetCurObject(); - aCompareWarningList.Remove(); - } + aCompareWarningList.clear(); /* in xml tags, do not require the following tags comment @@ -1440,35 +1419,35 @@ void LingTest::CheckTags( TokenList &aReference, TokenList &aTestee, BOOL bFixTa // filter uninteresting Tags TokenId aMetaTokens = 0; - for ( i=0 ; i < aReference.Count() ; i++ ) + for ( i=0 ; i < aReference.size() ; i++ ) { - if ( !IsTagMandatory( aReference.GetObject( i ), aMetaTokens ) ) - aReference.GetObject( i ).SetDone(); + if ( !IsTagMandatory( aReference[ i ], aMetaTokens ) ) + aReference[ i ].SetDone(); } aMetaTokens = 0; - for ( i=0 ; i < aTestee.Count() ; i++ ) + for ( i=0 ; i < aTestee.size() ; i++ ) { - if ( !IsTagMandatory( aTestee.GetObject( i ), aMetaTokens ) ) - aTestee.GetObject( i ).SetDone(); + if ( !IsTagMandatory( aTestee[ i ], aMetaTokens ) ) + aTestee[ i ].SetDone(); } // remove all matching tags - for ( i=0 ; i < aReference.Count() ; i++ ) + for ( i=0 ; i < aReference.size() ; i++ ) { - if ( aReference.GetObject( i ).IsDone() ) + if ( aReference[ i ].IsDone() ) continue; BOOL bTagFound = FALSE; - for ( j=0 ; j < aTestee.Count() && !bTagFound ; j++ ) + for ( j=0 ; j < aTestee.size() && !bTagFound ; j++ ) { - if ( aTestee.GetObject( j ).IsDone() ) + if ( aTestee[ j ].IsDone() ) continue; - if ( aReference.GetObject( i ).MatchesTranslation( aTestee.GetObject( j ), FALSE, aCompareWarningList ) ) + if ( aReference[ i ].MatchesTranslation( aTestee[ j ], FALSE, aCompareWarningList ) ) { - aReference.GetObject( i ).SetDone(); - aTestee.GetObject( j ).SetDone(); + aReference[ i ].SetDone(); + aTestee[ j ].SetDone(); bTagFound = TRUE; } } @@ -1480,62 +1459,62 @@ void LingTest::CheckTags( TokenList &aReference, TokenList &aTestee, BOOL bFixTa { // we fix only if its a really simple case USHORT nTagCount = 0; - for ( i=0 ; i < aReference.Count() ; i++ ) - if ( !aReference.GetObject( i ).IsDone() ) + for ( i=0 ; i < aReference.size() ; i++ ) + if ( !aReference[ i ].IsDone() ) nTagCount++; if ( nTagCount > 1 ) bCanFix = FALSE; nTagCount = 0; - for ( i=0 ; i < aTestee.Count() ; i++ ) - if ( !aTestee.GetObject( i ).IsDone() ) + for ( i=0 ; i < aTestee.size() ; i++ ) + if ( !aTestee[ i ].IsDone() ) nTagCount++; if ( nTagCount > 1 ) bCanFix = FALSE; } // generate errors for tags that have differing attributes - for ( i=0 ; i < aReference.Count() ; i++ ) + for ( i=0 ; i < aReference.size() ; i++ ) { - if ( aReference.GetObject( i ).IsDone() ) + if ( aReference[ i ].IsDone() ) continue; BOOL bTagFound = FALSE; - for ( j=0 ; j < aTestee.Count() && !bTagFound ; j++ ) + for ( j=0 ; j < aTestee.size() && !bTagFound ; j++ ) { - if ( aTestee.GetObject( j ).IsDone() ) + if ( aTestee[ j ].IsDone() ) continue; - if ( aReference.GetObject( i ).MatchesTranslation( aTestee.GetObject( j ), TRUE, aCompareWarningList, bCanFix && bFixTags ) ) + if ( aReference[ i ].MatchesTranslation( aTestee[ j ], TRUE, aCompareWarningList, bCanFix && bFixTags ) ) { - aReference.GetObject( i ).SetDone(); - aTestee.GetObject( j ).SetDone(); + aReference[ i ].SetDone(); + aTestee[ j ].SetDone(); bTagFound = TRUE; } } } // list remaining tags as errors - for ( i=0 ; i < aReference.Count() ; i++ ) + for ( i=0 ; i < aReference.size() ; i++ ) { - if ( aReference.GetObject( i ).IsDone() ) + if ( aReference[ i ].IsDone() ) continue; - aCompareWarningList.AddError( 20, "Missing Tag in Translation", aReference.GetObject( i ) ); + aCompareWarningList.AddError( 20, "Missing Tag in Translation", aReference[ i ] ); } - for ( i=0 ; i < aTestee.Count() ; i++ ) + for ( i=0 ; i < aTestee.size() ; i++ ) { - if ( aTestee.GetObject( i ).IsDone() ) + if ( aTestee[ i ].IsDone() ) continue; - aCompareWarningList.AddError( 21, "Extra Tag in Translation", aTestee.GetObject( i ) ); + aCompareWarningList.AddError( 21, "Extra Tag in Translation", aTestee[ i ] ); } - for ( i=0 ; i < aReference.Count() ; i++ ) - aReference.GetObject( i ).SetDone( FALSE ); + for ( i=0 ; i < aReference.size() ; i++ ) + aReference[ i ].SetDone( FALSE ); - for ( i=0 ; i < aTestee.Count() ; i++ ) - aTestee.GetObject( i ).SetDone( FALSE ); + for ( i=0 ; i < aTestee.size() ; i++ ) + aTestee[ i ].SetDone( FALSE ); } void LingTest::CheckReference( GSILine *aReference ) @@ -1557,12 +1536,12 @@ void LingTest::CheckTestee( GSILine *aTestee, BOOL bHasSourceLine, BOOL bFixTags BOOL bFixesDone = FALSE; // count backwards to allow replacing from right to left int i; - for ( i=aTesteeTokens.Count()-1 ; i>=0 ; i-- ) + for ( i = aTesteeTokens.size() ; i > 0 ; ) { - if ( aTesteeTokens.GetObject( i ).HasBeenFixed() ) + if ( aTesteeTokens[ --i ].HasBeenFixed() ) { bFixesDone = TRUE; - aFixedTestee.Replace( aTesteeTokens.GetObject( i ).nPos, aTesteeTokens.GetObject( i ).aTokenString.Len(), aTesteeTokens.GetObject( i ).MakeTag() ); + aFixedTestee.Replace( aTesteeTokens[ i ].nPos, aTesteeTokens[ i ].aTokenString.Len(), aTesteeTokens[ i ].MakeTag() ); } } if ( bFixesDone ) |