| Copyright | Will Thompson and Iñaki García Etxebarria |
|---|---|
| License | LGPL-2.1 |
| Maintainer | Iñaki García Etxebarria |
| Safe Haskell | None |
| Language | Haskell2010 |
GI.GLib.Structs.PathBuf
Description
GPathBuf is a helper type that allows you to easily build paths from
individual elements, using the platform specific conventions for path
separators.
c code
g_auto (GPathBuf) path; g_path_buf_init (&path); g_path_buf_push (&path, "usr"); g_path_buf_push (&path, "bin"); g_path_buf_push (&path, "echo"); g_autofree char *echo = g_path_buf_to_path (&path); g_assert_cmpstr (echo, ==, "/usr/bin/echo");
You can also load a full path and then operate on its components:
c code
g_auto (GPathBuf) path; g_path_buf_init_from_path (&path, "/usr/bin/echo"); g_path_buf_pop (&path); g_path_buf_push (&path, "sh"); g_autofree char *sh = g_path_buf_to_path (&path); g_assert_cmpstr (sh, ==, "/usr/bin/sh");
Since: 2.76
Synopsis
- newtype PathBuf = PathBuf (ManagedPtr PathBuf)
- newZeroPathBuf :: MonadIO m => m PathBuf
- type family ResolvePathBufMethod (t :: Symbol) o where ...
- data PathBufClearMethodInfo
- pathBufClear :: (HasCallStack, MonadIO m) => PathBuf -> m ()
- data PathBufClearToPathMethodInfo
- pathBufClearToPath :: (HasCallStack, MonadIO m) => PathBuf -> m (Maybe [Char])
- pathBufEqual :: (HasCallStack, MonadIO m) => Ptr () -> Ptr () -> m Bool
- data PathBufFreeMethodInfo
- pathBufFree :: (HasCallStack, MonadIO m) => PathBuf -> m ()
- data PathBufFreeToPathMethodInfo
- pathBufFreeToPath :: (HasCallStack, MonadIO m) => PathBuf -> m (Maybe [Char])
- data PathBufInitMethodInfo
- pathBufInit :: (HasCallStack, MonadIO m) => PathBuf -> m PathBuf
- data PathBufInitFromPathMethodInfo
- pathBufInitFromPath :: (HasCallStack, MonadIO m) => PathBuf -> Maybe [Char] -> m PathBuf
- data PathBufPopMethodInfo
- pathBufPop :: (HasCallStack, MonadIO m) => PathBuf -> m Bool
- data PathBufPushMethodInfo
- pathBufPush :: (HasCallStack, MonadIO m) => PathBuf -> [Char] -> m PathBuf
- data PathBufSetExtensionMethodInfo
- pathBufSetExtension :: (HasCallStack, MonadIO m) => PathBuf -> Maybe [Char] -> m Bool
- data PathBufSetFilenameMethodInfo
- pathBufSetFilename :: (HasCallStack, MonadIO m) => PathBuf -> [Char] -> m Bool
- data PathBufToPathMethodInfo
- pathBufToPath :: (HasCallStack, MonadIO m) => PathBuf -> m (Maybe [Char])
Exported types
Memory-managed wrapper type.
Constructors
| PathBuf (ManagedPtr PathBuf) |
Instances
Methods
Click to display all available methods, including inherited ones
Methods
clear, clearToPath, free, freeToPath, init, initFromPath, pop, push, toPath.
Getters
None.
Setters
type family ResolvePathBufMethod (t :: Symbol) o where ... Source #
Equations
| ResolvePathBufMethod "clear" o = PathBufClearMethodInfo | |
| ResolvePathBufMethod "clearToPath" o = PathBufClearToPathMethodInfo | |
| ResolvePathBufMethod "free" o = PathBufFreeMethodInfo | |
| ResolvePathBufMethod "freeToPath" o = PathBufFreeToPathMethodInfo | |
| ResolvePathBufMethod "init" o = PathBufInitMethodInfo | |
| ResolvePathBufMethod "initFromPath" o = PathBufInitFromPathMethodInfo | |
| ResolvePathBufMethod "pop" o = PathBufPopMethodInfo | |
| ResolvePathBufMethod "push" o = PathBufPushMethodInfo | |
| ResolvePathBufMethod "toPath" o = PathBufToPathMethodInfo | |
| ResolvePathBufMethod "setExtension" o = PathBufSetExtensionMethodInfo | |
| ResolvePathBufMethod "setFilename" o = PathBufSetFilenameMethodInfo | |
| ResolvePathBufMethod l o = MethodResolutionFailed l o :: Type |
clear
data PathBufClearMethodInfo Source #
Instances
| (signature ~ m (), MonadIO m) => OverloadedMethod PathBufClearMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufClearMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> m () |
Clears the contents of the path buffer.
This function should be use to free the resources in a stack-allocated
GPathBuf initialized using pathBufInit or
pathBufInitFromPath.
Since: 2.76
clearToPath
data PathBufClearToPathMethodInfo Source #
Instances
| (signature ~ m (Maybe [Char]), MonadIO m) => OverloadedMethod PathBufClearToPathMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufClearToPathMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> m (Maybe [Char]) | Returns: the built path |
Clears the contents of the path buffer and returns the built path.
This function returns NULL if the GPathBuf is empty.
See also: pathBufToPath
Since: 2.76
equal
Arguments
| :: (HasCallStack, MonadIO m) | |
| => Ptr () |
|
| -> Ptr () |
|
| -> m Bool | Returns: |
Compares two path buffers for equality and returns TRUE
if they are equal.
The paths inside the path buffers are not going to be normalized,
so X/Y/Z/A/.., X/./Y/Z and X/Y/Z are not going to be considered
equal.
This function can be passed to g_hash_table_new() as the
key_equal_func parameter.
Since: 2.76
free
data PathBufFreeMethodInfo Source #
Instances
| (signature ~ m (), MonadIO m) => OverloadedMethod PathBufFreeMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufFreeMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> m () |
Frees a GPathBuf allocated by g_path_buf_new().
Since: 2.76
freeToPath
data PathBufFreeToPathMethodInfo Source #
Instances
| (signature ~ m (Maybe [Char]), MonadIO m) => OverloadedMethod PathBufFreeToPathMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufFreeToPathMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> m (Maybe [Char]) | Returns: the path |
Frees a GPathBuf allocated by g_path_buf_new(), and
returns the path inside the buffer.
This function returns NULL if the GPathBuf is empty.
See also: pathBufToPath
Since: 2.76
init
data PathBufInitMethodInfo Source #
Instances
| (signature ~ m PathBuf, MonadIO m) => OverloadedMethod PathBufInitMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufInitMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> m PathBuf | Returns: the initialized path builder |
Initializes a GPathBuf instance.
Since: 2.76
initFromPath
data PathBufInitFromPathMethodInfo Source #
Instances
| (signature ~ (Maybe [Char] -> m PathBuf), MonadIO m) => OverloadedMethod PathBufInitFromPathMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufInitFromPathMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> Maybe [Char] |
|
| -> m PathBuf | Returns: the initialized path builder |
Initializes a GPathBuf instance with the given path.
Since: 2.76
pop
data PathBufPopMethodInfo Source #
Instances
| (signature ~ m Bool, MonadIO m) => OverloadedMethod PathBufPopMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufPopMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> m Bool | Returns: |
Removes the last element of the path buffer.
If there is only one element in the path buffer (for example, / on
Unix-like operating systems or the drive on Windows systems), it will
not be removed and False will be returned instead.
C code
GPathBuf buf, cmp; g_path_buf_init_from_path (&buf, "/bin/sh"); g_path_buf_pop (&buf); g_path_buf_init_from_path (&cmp, "/bin"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_pop (&buf); g_path_buf_init_from_path (&cmp, "/"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_clear (&buf);
Since: 2.76
push
data PathBufPushMethodInfo Source #
Instances
| (signature ~ ([Char] -> m PathBuf), MonadIO m) => OverloadedMethod PathBufPushMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufPushMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> [Char] |
|
| -> m PathBuf | Returns: the same pointer to |
Extends the given path buffer with path.
If path is absolute, it replaces the current path.
If path contains a directory separator, the buffer is extended by
as many elements the path provides.
On Windows, both forward slashes and backslashes are treated as
directory separators. On other platforms, DIR_SEPARATOR_S is the
only directory separator.
C code
GPathBuf buf, cmp; g_path_buf_init_from_path (&buf, "/tmp"); g_path_buf_push (&buf, ".X11-unix/X0"); g_path_buf_init_from_path (&cmp, "/tmp/.X11-unix/X0"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_push (&buf, "/etc/locale.conf"); g_path_buf_init_from_path (&cmp, "/etc/locale.conf"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_clear (&buf);
Since: 2.76
setExtension
data PathBufSetExtensionMethodInfo Source #
Instances
| (signature ~ (Maybe [Char] -> m Bool), MonadIO m) => OverloadedMethod PathBufSetExtensionMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufSetExtensionMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> Maybe [Char] |
|
| -> m Bool | Returns: |
Adds an extension to the file name in the path buffer.
If extension is NULL, the extension will be unset.
If the path buffer does not have a file name set, this function returns
FALSE and leaves the path buffer unmodified.
Since: 2.76
setFilename
data PathBufSetFilenameMethodInfo Source #
Instances
| (signature ~ ([Char] -> m Bool), MonadIO m) => OverloadedMethod PathBufSetFilenameMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufSetFilenameMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> [Char] |
|
| -> m Bool | Returns: |
Sets the file name of the path.
If the path buffer is empty, the filename is left unset and this
function returns FALSE.
If the path buffer only contains the root element (on Unix-like operating
systems) or the drive (on Windows), this is the equivalent of pushing
the new fileName.
If the path buffer contains a path, this is the equivalent of
popping the path buffer and pushing fileName, creating a
sibling of the original path.
C code
GPathBuf buf, cmp; g_path_buf_init_from_path (&buf, "/"); g_path_buf_set_filename (&buf, "bar"); g_path_buf_init_from_path (&cmp, "/bar"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_set_filename (&buf, "baz.txt"); g_path_buf_init_from_path (&cmp, "/baz.txt"); g_assert_true (g_path_buf_equal (&buf, &cmp); g_path_buf_clear (&cmp); g_path_buf_clear (&buf);
Since: 2.76
toPath
data PathBufToPathMethodInfo Source #
Instances
| (signature ~ m (Maybe [Char]), MonadIO m) => OverloadedMethod PathBufToPathMethodInfo PathBuf signature Source # | |
Defined in GI.GLib.Structs.PathBuf Methods overloadedMethod :: PathBuf -> signature # | |
| OverloadedMethodInfo PathBufToPathMethodInfo PathBuf Source # | |
Defined in GI.GLib.Structs.PathBuf Methods | |
Arguments
| :: (HasCallStack, MonadIO m) | |
| => PathBuf |
|
| -> m (Maybe [Char]) | Returns: the path |
Retrieves the built path from the path buffer.
On Windows, the result contains backslashes as directory separators, even if forward slashes were used in input.
If the path buffer is empty, this function returns NULL.
Since: 2.76