KDECore
kascii.cpp
Go to the documentation of this file.
00001 /* -*- c++ -*- 00002 Copyright (c) 2005 Ingo Kloecker <kloecker@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 as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "kascii.h" 00021 00022 int kasciistricmp( const char *str1, const char *str2 ) 00023 { 00024 const unsigned char *s1 = (const unsigned char *)str1; 00025 const unsigned char *s2 = (const unsigned char *)str2; 00026 int res; 00027 unsigned char c1, c2; 00028 00029 if ( !s1 || !s2 ) 00030 return s1 ? 1 : (s2 ? -1 : 0); 00031 if ( !*s1 || !*s2 ) 00032 return *s1 ? 1 : (*s2 ? -1 : 0); 00033 for (;*s1; ++s1, ++s2) { 00034 c1 = *s1; c2 = *s2; 00035 if (c1 >= 'A' && c1 <= 'Z') 00036 c1 += 'a' - 'A'; 00037 if (c2 >= 'A' && c2 <= 'Z') 00038 c2 += 'a' - 'A'; 00039 00040 if ((res = c1 - c2)) 00041 break; 00042 } 00043 return *s1 ? res : (*s2 ? -1 : 0); 00044 } 00045 00050 static unsigned char ASCIIToLower( unsigned char ch ) 00051 { 00052 if ( ch >= 'A' && ch <= 'Z' ) 00053 return ch - 'A' + 'a'; 00054 else 00055 return ch; 00056 } 00057 00058 char * kAsciiToLower( char *s ) 00059 { 00060 if ( !s ) 00061 return 0; 00062 for ( unsigned char *p = (unsigned char *) s; *p; ++p ) 00063 *p = ASCIIToLower( *p ); 00064 return s; 00065 } 00066 00071 static unsigned char ASCIIToUpper( unsigned char ch ) 00072 { 00073 if ( ch >= 'a' && ch <= 'z' ) 00074 return ch - 'a' + 'A'; 00075 else 00076 return ch; 00077 } 00078 00079 char * kAsciiToUpper( char *s ) 00080 { 00081 if ( !s ) 00082 return 0; 00083 for ( unsigned char *p = (unsigned char *) s; *p; ++p ) 00084 *p = ASCIIToUpper( *p ); 00085 return s; 00086 } 00087
KDE 4.6 API Reference