libemailfunctions

kasciistricmp.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2004 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include "kasciistricmp.h"
20
21#if ! KDE_IS_VERSION(3,3,89)
22
23static unsigned char tdepim_ASCIIToLower( unsigned char ch )
24{
25 if ( ch >= 'A' && ch <= 'Z' )
26 return ch - 'A' + 'a';
27 else
28 return ch;
29}
30
31int tdepim_kasciistricmp( const char *str1, const char *str2 )
32{
33 const unsigned char *s1 = (const unsigned char *) str1;
34 const unsigned char *s2 = (const unsigned char *) str2;
35 int res;
36 unsigned char c;
37
38 if ( !s1 || !s2 )
39 return s1 ? 1 : ( s2 ? -1 : 0 );
40 for ( ; !( res = ( c = tdepim_ASCIIToLower( *s1 ) ) - tdepim_ASCIIToLower( *s2 ) );
41 ++s1, ++s2 )
42 if ( !c ) // strings are equal
43 break;
44 return res;
45}
46
47#endif