sprint 1-alpha
|
00001 /****************************************************************************** 00002 * SPRINT::string 00003 * 00004 * Copyright (C) 2005-2011 Paolo Medici <www.pmx.it> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 #ifndef STRING_ALGO_H 00023 #define STRING_ALGO_H 00024 00028 #include <cstring> 00029 00030 namespace sprint { 00031 00033 template<class _S> 00034 inline _S trim(const _S &src) 00035 { 00036 typename _S::size_type s = src.find_first_not_of("\n\r\t "); 00037 typename _S::size_type n = src.find_last_not_of("\n\r\t "); 00038 // TODO: caso in cui s==0 e n == lenght 00039 return (s<n) ? ( _S(src, s, n-s+1) ) : (_S() ); 00040 } 00041 00043 template<class _S> 00044 inline _S trim(const _S &src, int start) 00045 { 00046 typename _S::size_type s = src.find_first_not_of("\n\r\t ", start); 00047 typename _S::size_type n = src.find_last_not_of("\n\r\t "); 00048 // TODO: caso in cui s==0 e n == lenght 00049 return (s<n) ? ( _S(src, s, n-s+1) ) : (_S() ); 00050 } 00051 00053 template<class _S> 00054 inline _S right_trim(const _S &src) 00055 { 00056 typename _S::size_type n = src.find_last_not_of("\n\r\t "); 00057 return (n!=0) ? ( _S(src, 0, n+1) ) : (_S() ); 00058 } 00059 00060 00062 inline bool iequals(const char *a, const char * b) 00063 { 00064 return !stricmp(a, b); 00065 } 00066 00068 template<class _S> 00069 bool iequals(const _S & a, const char * b) 00070 { 00071 return !stricmp(a.c_str(), b); 00072 } 00073 00075 template<class _S> 00076 bool iequals(const char *a, const _S & b) 00077 { 00078 return !stricmp(a, b.c_str()); 00079 } 00080 00081 template<class _S> 00082 bool iequals(const _S & a, const _S & b) 00083 { 00084 return !stricmp(a.c_str(), b.c_str()); 00085 } 00086 00087 } 00088 00089 #endif