Re: GLib substr function



On Fri, Apr 10, 2009 at 6:34 PM, Christian Dywan <christian imendio com> wrote:
> Am Fri, 10 Apr 2009 16:49:43 +0200
> schrieb b0unc3 <daniele maio gmail com>:
>
>> 2009/4/10 Nelson Benítez León <nbenitezl gmail com>
>>
>> > 2009/4/10 b0unc3 <daniele maio gmail com>:
>> > > Hi all,
>> > >
>> > > there is any implementation of a substr function in GLib ?
>> > >
>> > > I mean :
>> > > string = "hello world"
>> > > g_*substr*(string,2,6)
>> > > output = llo w
>> >
>> > Another way,
>> >
>> > substring (GString *str, int index, int len)
>> > {
>> >  return g_string_new_len (str->str, index, MIN (str->len - index,
>> > len)); }
>> >
>> > taken from http://bugzilla.gnome.org/show_bug.cgi?id=109286#c2 .
>> >
>> >
>> > I personally would like that glib provide those small but useful
>> > string functions (like other high level languages do), for example,
>> > glib doesn't provide a simple function to replace strings, like this
>> > one written by Tim in
>> > http://bugzilla.gnome.org/show_bug.cgi?id=65987#c2 ,
>> >
>> > gchar *
>> > g_strreplace (const gchar *string,
>> >              const gchar *search,
>> >              const gchar *replacement)
>> >
>> >
>> > Instead you currently have to use gregex to replace some simple
>> > strings (where no regex are involved).
>>
>>
>> First of all thanks to everyone who replayed.
>> The implementation using g_srtndup looks ok.
>>
>> I was wondering why not to add a so simple example in the official
>> docs (maybe in the g_strndup explanation).
>
> Hey,
>
> the reason is simple. This is entirely up to the programming language
> and not at all Glib specific. If you want to learn more about C you
> should look for a good C (online) book.
>

That's ridiculous! You have many things in glib (like ghash, gstring
etc.) which can be done better with specific language constructs in
some languages (associative arrays, operators on strings etc.). Yet,
as glib is primarily foused on C, it's a good idea to implement those
features, which are (in plain C) missing...

P.


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