libemailfunctions

kasciistricmp.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2004 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "kasciistricmp.h"
00020 
00021 #if ! KDE_IS_VERSION(3,3,89)
00022 
00023 static unsigned char kdepim_ASCIIToLower( unsigned char ch )
00024 {
00025   if ( ch >= 'A' && ch <= 'Z' )
00026     return ch - 'A' + 'a';
00027   else
00028     return ch;
00029 }
00030 
00031 int kdepim_kasciistricmp( const char *str1, const char *str2 )
00032 {
00033   const unsigned char *s1 = (const unsigned char *) str1;
00034   const unsigned char *s2 = (const unsigned char *) str2;
00035   int res;
00036   unsigned char c;
00037 
00038   if ( !s1 || !s2 )
00039     return s1 ? 1 : ( s2 ? -1 : 0 );
00040   for ( ; !( res = ( c = kdepim_ASCIIToLower( *s1 ) ) - kdepim_ASCIIToLower( *s2 ) );
00041         ++s1, ++s2 )
00042     if ( !c ) // strings are equal
00043       break;
00044   return res;
00045 }
00046 
00047 #endif