istring.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 1997-2001 Id Software, Inc.
00003 Copyright (C) 2003 The Pentagram Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00013 
00014 See the GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 */
00021 
00022 // istring.cpp -- case insensitive stl strings
00023 
00024 #include "pent_include.h"
00025 #include "istring.h"
00026 
00027 namespace Pentagram {
00028 
00029 int strncasecmp (const char *s1, const char *s2, uint32 length)
00030 {
00031         uint32  c1, c2;
00032         
00033         do
00034         {
00035                 c1 = *s1++;
00036                 c2 = *s2++;
00037 
00038                 if (!length--)
00039                         return 0;               // strings are equal until end point
00040                 
00041                 if (c1 != c2)
00042                 {
00043                         if (c1 >= 'a' && c1 <= 'z')
00044                                 c1 -= ('a' - 'A');
00045                         if (c2 >= 'a' && c2 <= 'z')
00046                                 c2 -= ('a' - 'A');
00047                         if (c1 != c2)
00048                                 return (c1 < c2) ? -1 : 1; // strings not equal
00049                 }
00050         } while (c1);
00051         
00052         return 0;               // strings are equal
00053 }
00054 
00055 int strcasecmp (const char *s1, const char *s2)
00056 {
00057         return strncasecmp (s1, s2, 2147483647);
00058 }
00059 
00060 #ifndef UNDER_CE
00061 
00062 bool ichar_traits::eq(const char_type & c1, const char_type & c2)
00063 {
00064         uint32 c3 = c1;
00065         uint32 c4 = c2;
00066         if (c3 >= 'a' && c3 <= 'z')
00067                 c3 -= ('a' - 'A');
00068         if (c4 >= 'a' && c4 <= 'z')
00069                 c4 -= ('a' - 'A');
00070         return c3 == c4;
00071 }
00072 
00073 bool ichar_traits::lt(const char_type & c1, const char_type & c2)
00074 {
00075         uint32 c3 = c1;
00076         uint32 c4 = c2;
00077         if (c3 >= 'a' && c3 <= 'z')
00078                 c3 -= ('a' - 'A');
00079         if (c4 >= 'a' && c4 <= 'z')
00080                 c4 -= ('a' - 'A');
00081         return c3 < c4;         
00082 }
00083 
00084 int ichar_traits::compare(const char_type * s1, const char_type * s2, size_t length)
00085 {
00086         return strncasecmp(s1, s2, length);
00087 }
00088 
00089 #endif
00090 
00091 };
00092 

Generated on Fri Jul 27 22:27:20 2007 for pentagram by  doxygen 1.4.7