/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/utils/eh_glib.c

Go to the documentation of this file.
00001 //---
00002 //
00003 // This file is part of sedflux.
00004 //
00005 // sedflux 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 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // sedflux 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 sedflux; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //
00019 //---
00020 
00021 #include <eh_utils.h>
00022 
00023 gsize eh_string_find_first_of(GString *s, char c)
00024 {
00025    char *p = strchr(s->str,c);
00026    return (p==NULL)?G_NPOS:p-s->str;
00027 }
00028 
00029 gsize eh_string_find_last_of(GString *s, char c)
00030 {
00031    char *p = strrchr(s->str,c);
00032    return (p==NULL)?G_NPOS:p-s->str;
00033 }
00034 
00035 void eh_string_remove_chr(GString *s,char c)
00036 {
00037    gsize n;
00038    while ( (n=eh_string_find_first_of(s,c))!=G_NPOS )
00039       g_string_erase(s,n,1);
00040 }
00041 
00042 void eh_string_remove_white_space(GString *s)
00043 {
00044    char *p=G_WHITESPACE;
00045    gsize i, len=strlen(p);
00046    for ( i=0 ; i<len ; i++, p++ )
00047       eh_string_remove_chr(s,*p);
00048 }
00049 
00050 char *eh_string_c_str(GString *s)
00051 {
00052    return s->str;
00053 }
00054 
00055 gsize eh_array_size(GArray *a)
00056 {
00057    return a->len;
00058 }
00059 /*
00060 GArray *eh_array_set_vals(GArray *a, guint index, gconstpointer data, guint len)
00061 {
00062    GRealArray *array = (GRealArray*)a;
00063    g_array_maybe_expand( a , index+len );
00064    g_memcpy( array->data + array->elt_size*index , data , len*array->elt_size );
00065    array->len += len;
00066    return a;
00067 }
00068 */
00069 
00070 // removes the link containing data and frees the data.  there is no
00071 // check to see that other links in the list point to data.  only the
00072 // first link containing data is removed.
00073 // list : a pointer to a GSList
00074 // data : the data to be removed and freed
00075 GSList *eh_slist_remove_and_free( GSList *list , gpointer data )
00076 {
00077    list = g_slist_remove( list , data );
00078    eh_free( data );
00079    return list;
00080 }
00081 
00082 void eh_free_slist_data( gpointer data , gpointer user_data )
00083 {
00084    eh_free( data );
00085 }
00086 

Generated on Fri Jan 4 18:04:16 2008 for sedflux by  doxygen 1.5.2