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

Re: Utf8 strings manipulation



Thanks a lot Tadej!!

I will try this to learn more about utf8 string manipulation but I will
use regexp because I need to replace more characters (This is only an
example)


Thanks again!!!


El Mon, 29 Sep 2008 16:18:50 +0200
"Tadej Borovšak" <tadeboro gmail com> escribió:

> Hello,
> 
> what I would do (not necessarily the smartest thing;) is try to
> determine what strings I'll be operating on. If I'm operating on
> ANSI/iso8859-1 strings, I don't need to use uft8-specialized
> functions, since characters from those have the same codes in all
> encodings.
> 
> That thing out of the way, we can go and convert our string. I would
> do it with glib's string manipulation functions like this (example
> only):
> 
> ==== CODE ======
> #include <glib.h>
> #include <string.h>
> #include <stdio.h>
> 
> int
> main( int argc, char **argv )
> {
>     gchar *string = "gtk_source_completion";
>     gchar *string_new;
>     gchar **parts;
>     gchar **parts_bk;
> 
>     printf( "%s\n", string );
> 
>     parts = g_strsplit( string, "_", -1 );
>     parts_bk = parts;
> 
>     for( parts; parts; parts++ )
>     {
>         gchar *tmp;
>         tmp = g_utf8_strup( *parts, ( g_utf8_next_char( *parts ) -
> *parts ) * sizeof( gchar ) );
>         memcpy( *parts, tmp, strlen( tmp ) );
>         g_free( tmp );
>     }
> 
>     string_new = g_strjoinv( NULL, parts_bk );
>     g_strfreev( parts_bk );
> 
>     printf( "%s\n", string_new );
> 
>     return( 0 );
> }
> 
> ==== /CODE =====
> 
> Hope it's been helpfull.
> 
> 
> 2008/9/29 Perriman <chuchiperriman gmail com>:
> > Hi all,
> >
> >        I'm trying to transform an utf8 string. I have some problems
> > with it because I don't know how to do it or where I can see an
> > example (a tutorial, doc or application).
> >
> > I need transform this text (in utf8):
> >
> > gtk_source_completion
> >
> > to:
> >
> > GtkSourceCompletion.
> >
> > I don't know how replace a character or delete a character. Perhaps
> > I need to allocate a gchar* array first and then use g_utf8_strncpy
> > in all _, I don't know. In that case, I don't know how much memory
> > I need to allocate.
> >
> > Can you help me?
> >
> > Regards,
> >        Perriman
> > _______________________________________________
> > gtk-app-devel-list mailing list
> > gtk-app-devel-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> >
> 
> 
> 


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