Path manipulation in glib.h




Hello,

I'd opt for a set of path manipulation functions in glib.h (in addition
to g_basename() and g_dirname():

gchar ** g_path_split(const gchar *path);
    returns a NULL terminated array of the elements of path.
    Examples:

	file.c	    -> { "file.c", NULL }
	dir/	    -> { "dir", NULL }
	./file.c    -> { "file.c", NULL }
	dir/file.c  -> { "dir", "file.c", NULL }
	dir/../file.c -> { "dir", "..", "file.c", NULL } or maybe
			{ "file.c", NULL }
	../file.c   -> { "..", "file.c"
	/bin/sh     -> { "", "bin", "sh", NULL }

    Windows:

	C:\WinNT\Fonts\Arial.ttf -> { "", "C", "WinNT", "Fonts", "Arial.ttf", NULL }
	\\SERVER\Resource\file.c -> { "", "", "SERVER", "Resource", "file.c", NULL }

    VMS:

	dev$name:[dir1.dir2.dir3]file.c ->
	    { "", "dev$name", "dir1", "dir2", "dir3", "file.c" }

    Maybe it would be better to return a hint in array[0], like
    G_RELATIVE_PATH, G_ABSOLUTE_PATH, G_UNC_PATH, G_URL, etc.

gchar * g_path_join (const gchar * path_element, ...);
gchar * g_path_joinv (const gchar ** path_elements);

    Create a path from elements.

const gchar * g_filename_ext (const gchar * path);

    Returns a pointer to the extension of a path.

	file.c	    -> "c"
	dir/	    -> ""

And a string function:

    int g_strecmp (const gchar * string, const gchar * end);
    int g_strecasecmp (const gchar * string, const gchar * end);

	return 1 if string ends with end.

	    "file.c", "c" -> 1
	    "dir/", "c" -> 0

--
Dipl. Inf. (FH) Aaron "Optimizer" Digulla     Assistent im BIKS Labor, FB WI
"(to) optimize: Make a program faster by      FH Konstanz, Brauneggerstr. 55
improving the algorithms rather than by       Tel:+49-7531-206-514
buying a faster machine."                     EMail: digulla@fh-konstanz.de



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