istring.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2004 The Pentagram Team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program 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.  
00012 
00013 See the GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 */
00020 
00021 // istring.h -- case insensitive stl strings
00022 
00023 #ifndef ISTRING_H
00024 #define ISTRING_H
00025 
00026 #include <string>
00027 
00028 namespace Pentagram {
00029 
00030 int strcasecmp (const char *s1, const char *s2);
00031 int strncasecmp (const char *s1, const char *s2, uint32 length);
00032 
00033 #ifndef UNDER_CE
00034 
00036 struct ichar_traits : public std::char_traits<char>
00037 {
00039         static bool eq(const char_type & c1, const char_type & c2);
00040 
00043         static bool lt(const char_type & c1, const char_type & c2);
00044 
00046         static int compare(const char_type * s1, const char_type * s2, size_t length);
00047 };
00048 
00049 template<class _Elem,
00050         class _Traits = std::char_traits<_Elem>,
00051         class _Ax = std::allocator<_Elem> >
00052         class pent_string
00053                 : public std::basic_string<_Elem, _Traits, _Ax>
00054         {       // null-terminated transparent array of elements
00055 public:
00056         typedef pent_string<_Elem, _Traits, _Ax> _Myt;
00057         typedef std::basic_string<_Elem, _Traits, _Ax> _Mybase;
00058         typedef _Ax _Alloc;
00059         typedef typename _Alloc::size_type size_type;
00060         typedef typename _Alloc::difference_type difference_type;
00061         typedef typename _Alloc::pointer _Tptr;
00062         typedef typename _Alloc::const_pointer _Ctptr;
00063         typedef _Tptr pointer;
00064         typedef _Ctptr const_pointer;
00065         typedef typename _Alloc::reference reference;
00066         typedef typename _Alloc::const_reference const_reference;
00067         typedef typename _Alloc::value_type value_type;
00068 
00069         typedef ichar_traits traits_type;
00070 
00071         pent_string() 
00072                 : _Mybase()
00073                 {
00074                 }
00075 
00076         explicit pent_string(const _Alloc& _Al)
00077                 : _Mybase(_Al)
00078                 {
00079                 }
00080 
00081         pent_string(const _Mybase& _Right)
00082                 : _Mybase(_Right)
00083                 {       // construct by copying _Right
00084                 }
00085 
00086         pent_string(const _Mybase& _Right, size_type _Roff,
00087                 size_type _Count = _Mybase::npos)
00088                 : _Mybase(_Right, _Roff, _Count)
00089                 {       // construct from _Right [_Roff, _Roff + _Count)
00090                 }
00091 
00092         pent_string(const _Mybase& _Right, size_type _Roff, size_type _Count,
00093                 const _Alloc& _Al)
00094                 : _Mybase(_Right, _Roff, _Count, _Al)
00095                 {       // construct from _Right [_Roff, _Roff + _Count) with allocator
00096                 }
00097 
00098         pent_string(const _Elem *_Ptr, size_type _Count)
00099                 : _Mybase(_Ptr, _Count)
00100                 {       // construct from [_Ptr, _Ptr + _Count)
00101                 }
00102 
00103         pent_string(const _Elem *_Ptr, size_type _Count, const _Alloc& _Al)
00104                 : _Mybase(_Ptr, _Count, _Al)
00105                 {       // construct from [_Ptr, _Ptr + _Count) with allocator
00106                 }
00107 
00108         pent_string(const _Elem *_Ptr)
00109                 : _Mybase(_Ptr)
00110                 {       // construct from [_Ptr, <null>)
00111                 }
00112 
00113         pent_string(const _Elem *_Ptr, const _Alloc& _Al)
00114                 : _Mybase(_Ptr, _Al)
00115                 {       // construct from [_Ptr, <null>) with allocator
00116                 }
00117 
00118         pent_string(size_type _Count, _Elem _Ch)
00119                 : _Mybase(_Count, _Ch)
00120                 {       // construct from _Count * _Ch
00121                 }
00122 
00123         pent_string(size_type _Count, _Elem _Ch, const _Alloc& _Al)
00124                 : _Mybase(_Count, _Ch, _Al)
00125                 {       // construct from _Count * _Ch with allocator
00126                 }
00127 
00128         template<class _It>
00129                 pent_string(_It _First, _It _Last)
00130                 : _Mybase(_First, _Last)
00131                 {       // construct from [_First, _Last)
00132                 }
00133 
00134         template<class _It>
00135                 pent_string(_It _First, _It _Last, const _Alloc& _Al)
00136                 : _Mybase(_First, _Last, _Al)
00137                 {       // construct from [_First, _Last) with allocator
00138                 }
00139 
00140         //
00141         // Overloaded operators (will return the correct type)
00142         //
00143 
00144         _Myt& operator=(const _Myt& _Right)
00145                 {       // assign _Right
00146                 assign(_Right);
00147                 return (*this);
00148                 }
00149 
00150         _Myt& operator=(const _Elem *_Ptr)
00151                 {       // assign [_Ptr, <null>)
00152                 assign(_Ptr);
00153                 return (*this);
00154                 }
00155 
00156         _Myt& operator=(_Elem _Ch)
00157                 {       // assign 1 * _Ch
00158                 assign(1, _Ch);
00159                 return (*this);
00160                 }
00161 
00162         _Myt& operator+=(const _Myt& _Right)
00163                 {       // append _Right
00164                 append(_Right);
00165                 return (*this);
00166                 }
00167 
00168         _Myt& operator+=(const _Elem *_Ptr)
00169                 {       // append [_Ptr, <null>)
00170                 append(_Ptr);
00171                 return (*this);
00172                 }
00173 
00174         _Myt& operator+=(_Elem _Ch)
00175                 {       // append 1 * _Ch
00176                 append(static_cast<size_type>(1), _Ch);
00177                 return (*this);
00178                 }
00179 
00180         // New case insensitive compare functions
00181 
00182         int compare(const _Mybase& _Right) const
00183                 {       // compare [0, _Mysize) with _Right
00184                 return (compare(0, this->size(), _Right.data(), _Right.size()));
00185                 }
00186 
00187         int compare(size_type _Off, size_type _N0,
00188                 const _Mybase& _Right) const
00189                 {       // compare [_Off, _Off + _N0) with _Right
00190                 return (compare(_Off, _N0, _Right, 0, _Mybase::npos));
00191                 }
00192 
00193         int compare(size_type _Off, size_type _N0, const _Myt& _Right,
00194                 size_type _Roff, size_type _Count) const
00195                 {       // compare [_Off, _Off + _N0) with _Right [_Roff, _Roff + _Count)
00196                 if (_Right.size() < _Roff)
00197                         return 0; //_String_base::_Xran();      // _Off off end
00198                 if (_Right.size() - _Roff < _Count)
00199                         _Count = _Right.size() - _Roff; // trim _Count to size
00200                 return (compare(_Off, _N0, _Right.data() + _Roff, _Count));
00201                 }
00202 
00203         int compare(const _Elem *_Ptr) const
00204                 {       // compare [0, _Mysize) with [_Ptr, <null>)
00205                 return (compare(0, this->size(), _Ptr, _Traits::length(_Ptr)));
00206                 }
00207 
00208         int compare(size_type _Off, size_type _N0, const _Elem *_Ptr) const
00209                 {       // compare [_Off, _Off + _N0) with [_Ptr, <null>)
00210                 return (compare(_Off, _N0, _Ptr, _Traits::length(_Ptr)));
00211                 }
00212 
00213         int compare(size_type _Off, size_type _N0, const _Elem *_Ptr,
00214                 size_type _Count) const
00215                 {       // compare [_Off, _Off + _N0) with [_Ptr, _Ptr + _Count)
00216                 if (this->size() < _Off)
00217                         return 0; //_String_base::_Xran();      // _Off off end
00218                 if (this->size() - _Off < _N0)
00219                         _N0 = this->size() - _Off;      // trim _N0 to size
00220 
00221                 size_type _Ans = _N0 == 0 ? 0
00222                         : ichar_traits::compare(this->data() + _Off, _Ptr,
00223                                 _N0 < _Count ? _N0 : _Count);
00224                 return (_Ans != 0 ? static_cast<int>(_Ans) : _N0 < _Count ? -1
00225                         : _N0 == _Count ? 0 : +1);
00226                 }
00227         };
00228 
00230 //template pent_string<char>;
00231 typedef pent_string<char> istring;
00232 
00233 inline pent_string<char> operator+(
00234                 const pent_string<char> & _Left,
00235                 const pent_string<char> & _Right)
00236         {       // return string + string
00237         return (pent_string<char>(_Left) += _Right);
00238         }
00239 
00240 inline pent_string<char> operator+(
00241                 const pent_string<char> & _Left,
00242                 const std::basic_string<char>& _Right)
00243         {       // return string + string
00244         return (pent_string<char>(_Left) += _Right);
00245         }
00246 
00247 inline pent_string<char> operator+(
00248                 const std::basic_string<char>& _Left,
00249                 const pent_string<char> & _Right)
00250         {       // return string + string
00251         return (pent_string<char>(_Left) += _Right);
00252         }
00253 
00254 inline pent_string<char> operator+(
00255                 const char *_Left,
00256                 const pent_string<char>& _Right)
00257         {       // return NTCS + string
00258         return (pent_string<char>(_Left) += _Right);
00259         }
00260 
00261 inline pent_string<char> operator+(
00262                 const char _Left,
00263                 const pent_string<char>& _Right)
00264         {       // return character + string
00265         return (pent_string<char>(1, _Left) += _Right);
00266         }
00267 
00268 inline pent_string<char> operator+(
00269                 const pent_string<char>& _Left,
00270                 const char *_Right)
00271         {       // return string + NTCS
00272         return (pent_string<char>(_Left) += _Right);
00273         }
00274 
00275 inline pent_string<char> operator+(
00276                 const pent_string<char>& _Left,
00277                 const char _Right)
00278         {       // return string + character
00279         return (pent_string<char>(_Left) += _Right);
00280         }
00281 
00282 
00283 inline bool operator==(
00284                 const pent_string<char>& _Left,
00285                 const pent_string<char>& _Right)
00286         {       // test for string equality
00287         return (_Left.compare(_Right) == 0);
00288         }
00289 
00290 inline bool operator==(
00291                 const pent_string<char>& _Left,
00292                 const std::basic_string<char>& _Right)
00293         {       // test for string equality
00294         return (_Left.compare(_Right) == 0);
00295         }
00296 
00297 inline bool operator==(
00298                 const std::basic_string<char>& _Left,
00299                 const pent_string<char>& _Right)
00300         {       // test for string equality
00301         return (_Right.compare(_Left) == 0);
00302         }
00303 
00304 inline bool operator==(
00305                 const char * _Left,
00306                 const pent_string<char>& _Right)
00307         {       // test for NTCS vs. string equality
00308         return (_Right.compare(_Left) == 0);
00309         }
00310 
00311 inline bool operator==(
00312                 const pent_string<char>& _Left,
00313                 const char *_Right)
00314         {       // test for string vs. NTCS equality
00315         return (_Left.compare(_Right) == 0);
00316         }
00317 
00318 inline bool operator!=(
00319                 const pent_string<char>& _Left,
00320                 const pent_string<char>& _Right)
00321         {       // test for string inequality
00322         return (!(_Left == _Right));
00323         }
00324 
00325 inline bool operator!=(
00326                 const pent_string<char>& _Left,
00327                 const std::basic_string<char>& _Right)
00328         {       // test for string inequality
00329         return (!(_Left == _Right));
00330         }
00331 
00332 inline bool operator!=(
00333                 const std::basic_string<char>& _Left,
00334                 const pent_string<char>& _Right)
00335         {       // test for string inequality
00336         return (!(_Left == _Right));
00337         }
00338 
00339 inline bool operator!=(
00340                 const char *_Left,
00341                 const pent_string<char>& _Right)
00342         {       // test for NTCS vs. string inequality
00343         return (!(_Left == _Right));
00344         }
00345 
00346 inline bool operator!=(
00347                 const pent_string<char>& _Left,
00348                 const char *_Right)
00349         {       // test for string vs. NTCS inequality
00350         return (!(_Left == _Right));
00351         }
00352 
00353 
00354 
00355 inline bool operator<(
00356                 const pent_string<char>& _Left,
00357                 const pent_string<char>& _Right)
00358         {       // test if string < string
00359         return (_Left.compare(_Right) < 0);
00360         }
00361 
00362 inline bool operator<(
00363                 const pent_string<char>& _Left,
00364                 const std::basic_string<char>& _Right)
00365         {       // test if string < string
00366         return (_Left.compare(_Right) < 0);
00367         }
00368 
00369 inline bool operator<(
00370                 const std::basic_string<char>& _Left,
00371                 const pent_string<char>& _Right)
00372         {       // test if string < string
00373         return (_Right.compare(_Left) > 0);
00374         }
00375 
00376 inline bool operator<(
00377                 const char * _Left,
00378                 const pent_string<char>& _Right)
00379         {       // test if NTCS < string
00380         return (_Right.compare(_Left) > 0);
00381         }
00382 
00383 inline bool operator<(
00384                 const pent_string<char>& _Left,
00385                 const char *_Right)
00386         {       // test if string < NTCS
00387         return (_Left.compare(_Right) < 0);
00388         }
00389 
00390 
00391 
00392 inline bool operator>(
00393                 const pent_string<char>& _Left,
00394                 const pent_string<char>& _Right)
00395         {       // test if string > string
00396         return (_Right < _Left);
00397         }
00398 
00399 inline bool operator>(
00400                 const pent_string<char>& _Left,
00401                 const std::basic_string<char>& _Right)
00402         {       // test if string > string
00403         return (_Right < _Left);
00404         }
00405 
00406 inline bool operator>(
00407                 const std::basic_string<char>& _Left,
00408                 const pent_string<char>& _Right)
00409         {       // test if string > string
00410         return (_Right < _Left);
00411         }
00412 
00413 inline bool operator>(
00414                 const char * _Left,
00415                 const pent_string<char>& _Right)
00416         {       // test if NTCS > string
00417         return (_Right < _Left);
00418         }
00419 
00420 inline bool operator>(
00421                 const pent_string<char>& _Left,
00422                 const char *_Right)
00423         {       // test if string > NTCS
00424         return (_Right < _Left);
00425         }
00426 
00427 
00428 inline bool operator<=(
00429                 const pent_string<char>& _Left,
00430                 const pent_string<char>& _Right)
00431         {       // test if string <= string
00432         return (!(_Right < _Left));
00433         }
00434 
00435 inline bool operator<=(
00436                 const pent_string<char>& _Left,
00437                 const std::basic_string<char>& _Right)
00438         {       // test if string <= string
00439         return (!(_Right < _Left));
00440         }
00441 
00442 inline bool operator<=(
00443                 const std::basic_string<char>& _Left,
00444                 const pent_string<char>& _Right)
00445         {       // test if string <= string
00446         return (!(_Right < _Left));
00447         }
00448 
00449 inline bool operator<=(
00450                 const char * _Left,
00451                 const pent_string<char>& _Right)
00452         {       // test if NTCS <= string
00453         return (!(_Right < _Left));
00454         }
00455 
00456 inline bool operator<=(
00457                 const pent_string<char>& _Left,
00458                 const char *_Right)
00459         {       // test if string <= NTCS
00460         return (!(_Right < _Left));
00461         }
00462 
00463 
00464 inline bool operator>=(
00465                 const pent_string<char>& _Left,
00466                 const pent_string<char>& _Right)
00467         {       // test if string >= string
00468         return (!(_Left < _Right));
00469         }
00470 
00471 inline bool operator>=(
00472                 const pent_string<char>& _Left,
00473                 const std::basic_string<char>& _Right)
00474         {       // test if string >= string
00475         return (!(_Left < _Right));
00476         }
00477 
00478 inline bool operator>=(
00479                 const std::basic_string<char>& _Left,
00480                 const pent_string<char>& _Right)
00481         {       // test if string >= string
00482         return (!(_Left < _Right));
00483         }
00484 
00485 inline bool operator>=(
00486                 const char * _Left,
00487                 const pent_string<char>& _Right)
00488         {       // test if NTCS >= string
00489         return (!(_Left < _Right));
00490         }
00491 
00492 inline bool operator>=(
00493                 const pent_string<char>& _Left,
00494                 const char *_Right)
00495         {       // test if string >= NTCS
00496         return (!(_Left < _Right));
00497         }
00498 
00499 #else
00500         typedef std::string istring;
00501 #endif
00502 
00503 }
00504 
00505 
00506 #endif 
00507 

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