00001 /* 00002 * $Id: trim.h 4518 2008-07-28 15:39:28Z henningw $ 00003 * 00004 * Copyright (C) 2001-2003 FhG Fokus 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version 00012 * 00013 * Kamailio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 00024 #ifndef TRIM_H 00025 #define TRIM_H 00026 00027 #include "str.h" 00028 00029 00030 /* 00031 * This switch-case statement is used in 00032 * trim_leading and trim_trailing. You can 00033 * define characters that should be skipped 00034 * here. 00035 */ 00036 #define TRIM_SWITCH(c) switch(c) { \ 00037 case ' ': \ 00038 case '\t': \ 00039 case '\r': \ 00040 case '\n': \ 00041 break; \ 00042 \ 00043 default: \ 00044 return; \ 00045 } 00046 00047 00048 /*! \brief 00049 * Remove any leading whitechars, like spaces, 00050 * horizontal tabs, carriage returns and line 00051 * feeds 00052 * 00053 * WARNING: String descriptor structure will be 00054 * modified ! Make a copy otherwise you 00055 * might be unable to free _s->s for 00056 * example ! 00057 * 00058 */ 00059 static inline void trim_leading(str* _s) 00060 { 00061 for(; _s->len > 0; _s->len--, _s->s++) { 00062 TRIM_SWITCH(*(_s->s)); 00063 } 00064 } 00065 00066 00067 /*! \brief 00068 * Remove any trailing white char, like spaces, 00069 * horizontal tabs, carriage returns and line feeds 00070 * 00071 * WARNING: String descriptor structure will be 00072 * modified ! Make a copy otherwise you 00073 * might be unable to free _s->s for 00074 * example ! 00075 */ 00076 static inline void trim_trailing(str* _s) 00077 { 00078 for(; _s->len > 0; _s->len--) { 00079 TRIM_SWITCH(_s->s[_s->len - 1]); 00080 } 00081 } 00082 00083 00084 /*! \brief 00085 * Do trim_leading and trim_trailing 00086 * 00087 * WARNING: String structure will be modified ! 00088 * Make a copy otherwise you might be 00089 * unable to free _s->s for example ! 00090 */ 00091 static inline void trim(str* _s) 00092 { 00093 trim_leading(_s); 00094 trim_trailing(_s); 00095 } 00096 00097 00098 #endif /* TRIM_H */
1.5.6