Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, March 2002
[BUG] QString::localAwareCompare


Message 1 in thread

It seems to be a bug, because replacing this method with QString::compare 
produced proper results.

I have two QStringList's which indexes are dependent from each other. It may
look quite strange, but it's done only on developer stage - it's for index 
generating - later it's better to have two QStringList's.

void CHDataIndex::InsertItem( const QString& a_rUrl, const QString& 	
			a_rKeyWord, const QString& a_rTitle )
{
	QStringList::iterator		u	= m_aUrls.begin();
	QStringList::iterator		k	= m_aKeywords.begin();
	int				cmp = 0;
	QString				keyword = a_rKeyWord.lower();
	
	for ( ; k != m_aKeywords.end() && u != m_aUrls.end() && ; ++k, ++u )
	{
//		cmp = QString::localeAwareCompare( (*k).lower(), keyword );
		cmp = QString::compare( (*k).lower(), keyword );

		if ( cmp > 0 )
		{
			m_aUrls.insert( u, a_rUrl );
			m_aKeywords.insert( k, a_rKeyWord );
			break;
		}
	}
	
	if ( cmp <= 0 )		// They haven't been inserted in loop.
	{
		m_aKeywords.append( a_rKeyWord );
		m_aUrls.append( a_rUrl );
	}
}

I don't know why, but all item's are multiplied 6 times when 
localAwareCompare is used. Everything works fine with simple compare.

What's more strange: doc says localAwareCompare = compare on OS != Windows.
(I'm doing this job on RH Linux) :-/

-- 
 [ signature omitted ] 

Message 2 in thread

Mariusz Lotko wrote:

> It seems to be a bug, because replacing this method with QString::compare
> produced proper results.
>
> I have two QStringList's which indexes are dependent from each other. It may
> look quite strange, but it's done only on developer stage - it's for index
> generating - later it's better to have two QStringList's.
>
> void CHDataIndex::InsertItem( const QString& a_rUrl, const QString&
>                         a_rKeyWord, const QString& a_rTitle )
> {
>         QStringList::iterator           u       = m_aUrls.begin();
>         QStringList::iterator           k       = m_aKeywords.begin();
>         int                             cmp = 0;
>         QString                         keyword = a_rKeyWord.lower();
>
>         for ( ; k != m_aKeywords.end() && u != m_aUrls.end() && ; ++k, ++u )
>

Haven't you cut something, what could change your condition? (k !=
m_aKeywords.end() && u != m_aUrls.end() && WHAT?)

JK

>       {
> //              cmp = QString::localeAwareCompare( (*k).lower(), keyword );
>                 cmp = QString::compare( (*k).lower(), keyword );
>
>                 if ( cmp > 0 )
>                 {
>                         m_aUrls.insert( u, a_rUrl );
>                         m_aKeywords.insert( k, a_rKeyWord );
>                         break;
>                 }
>         }
>
>         if ( cmp <= 0 )         // They haven't been inserted in loop.
>         {
>                 m_aKeywords.append( a_rKeyWord );
>                 m_aUrls.append( a_rUrl );
>         }
> }
>
> I don't know why, but all item's are multiplied 6 times when
> localAwareCompare is used. Everything works fine with simple compare.
>
> What's more strange: doc says localAwareCompare = compare on OS != Windows.
> (I'm doing this job on RH Linux) :-/
>
> --
> Mariusz Lotko
> Pruftechnik Technology sp. z o. o.
> http://www.pruftechnik.com.pl/
>
> --
> List archive and information: http://qt-interest.trolltech.com


Message 3 in thread

On Mon 18. March 2002 11:11, you wrote:
> >         for ( ; k != m_aKeywords.end() && u != m_aUrls.end() && ; ++k,
> > ++u )
>
> Haven't you cut something, what could change your condition? (k !=
> m_aKeywords.end() && u != m_aUrls.end() && WHAT?)

And nothing. Too much copy & paste :-)

-- 
 [ signature omitted ] 

Message 4 in thread

Doesn't QStringList::insert invalidate iterators?

All I can offer is:

