Re: gtk-oberzalek-991111-1.patch.README

Martin Oberzalek <> writes:

> This is the README file of the gtk-oberzalek-991111-1.patch.gz
> in  the incoming directory of
> Note:
> That's a patch for the glib, but I named it gtk-ob... because of 
> your instructions at

Actually, naming it glib-* would be more appropriate. The instructions
may not be very clear.

> I added the g_strinstr function to g_str* functions.
> g_strinstr -> g_str in string
> That's a port of INSTR command from basic. 
> I actually port a basic application to gnome and so I need that function.
> gint g_strinstr( gchar *text, gchar *word )

Hmmm, this looks a lot like strstr, except that it is case-insensitive.

If we added a function like this, it should be called something like:

 g_strcasestr() or g_strstr_insensitive()

I'm not sure if such a function is useful or not for general purpose
implementation - if we did add such a function, I'd like to see
a more efficient implementation - you might want to look at 
a text like Knuth for information about string searching algorithms.

(A simple optimization is to scan text for the initial character
of the word before trying a strncasecmp. Also, the inner copy in your
implementation is going to be very slow.)

> text: A string where should be searched for the keyword.
> word: The keyword.
> returns: The function returns the position of the keyword, if the keyword
> 	 is found. If not it returns -1.
> 	 The functions starts counting the position with 0.
> I hope I helped you.


> I added some BASIC string functions to the glib:
> BASIC        GLIB                                                           DESCRIPTION
> LEFT$        #define g_strleft(text, len) g_strndup(text, len)              only to complete the functions
> RIGHT$	     gchar* g_strright(gchar *text, gint len)                       same as g_strleft, but fromthe right side of the string
> MID$         gchar* g_strmid(gchar *text, guint pos, guint len)             copies a string out of a string
> INSTR$	     gint g_strinstr(gchar *text, gchar* word)                      finds a string in a string and gives it's position back
> These functions are very useful for porting applications from BASIC to C
> I actually port eliza, so I needed them. 

Hmmm, your implementations suffer from a bit of inefficiency:

#define g_strmid(text,pos,len) g_strndup ((text) + (pos), len)
#define g_strright(text,len) g_strdup ((text) + strlen(text) - (len))

I'd be inclined to say that these wrappers don't add enough convenience
to really be worth adding into GLib ... there are various other 
string manipulation libraries that one might want to emulate 
Perl, Java, STL, etc... and I don't think we want to have 
#define's for all possible names...


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]