Fwd: case-convertion problems with locale-dependent functions

Ingo Klöcker kloecker at kde.org
Sat Nov 20 22:40:09 GMT 2004


On Saturday 20 November 2004 22:31, Ingo Klöcker wrote:
> Hi,
>
> this is a kde-core issue. I've removed the kdepim-specific patch.
> FWIW, I propose to call the function kasciistricmp (instead of
> kstricmp) because it's only useful for making case-independent
> comparisons of ASCII strings.

While adding this to libkdepim (for KDE 3.3 compatibility) I noticed 
that the function returns 0 for kstricmp( "Test", "TestTest" ). The 
following version should behave correctly:

unsigned char kAsciiToLower( unsigned char ch )
{
  if ( ch >= 'A' && ch <= 'Z' )
    return ch + 'a' - 'A';
  else
    return ch;
}

int kAsciiStrICmp( const char *str1, const char *str2 )
{
  const unsigned char *s1 = (const unsigned char *) str1;
  const unsigned char *s2 = (const unsigned char *) str2;
  int res;
  unsigned char c;

  if ( !s1 || !s2 )
    return s1 ? 1 : ( s2 ? -1 : 0 );
  for ( ; !( res = ( c = kAsciiToLower( *s1 ) ) - kAsciiToLower( *s2 ) );
        ++s1, ++s2 )
    if ( !c ) // strings are equal
      break;
  return res;
}

Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20041120/c65fdb9c/attachment.sig>


More information about the kde-core-devel mailing list