u = m_aUrls.insert( u, a_rUrl );
K = m_aKeywords.insert( k, a_rKeyWord );

-- Paul.

> -----Original Message-----
> From: Mariusz Lotko [mailto:mariusz.lotko@pruftechnik.com.pl] 
> Sent: 18 March 2002 08:33
> To: qt-interest@trolltech.com
> Subject: [BUG] QString::localAwareCompare
> 
> 
> It seems to be a bug, because replacing this method with 
> QString::compare 
> produced proper results.
> 
> I have two QStringList's which indexes are dependent from 
> each other. It may look quite strange, but it's done only on 
> developer stage - it's for index 
> generating - later it's better to have two QStringList's.
> 
> void CHDataIndex::InsertItem( const QString& a_rUrl, const QString& 	
> 			a_rKeyWord, const QString& a_rTitle )
> {
> 	QStringList::iterator		u	= m_aUrls.begin();
> 	QStringList::iterator		k	= m_aKeywords.begin();
> 	int				cmp = 0;
> 	QString				keyword = a_rKeyWord.lower();
> 	
> 	for ( ; k != m_aKeywords.end() && u != m_aUrls.end() && 
> ; ++k, ++u )
> 	{
> //		cmp = QString::localeAwareCompare( 
> (*k).lower(), keyword );
> 		cmp = QString::compare( (*k).lower(), keyword );
> 
> 		if ( cmp > 0 )
> 		{
> 			m_aUrls.insert( u, a_rUrl );
> 			m_aKeywords.insert( k, a_rKeyWord );
> 			break;
> 		}
> 	}
> 	
> 	if ( cmp <= 0 )		// They haven't been inserted in loop.
> 	{
> 		m_aKeywords.append( a_rKeyWord );
> 		m_aUrls.append( a_rUrl );
> 	}
> }
> 
> I don't know why, but all item's are multiplied 6 times when 
> localAwareCompare is used. Everything works fine with simple compare.
> 
> What's more strange: doc says localAwareCompare = compare on 
> OS != Windows. (I'm doing this job on RH Linux) :-/
> 
> -- 
> Mariusz Lotko
> Pruftechnik Technology sp. z o. o. http://www.pruftechnik.com.pl/
> 
> --
> List archive and information: http://qt-interest.trolltech.com
> 


Message 5 in thread

On Mon 18. March 2002 10:10, you wrote:
>
> All I can offer is:
>
> u = m_aUrls.insert( u, a_rUrl );
> K = m_aKeywords.insert( k, a_rKeyWord );

I don't think it matters in this case. What should I update iterators' values 
if I won't use them anymore? (break is called).

Anyway, according to documentation, iterator to just added value is returned.
It doesn't have sense in this case.

And I'll repeat the most important: with compare it works just fine, only 
with localeAwareCompare fails. It's quite strange, because I sort English 
strings.


> > void CHDataIndex::InsertItem( const QString& a_rUrl, const QString&
> > 			a_rKeyWord, const QString& a_rTitle )
> > {
> > 	QStringList::iterator		u	= m_aUrls.begin();
> > 	QStringList::iterator		k	= m_aKeywords.begin();
> > 	int				cmp = 0;
> > 	QString				keyword = a_rKeyWord.lower();
> >
> > 	for ( ; k != m_aKeywords.end() && u != m_aUrls.end() &&
> > ; ++k, ++u )
> > 	{
> > //		cmp = QString::localeAwareCompare(
> > (*k).lower(), keyword );
> > 		cmp = QString::compare( (*k).lower(), keyword );
> >
> > 		if ( cmp > 0 )
> > 		{
> > 			m_aUrls.insert( u, a_rUrl );
> > 			m_aKeywords.insert( k, a_rKeyWord );
> > 			break;
> > 		}
> > 	}
> >
> > 	if ( cmp <= 0 )		// They haven't been inserted in loop.
> > 	{
> > 		m_aKeywords.append( a_rKeyWord );
> > 		m_aUrls.append( a_rUrl );
> > 	}
> > }
> >


-- 
 [ signature omitted ]