ISIS Core Library 0.7.2 (api 3.0.0)
|
00001 /* 00002 <one line to give the program's name and a brief idea of what it does.> 00003 Copyright (C) <year> <name of author> 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (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. See the 00013 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, see <http://www.gnu.org/licenses/>. 00017 00018 */ 00019 00020 #include "istring.hpp" 00021 #ifdef _MSC_VER 00022 #include <Windows.h> 00023 #else 00024 #include <strings.h> 00025 #endif 00026 #include <algorithm> 00027 00029 namespace isis 00030 { 00031 namespace util 00032 { 00033 namespace _internal 00034 { 00035 00036 std::locale const ichar_traits::loc = std::locale( "C" ); 00037 00038 int ichar_traits::compare( const char *s1, const char *s2, size_t n ) 00039 { 00040 #ifdef _MSC_VER 00041 return lstrcmpiA( s1, s2 ); //@todo find some with length parameter 00042 #else 00043 return strncasecmp( s1, s2, n ); 00044 #endif 00045 } 00046 00047 bool ichar_traits::eq( const char &c1, const char &c2 ) 00048 { 00049 return std::tolower( c1, loc ) == std::tolower( c2, loc ); 00050 } 00051 00052 bool ichar_traits::lt( const char &c1, const char &c2 ) 00053 { 00054 return std::tolower( c1, loc ) < std::tolower( c2, loc ); 00055 } 00056 00057 const char *ichar_traits::find( const char *s, size_t n, const char &a ) 00058 { 00059 const char lowA = std::tolower( a ); 00060 00061 if( lowA == std::toupper( a ) ) { // if a has no cases we can do naive search 00062 return std::find( s, s + n, a ); 00063 } else for( size_t i = 0; i < n; i++, s++ ) { 00064 if( std::tolower( *s ) == lowA ) 00065 return s; 00066 } 00067 00068 return NULL; 00069 } 00070 00071 00072 } 00073 } 00074 } 00076 00077 namespace boost 00078 { 00079 template<> isis::util::istring lexical_cast< isis::util::istring, std::string >( const std::string &arg ) {return isis::util::istring( arg.begin(), arg.end() );} 00080 template<> std::string lexical_cast< std::string, isis::util::istring >( const isis::util::istring &arg ) {return std::string( arg.begin(), arg.end() );} 00081 }